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 "types.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
#define VERSION 0.1.1
|
#define VERSION 0.1.2
|
||||||
|
|
||||||
#ifndef GITHASH
|
#ifndef GITHASH
|
||||||
#define FULLVERSION VERSION
|
#define FULLVERSION VERSION
|
||||||
|
|
@ -164,10 +164,9 @@ int main( int argc, char *argv[] ){
|
||||||
initBoard( playboard );
|
initBoard( playboard );
|
||||||
// Begin loopin
|
// Begin loopin
|
||||||
for(;; playboard.player = !playboard.player ){
|
for(;; playboard.player = !playboard.player ){
|
||||||
move_t move = askMove();
|
int column = askColumn( playboard );
|
||||||
int column = askColumn( playboard, move );
|
playMove( &playboard, column );
|
||||||
playMove( &playboard, move, column );
|
|
||||||
calcWins( &wins, playboard, column );
|
calcWins( &wins, playboard, column );
|
||||||
updateBoard( wins, playboard, move, column );
|
updateBoard( wins, playboard, column );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
logic.c
19
logic.c
|
|
@ -38,25 +38,16 @@ static inline int bottomHeightMask( const int a, const int b ){
|
||||||
return safeHeightMask( bottom( a, b ) );
|
return safeHeightMask( bottom( a, b ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void playMove(
|
inline void playMove(
|
||||||
board_t *boardptr,
|
board_t *boardptr,
|
||||||
const move_t move,
|
|
||||||
const int column
|
const int column
|
||||||
){
|
){
|
||||||
switch( move ){
|
boardptr->column [ column ] |=
|
||||||
case PUT: // Put a new piece in the board
|
boardptr->player << boardptr->height [ column ];
|
||||||
boardptr->column [ column ] |=
|
boardptr->height [ 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,
|
wins_t *wins,
|
||||||
const board_t board,
|
const board_t board,
|
||||||
const int column
|
const int column
|
||||||
|
|
|
||||||
1
logic.h
1
logic.h
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
extern void playMove(
|
extern void playMove(
|
||||||
board_t *boardptr,
|
board_t *boardptr,
|
||||||
const move_t move,
|
|
||||||
const int column
|
const int column
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
7
types.h
7
types.h
|
|
@ -4,13 +4,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
QUIT=0,
|
|
||||||
PUT,
|
|
||||||
POP,
|
|
||||||
MOVECOUNT
|
|
||||||
} move_t;
|
|
||||||
|
|
||||||
typedef int column_t;
|
typedef int column_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
6
ui.h
6
ui.h
|
|
@ -11,13 +11,9 @@ extern void initBoard(
|
||||||
extern void updateBoard(
|
extern void updateBoard(
|
||||||
const wins_t wins,
|
const wins_t wins,
|
||||||
const board_t board,
|
const board_t board,
|
||||||
const move_t move,
|
|
||||||
const int column
|
const int column
|
||||||
);
|
);
|
||||||
|
|
||||||
extern int askColumn(
|
extern int askColumn(
|
||||||
const board_t board,
|
const board_t board
|
||||||
const move_t move
|
|
||||||
);
|
);
|
||||||
|
|
||||||
extern move_t askMove( void );
|
|
||||||
|
|
|
||||||
90
ui_ncurses.c
90
ui_ncurses.c
|
|
@ -132,28 +132,14 @@ void initBoard( const board_t board ){
|
||||||
void updateBoard(
|
void updateBoard(
|
||||||
const wins_t wins,
|
const wins_t wins,
|
||||||
const board_t board,
|
const board_t board,
|
||||||
const move_t move,
|
|
||||||
const int column
|
const int column
|
||||||
){
|
){
|
||||||
int height = board.height[ column ];
|
int height = board.height[ column ];
|
||||||
switch( move ){
|
mvaddstr(
|
||||||
case PUT:
|
BOARD_Y + BOARD_DY * ( board.rows - height + 1 ),
|
||||||
mvaddstr(
|
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||||
BOARD_Y + BOARD_DY * ( board.rows - height + 1 ),
|
board.column[ column ] & 1 << ( height - 1 ) ? "1" : "0"
|
||||||
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];
|
char num[4];
|
||||||
sprintf( num, "%3d", wins.count0.vertical );
|
sprintf( num, "%3d", wins.count0.vertical );
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
|
|
@ -218,8 +204,7 @@ void updateBoard(
|
||||||
}
|
}
|
||||||
|
|
||||||
int askColumn(
|
int askColumn(
|
||||||
const board_t board,
|
const board_t board
|
||||||
const move_t move
|
|
||||||
){
|
){
|
||||||
int column = 0;
|
int column = 0;
|
||||||
#ifdef ARROWS
|
#ifdef ARROWS
|
||||||
|
|
@ -244,33 +229,15 @@ int askColumn(
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
switch( move ){
|
for(; board.height[ column ] >= board.rows; ) switch( ch ){
|
||||||
case PUT:
|
case KEY_RIGHT:
|
||||||
for(; board.height[ column ] >= board.rows; ) switch( ch ){
|
if( column >= board.columns ) ch = KEY_LEFT;
|
||||||
case KEY_RIGHT:
|
else column++;
|
||||||
if( column >= board.columns ) ch = KEY_LEFT;
|
|
||||||
else column++;
|
|
||||||
break;
|
|
||||||
case KEY_LEFT:
|
|
||||||
if( column == 0 ) ch = KEY_RIGHT;
|
|
||||||
else column--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case POP:
|
case KEY_LEFT:
|
||||||
for(; board.height[ column ] <= 0; ) switch( ch ){
|
if( column == 0 ) ch = KEY_RIGHT;
|
||||||
case KEY_RIGHT:
|
else column--;
|
||||||
if( column >= board.columns ) ch = KEY_LEFT;
|
|
||||||
else column++;
|
|
||||||
break;
|
|
||||||
case KEY_LEFT:
|
|
||||||
if( column == 0 ) ch = KEY_RIGHT;
|
|
||||||
else column--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
// Do nothing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* !ARROWS */
|
#else /* !ARROWS */
|
||||||
|
|
@ -282,14 +249,7 @@ int askColumn(
|
||||||
);
|
);
|
||||||
if( board.player ) addstr( "1" );
|
if( board.player ) addstr( "1" );
|
||||||
else addstr( "0" );
|
else addstr( "0" );
|
||||||
switch( move ){
|
addstr( " put the piece? " );
|
||||||
case PUT:
|
|
||||||
addstr( " put the piece? " );
|
|
||||||
case POP:
|
|
||||||
addstr( " pop a piece? " );
|
|
||||||
default:
|
|
||||||
addstr( " Undefined move a thingy? " );
|
|
||||||
}
|
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
refresh();
|
refresh();
|
||||||
scanw( " %d", &column );
|
scanw( " %d", &column );
|
||||||
|
|
@ -300,30 +260,14 @@ int askColumn(
|
||||||
);
|
);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
if( column >= 0 && column < board.columns )
|
if( column >= 0 && column < board.columns )
|
||||||
switch( move ){
|
if( board.height [ column ] < board.columns )
|
||||||
case PUT:
|
return column;
|
||||||
if( board.height [ column ] < board.columns )
|
else addstr( "Pls enter a column that ain't full" );
|
||||||
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" );
|
else addstr( "Pls enter a column that exists" );
|
||||||
}
|
}
|
||||||
#endif /* ! ARROWS */
|
#endif /* ! ARROWS */
|
||||||
}
|
}
|
||||||
|
|
||||||
move_t askMove( void ){
|
|
||||||
move_t move = PUT;
|
|
||||||
// TODO: actually ask what move
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef INPUT_X
|
#undef INPUT_X
|
||||||
#undef INPUT_Y
|
#undef INPUT_Y
|
||||||
#undef SCOREBOARD_X
|
#undef SCOREBOARD_X
|
||||||
|
|
|
||||||
63
ui_vt100.c
63
ui_vt100.c
|
|
@ -69,31 +69,16 @@ void initBoard( const board_t board ){
|
||||||
void updateBoard(
|
void updateBoard(
|
||||||
const wins_t wins,
|
const wins_t wins,
|
||||||
const board_t board,
|
const board_t board,
|
||||||
const move_t move,
|
|
||||||
const int column
|
const int column
|
||||||
){
|
){
|
||||||
int height = board.height [ column ];
|
int height = board.height [ column ];
|
||||||
switch( move ){
|
printf(
|
||||||
case PUT: // Only print the put one
|
"\033[%dA\033[%dC%c\033[%dB",
|
||||||
printf(
|
height + 3,
|
||||||
"\033[%dA\033[%dC%c\033[%dB",
|
column * 3 + 4,
|
||||||
height + 3,
|
'0' + !!( board.player ),
|
||||||
column * 3 + 4,
|
height + 1
|
||||||
'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(
|
printf(
|
||||||
"\r\033[7A\033[%dC"
|
"\r\033[7A\033[%dC"
|
||||||
"%3d │%3d\033[B\033[8D"
|
"%3d │%3d\033[B\033[8D"
|
||||||
|
|
@ -112,18 +97,11 @@ void updateBoard(
|
||||||
}
|
}
|
||||||
|
|
||||||
int askColumn(
|
int askColumn(
|
||||||
const board_t board,
|
const board_t board
|
||||||
const move_t move
|
|
||||||
){
|
){
|
||||||
int column;
|
int column;
|
||||||
for(;;){
|
for(;;){
|
||||||
switch( move ){
|
printf( "Wher player %d put? ", board.player );
|
||||||
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( "\033[K" ); // clear everything after cursor
|
printf( "\033[K" ); // clear everything after cursor
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
column = -1;
|
column = -1;
|
||||||
|
|
@ -141,32 +119,15 @@ int askColumn(
|
||||||
}
|
}
|
||||||
column -= FIRST_NUMBER;
|
column -= FIRST_NUMBER;
|
||||||
if( column >= 0 && column < board.columns )
|
if( column >= 0 && column < board.columns )
|
||||||
switch( move ){
|
if( board.height [ column ] < board.rows )
|
||||||
case PUT:
|
return column;
|
||||||
if( board.height [ column ] < board.rows )
|
else printf( "\033[2Apls enter a column that ain't full" );
|
||||||
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
|
else
|
||||||
printf( "\033[2Apls enter valid column" );
|
printf( "\033[2Apls enter valid column" );
|
||||||
printf( "\033[K\n" );
|
printf( "\033[K\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move_t askMove( void ){
|
|
||||||
move_t move = PUT;
|
|
||||||
// TODO: actually ask what move
|
|
||||||
return move;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef BOARD_WIDTH_CHARS
|
#undef BOARD_WIDTH_CHARS
|
||||||
#undef SCOREBOARD_OFFSET
|
#undef SCOREBOARD_OFFSET
|
||||||
#undef SCOREBOARD_WIDTH
|
#undef SCOREBOARD_WIDTH
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue