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