Removed all move_t stuff because it was not implemented and anything other than putting got broken in the previous commit
This commit is contained in:
parent
8810175693
commit
355c79bac4
7 changed files with 39 additions and 156 deletions
|
|
@ -27,7 +27,7 @@
|
|||
#include "types.h"
|
||||
#include "ui.h"
|
||||
|
||||
#define VERSION 0.1.1
|
||||
#define VERSION 0.1.2
|
||||
|
||||
#ifndef GITHASH
|
||||
#define FULLVERSION VERSION
|
||||
|
|
@ -164,10 +164,9 @@ int main( int argc, char *argv[] ){
|
|||
initBoard( playboard );
|
||||
// Begin loopin
|
||||
for(;; playboard.player = !playboard.player ){
|
||||
move_t move = askMove();
|
||||
int column = askColumn( playboard, move );
|
||||
playMove( &playboard, move, column );
|
||||
int column = askColumn( playboard );
|
||||
playMove( &playboard, column );
|
||||
calcWins( &wins, playboard, column );
|
||||
updateBoard( wins, playboard, move, column );
|
||||
updateBoard( wins, playboard, column );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
logic.c
13
logic.c
|
|
@ -38,25 +38,16 @@ static inline int bottomHeightMask( const int a, const int b ){
|
|||
return safeHeightMask( bottom( a, b ) );
|
||||
}
|
||||
|
||||
void playMove(
|
||||
inline void playMove(
|
||||
board_t *boardptr,
|
||||
const move_t move,
|
||||
const int column
|
||||
){
|
||||
switch( move ){
|
||||
case PUT: // Put a new piece in the board
|
||||
boardptr->column [ column ] |=
|
||||
boardptr->player << boardptr->height [ column ];
|
||||
boardptr->height [ column ]++;
|
||||
break;
|
||||
case POP: // Pop out the lowest and make all above fall down
|
||||
boardptr->column [ column ] >>= 1;
|
||||
boardptr->height [ column ]--;
|
||||
default: // Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
void calcWins(
|
||||
inline void calcWins(
|
||||
wins_t *wins,
|
||||
const board_t board,
|
||||
const int column
|
||||
|
|
|
|||
1
logic.h
1
logic.h
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
extern void playMove(
|
||||
board_t *boardptr,
|
||||
const move_t move,
|
||||
const int column
|
||||
);
|
||||
|
||||
|
|
|
|||
7
types.h
7
types.h
|
|
@ -4,13 +4,6 @@
|
|||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
typedef enum {
|
||||
QUIT=0,
|
||||
PUT,
|
||||
POP,
|
||||
MOVECOUNT
|
||||
} move_t;
|
||||
|
||||
typedef int column_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
6
ui.h
6
ui.h
|
|
@ -11,13 +11,9 @@ extern void initBoard(
|
|||
extern void updateBoard(
|
||||
const wins_t wins,
|
||||
const board_t board,
|
||||
const move_t move,
|
||||
const int column
|
||||
);
|
||||
|
||||
extern int askColumn(
|
||||
const board_t board,
|
||||
const move_t move
|
||||
const board_t board
|
||||
);
|
||||
|
||||
extern move_t askMove( void );
|
||||
|
|
|
|||
58
ui_ncurses.c
58
ui_ncurses.c
|
|
@ -132,28 +132,14 @@ void initBoard( const board_t board ){
|
|||
void updateBoard(
|
||||
const wins_t wins,
|
||||
const board_t board,
|
||||
const move_t move,
|
||||
const int column
|
||||
){
|
||||
int height = board.height[ column ];
|
||||
switch( move ){
|
||||
case PUT:
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( board.rows - height + 1 ),
|
||||
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||
board.column[ column ] & 1 << ( height - 1 ) ? "1" : "0"
|
||||
);
|
||||
break;
|
||||
default:
|
||||
for( int row = 0; row < height; row++ ){
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( board.rows - row ),
|
||||
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||
board.column[ column ] & 1 << row ? "1" : "0"
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
char num[4];
|
||||
sprintf( num, "%3d", wins.count0.vertical );
|
||||
mvaddstr(
|
||||
|
|
@ -218,8 +204,7 @@ void updateBoard(
|
|||
}
|
||||
|
||||
int askColumn(
|
||||
const board_t board,
|
||||
const move_t move
|
||||
const board_t board
|
||||
){
|
||||
int column = 0;
|
||||
#ifdef ARROWS
|
||||
|
|
@ -244,8 +229,6 @@ int askColumn(
|
|||
case KEY_DOWN:
|
||||
return column;
|
||||
}
|
||||
switch( move ){
|
||||
case PUT:
|
||||
for(; board.height[ column ] >= board.rows; ) switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
if( column >= board.columns ) ch = KEY_LEFT;
|
||||
|
|
@ -256,22 +239,6 @@ int askColumn(
|
|||
else column--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case POP:
|
||||
for(; board.height[ column ] <= 0; ) switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
if( column >= board.columns ) ch = KEY_LEFT;
|
||||
else column++;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if( column == 0 ) ch = KEY_RIGHT;
|
||||
else column--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
#else /* !ARROWS */
|
||||
for(;;){
|
||||
|
|
@ -282,14 +249,7 @@ int askColumn(
|
|||
);
|
||||
if( board.player ) addstr( "1" );
|
||||
else addstr( "0" );
|
||||
switch( move ){
|
||||
case PUT:
|
||||
addstr( " put the piece? " );
|
||||
case POP:
|
||||
addstr( " pop a piece? " );
|
||||
default:
|
||||
addstr( " Undefined move a thingy? " );
|
||||
}
|
||||
clrtoeol();
|
||||
refresh();
|
||||
scanw( " %d", &column );
|
||||
|
|
@ -300,30 +260,14 @@ int askColumn(
|
|||
);
|
||||
clrtoeol();
|
||||
if( column >= 0 && column < board.columns )
|
||||
switch( move ){
|
||||
case PUT:
|
||||
if( board.height [ column ] < board.columns )
|
||||
return column;
|
||||
else addstr( "Pls enter a column that ain't full" );
|
||||
break;
|
||||
case POP:
|
||||
if( board.height [ column ] != 0 )
|
||||
return column;
|
||||
else addstr( "Pls enter a column that ain't empty" );
|
||||
default:
|
||||
return column;
|
||||
}
|
||||
else addstr( "Pls enter a column that exists" );
|
||||
}
|
||||
#endif /* ! ARROWS */
|
||||
}
|
||||
|
||||
move_t askMove( void ){
|
||||
move_t move = PUT;
|
||||
// TODO: actually ask what move
|
||||
return move;
|
||||
}
|
||||
|
||||
#undef INPUT_X
|
||||
#undef INPUT_Y
|
||||
#undef SCOREBOARD_X
|
||||
|
|
|
|||
43
ui_vt100.c
43
ui_vt100.c
|
|
@ -69,12 +69,9 @@ void initBoard( const board_t board ){
|
|||
void updateBoard(
|
||||
const wins_t wins,
|
||||
const board_t board,
|
||||
const move_t move,
|
||||
const int column
|
||||
){
|
||||
int height = board.height [ column ];
|
||||
switch( move ){
|
||||
case PUT: // Only print the put one
|
||||
printf(
|
||||
"\033[%dA\033[%dC%c\033[%dB",
|
||||
height + 3,
|
||||
|
|
@ -82,18 +79,6 @@ void updateBoard(
|
|||
'0' + !!( board.player ),
|
||||
height + 1
|
||||
);
|
||||
break;
|
||||
default: // Print all the pieces in the column and the air above
|
||||
printf( "\033[%dA", height + 4 );
|
||||
if( height < board.rows ) printf( "\033[%dC ", column * 3 + 4 );
|
||||
else printf( "\033[%dC", column * 3 + 5 );
|
||||
for( int row = height; row --> 0; )
|
||||
printf(
|
||||
"\033[B\033[D%c",
|
||||
'0' + !!( board.column [ column ] & ( 1 << row ) )
|
||||
);
|
||||
printf( "\033[2B" );
|
||||
}
|
||||
printf(
|
||||
"\r\033[7A\033[%dC"
|
||||
"%3d │%3d\033[B\033[8D"
|
||||
|
|
@ -112,18 +97,11 @@ void updateBoard(
|
|||
}
|
||||
|
||||
int askColumn(
|
||||
const board_t board,
|
||||
const move_t move
|
||||
const board_t board
|
||||
){
|
||||
int column;
|
||||
for(;;){
|
||||
switch( move ){
|
||||
case PUT: printf( "Wher player %d put? ", board.player );
|
||||
break;
|
||||
case POP: printf( "Wher player %d pop? ", board.player );
|
||||
break;
|
||||
default: printf( "Wher player %d do the thing? ", board.player );
|
||||
}
|
||||
printf( "Wher player %d put? ", board.player );
|
||||
printf( "\033[K" ); // clear everything after cursor
|
||||
fflush( stdout );
|
||||
column = -1;
|
||||
|
|
@ -141,32 +119,15 @@ int askColumn(
|
|||
}
|
||||
column -= FIRST_NUMBER;
|
||||
if( column >= 0 && column < board.columns )
|
||||
switch( move ){
|
||||
case PUT:
|
||||
if( board.height [ column ] < board.rows )
|
||||
return column;
|
||||
else printf( "\033[2Apls enter a column that ain't full" );
|
||||
break;
|
||||
case POP:
|
||||
if( board.height [ column ] != 0 )
|
||||
return column;
|
||||
else printf( "\033[2Apls enter a column that ain't empty" );
|
||||
break;
|
||||
default:
|
||||
return column;
|
||||
}
|
||||
else
|
||||
printf( "\033[2Apls enter valid column" );
|
||||
printf( "\033[K\n" );
|
||||
}
|
||||
}
|
||||
|
||||
move_t askMove( void ){
|
||||
move_t move = PUT;
|
||||
// TODO: actually ask what move
|
||||
return move;
|
||||
}
|
||||
|
||||
#undef BOARD_WIDTH_CHARS
|
||||
#undef SCOREBOARD_OFFSET
|
||||
#undef SCOREBOARD_WIDTH
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue