From 89712fc9dcce09c8db800bffb86ac858a5eb7314 Mon Sep 17 00:00:00 2001 From: AnnaSnoeijs Date: Fri, 6 Jun 2025 21:31:59 +0200 Subject: [PATCH] Removed ONLYPUT --- .gitignore | 1 + config.h | 1 - connect4.c | 5 ----- logic.c | 6 ------ logic.h | 2 -- ui.h | 4 ---- ui_ncurses.c | 43 ++++++++++++++++++++++++------------------- ui_vt100.c | 16 ---------------- 8 files changed, 25 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 38e34c6..888f7a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ obj/ out/ +rpmbuild/ diff --git a/config.h b/config.h index 2df3233..f1e8451 100644 --- a/config.h +++ b/config.h @@ -6,5 +6,4 @@ #define FIRST_NUMBER 1 -#define ONLYPUT #define ARROWS diff --git a/connect4.c b/connect4.c index 5487c26..089064a 100644 --- a/connect4.c +++ b/connect4.c @@ -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 ); } diff --git a/logic.c b/logic.c index ed7c153..7c05cab 100644 --- a/logic.c +++ b/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( diff --git a/logic.h b/logic.h index 712ed87..744f01c 100644 --- a/logic.h +++ b/logic.h @@ -6,9 +6,7 @@ extern void playMove( board_t *boardptr, -#ifndef ONLYPUT const move_t move, -#endif /* ! ONLYPUT */ const int column ); diff --git a/ui.h b/ui.h index 4423255..5b8024b 100644 --- a/ui.h +++ b/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 */ diff --git a/ui_ncurses.c b/ui_ncurses.c index 5f1698f..88d0cfe 100644 --- a/ui_ncurses.c +++ b/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 diff --git a/ui_vt100.c b/ui_vt100.c index beda124..05e5a39 100644 --- a/ui_vt100.c +++ b/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