Removed ONLYPUT
This commit is contained in:
parent
4f25f66495
commit
89712fc9dc
8 changed files with 25 additions and 53 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
obj/
|
||||
out/
|
||||
rpmbuild/
|
||||
|
|
|
|||
1
config.h
1
config.h
|
|
@ -6,5 +6,4 @@
|
|||
|
||||
#define FIRST_NUMBER 1
|
||||
|
||||
#define ONLYPUT
|
||||
#define ARROWS
|
||||
|
|
|
|||
|
|
@ -59,14 +59,9 @@ int main(){
|
|||
.win1 = {0},
|
||||
};
|
||||
for(;; playboard.player = !playboard.player ){
|
||||
#ifndef ONLYPUT
|
||||
move_t move = askMove();
|
||||
int column = askColumn( playboard, move );
|
||||
playMove( &playboard, move, column );
|
||||
#else /* ONLYPUT */
|
||||
int column = askColumn( playboard );
|
||||
playMove( &playboard, column );
|
||||
#endif /* ONLYPUT */
|
||||
calcWins( &wins, playboard );
|
||||
updateBoard( wins, playboard, column );
|
||||
}
|
||||
|
|
|
|||
6
logic.c
6
logic.c
|
|
@ -40,25 +40,19 @@ static inline int bottomHeightMask( const int a, const int b ){
|
|||
|
||||
void playMove(
|
||||
board_t *boardptr,
|
||||
#ifndef ONLYPUT
|
||||
const move_t move,
|
||||
#endif /* ! ONLYPUT */
|
||||
const int column
|
||||
){
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT: // Put a new piece in the board
|
||||
#endif /* ! ONLYPUT */
|
||||
boardptr->column [ column ] |=
|
||||
boardptr->player << boardptr->height [ column ];
|
||||
boardptr->height [ column ]++;
|
||||
#ifndef ONLYPUT
|
||||
break;
|
||||
case POP: // Pop out the lowest and make all above fall down
|
||||
boardptr->column [ column ] >>= 1;
|
||||
boardptr->height [ column ]--;
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
}
|
||||
|
||||
void calcWins(
|
||||
|
|
|
|||
2
logic.h
2
logic.h
|
|
@ -6,9 +6,7 @@
|
|||
|
||||
extern void playMove(
|
||||
board_t *boardptr,
|
||||
#ifndef ONLYPUT
|
||||
const move_t move,
|
||||
#endif /* ! ONLYPUT */
|
||||
const int column
|
||||
);
|
||||
|
||||
|
|
|
|||
4
ui.h
4
ui.h
|
|
@ -14,11 +14,7 @@ extern void updateBoard(
|
|||
|
||||
extern int askColumn(
|
||||
const board_t board
|
||||
#ifndef ONLYPUT
|
||||
,const move_t move
|
||||
#endif /* ! ONLYPUT */
|
||||
);
|
||||
|
||||
#ifndef ONLYPUT
|
||||
extern move_t askMove( void );
|
||||
#endif /* ! ONLYPUT */
|
||||
|
|
|
|||
43
ui_ncurses.c
43
ui_ncurses.c
|
|
@ -206,9 +206,7 @@ void updateBoard(
|
|||
|
||||
int askColumn(
|
||||
const board_t board
|
||||
#ifndef ONLYPUT
|
||||
,const move_t move
|
||||
#endif /* ONLYPUT */
|
||||
){
|
||||
int column = 0;
|
||||
#ifdef ARROWS
|
||||
|
|
@ -233,15 +231,32 @@ int askColumn(
|
|||
case KEY_DOWN:
|
||||
return column;
|
||||
}
|
||||
for(; board.height[ column ] >= BOARD_HEIGHT; ) switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
if( column >= BOARD_WIDTH ) ch = KEY_LEFT;
|
||||
else column++;
|
||||
switch( move ){
|
||||
case PUT:
|
||||
for(; board.height[ column ] >= BOARD_HEIGHT; ) switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
if( column >= BOARD_WIDTH ) ch = KEY_LEFT;
|
||||
else column++;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if( column == 0 ) ch = KEY_RIGHT;
|
||||
else column--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if( column == 0 ) ch = KEY_RIGHT;
|
||||
else column--;
|
||||
case POP:
|
||||
for(; board.height[ column ] <= 0; ) switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
if( column >= BOARD_WIDTH ) ch = KEY_LEFT;
|
||||
else column++;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if( column == 0 ) ch = KEY_RIGHT;
|
||||
else column--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
#else /* !ARROWS */
|
||||
|
|
@ -253,16 +268,12 @@ int askColumn(
|
|||
);
|
||||
if( board.player ) addstr( "1" );
|
||||
else addstr( "0" );
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT:
|
||||
#endif /* ONLYPUT */
|
||||
addstr( " put the piece? " );
|
||||
#ifndef ONLYPUT
|
||||
case POP:
|
||||
addstr( " pop a piece? " );
|
||||
}
|
||||
#endif /* ONLYPUT */
|
||||
clrtoeol();
|
||||
refresh();
|
||||
scanw( " %d", &column );
|
||||
|
|
@ -273,33 +284,27 @@ int askColumn(
|
|||
);
|
||||
clrtoeol();
|
||||
if( column >= 0 && column < BOARD_WIDTH )
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT:
|
||||
#endif /* ! ONLYPUT */
|
||||
if( board.height [ column ] < BOARD_HEIGHT )
|
||||
return column;
|
||||
else addstr( "Pls enter a column that ain't full" );
|
||||
#ifndef ONLYPUT
|
||||
break;
|
||||
case POP:
|
||||
if( board.height [ column ] != 0 )
|
||||
return column;
|
||||
else addstr( "Pls enter a column that ain't empty" );
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
else addstr( "Pls enter a column that exists" );
|
||||
}
|
||||
#endif /* ! ARROWS */
|
||||
}
|
||||
|
||||
#ifndef ONLYPUT
|
||||
move_t askMove( void ){
|
||||
move_t move = PUT;
|
||||
// TODO: actually ask what move
|
||||
return move;
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
|
||||
#undef INPUT_X
|
||||
#undef INPUT_Y
|
||||
|
|
|
|||
16
ui_vt100.c
16
ui_vt100.c
|
|
@ -72,10 +72,8 @@ void updateBoard(
|
|||
const int column
|
||||
){
|
||||
int height = board.height [ column ];
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT: // Only print the put one
|
||||
#endif /* ! ONLYPUT */
|
||||
printf(
|
||||
"\033[%dA\033[%dC%c\033[%dB",
|
||||
height + 3,
|
||||
|
|
@ -83,7 +81,6 @@ void updateBoard(
|
|||
'0' + !!( board.player ),
|
||||
height + 1
|
||||
);
|
||||
#ifndef ONLYPUT
|
||||
break;
|
||||
default: // Print all the pieces in the column and the air above
|
||||
printf( "\033[%dA", height + 4 );
|
||||
|
|
@ -96,7 +93,6 @@ void updateBoard(
|
|||
);
|
||||
printf( "\033[2B" );
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
printf(
|
||||
"\r\033[7A\033[%dC"
|
||||
"%3d │%3d\033[B\033[8D"
|
||||
|
|
@ -116,21 +112,15 @@ void updateBoard(
|
|||
|
||||
int askColumn(
|
||||
const board_t board
|
||||
#ifndef ONLYPUT
|
||||
,const move_t move
|
||||
#endif /* ONLYPUT */
|
||||
){
|
||||
int column;
|
||||
for(;;){
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT: printf( "Wher player %d put? ", board.player );
|
||||
break;
|
||||
case POP: printf( "Wher player %d pop? ", board.player );
|
||||
}
|
||||
#else /* ONLYPUT */
|
||||
printf( "Wher player %d put? ", board.player );
|
||||
#endif /* ONLYPUT */
|
||||
printf( "\033[K" ); // clear everything after cursor
|
||||
fflush( stdout );
|
||||
column = -1;
|
||||
|
|
@ -148,34 +138,28 @@ int askColumn(
|
|||
}
|
||||
column -= FIRST_NUMBER;
|
||||
if( column >= 0 && column < BOARD_WIDTH )
|
||||
#ifndef ONLYPUT
|
||||
switch( move ){
|
||||
case PUT:
|
||||
#endif /* ! ONLYPUT */
|
||||
if( board.height [ column ] < BOARD_HEIGHT )
|
||||
return column;
|
||||
else printf( "\033[2Apls enter a column that ain't full" );
|
||||
#ifndef ONLYPUT
|
||||
break;
|
||||
case POP:
|
||||
if( board.height [ column ] != 0 )
|
||||
return column;
|
||||
else printf( "\033[2Apls enter a column that ain't empty" );
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
else
|
||||
printf( "\033[2Apls enter valid column" );
|
||||
printf( "\033[K\n" );
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef ONLYPUT
|
||||
move_t askMove( void ){
|
||||
move_t move = PUT;
|
||||
// TODO: actually ask what move
|
||||
return move;
|
||||
}
|
||||
#endif /* ! ONLYPUT */
|
||||
|
||||
#undef BOARD_WIDTH_CHARS
|
||||
#undef SCOREBOARD_OFFSET
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue