From b05a803cd83fa3460f9650a8de1a4c5e37cad2e0 Mon Sep 17 00:00:00 2001 From: AnnaSnoeijs Date: Fri, 6 Jun 2025 21:31:59 +0200 Subject: [PATCH] Fixed a typo --- config.h | 2 +- connect4.c | 2 +- logic.c | 24 ++++++++++++------------ types.h | 2 +- ui_ncurses.c | 28 ++++++++++++++-------------- ui_vt100.c | 26 +++++++++++++------------- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/config.h b/config.h index 361eb2e..2df3233 100644 --- a/config.h +++ b/config.h @@ -2,7 +2,7 @@ #pragma once #define BOARD_WIDTH 7 -#define BOARD_HEIGTH 6 +#define BOARD_HEIGHT 6 #define FIRST_NUMBER 1 diff --git a/connect4.c b/connect4.c index a18fd26..db13ac1 100644 --- a/connect4.c +++ b/connect4.c @@ -38,7 +38,7 @@ int main(){ board_t playboard = { .player = 0, .column = {0}, - .heigth = {0}, + .height = {0}, }; wins_t wins = { .count0 = { diff --git a/logic.c b/logic.c index 5b74d35..e5ea9de 100644 --- a/logic.c +++ b/logic.c @@ -26,12 +26,12 @@ static inline int bottom( const int a, const int b ){ return a < b ? a : b; } -static inline int heigthMask( const int a ){ +static inline int heightMask( const int a ){ return ( 1 << a ) - 1; } static inline int safeHeigthMask( const int a ){ - return a > 0 ? heigthMask( a ) : 0; + return a > 0 ? heightMask( a ) : 0; } static inline int bottomHeigthMask( const int a, const int b ){ @@ -50,13 +50,13 @@ void playMove( case PUT: // Put a new piece in the board #endif /* ! ONLYPUT */ boardptr->column [ column ] |= - boardptr->player << boardptr->heigth [ column ]; - boardptr->heigth [ 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->heigth [ column ]--; + boardptr->height [ column ]--; } #endif /* ! ONLYPUT */ } @@ -73,7 +73,7 @@ void calcWins( wins->same.vertical2 [ i ] = ~( board.column [ i ] ^ board.column [ i ] >> 1 ) - & safeHeigthMask( board.heigth [ i ] - 1 ); + & safeHeigthMask( board.height [ i ] - 1 ); // Actually check for win wins->same.vertical4 [ i ] = wins->same.vertical2 [ i ] @@ -100,22 +100,22 @@ void calcWins( ~( board.column [ i ] ^ board.column [ i + 1 ] ) & bottomHeigthMask( - board.heigth [ i ], - board.heigth [ i + 1 ] + board.height [ i ], + board.height [ i + 1 ] ); wins->same.diagonalUp2 [ i ] = ~( board.column [ i ] ^ board.column [ i + 1 ] >> 1 ) & bottomHeigthMask( - board.heigth [ i ], - board.heigth [ i + 1 ] - 1 + board.height [ i ], + board.height [ i + 1 ] - 1 ); wins->same.diagonalDown2 [ i ] = ~( board.column [ i ] ^ board.column [ i + 1 ] << 1 ) & bottomHeigthMask( - board.heigth [ i ], - board.heigth [ i + 1 ] + 1 + board.height [ i ], + board.height [ i + 1 ] + 1 ) & ~1; // A diagonal line down ain't starts at the floor innit? } diff --git a/types.h b/types.h index ca14da5..5ddc194 100644 --- a/types.h +++ b/types.h @@ -10,7 +10,7 @@ typedef enum { typedef struct { int player; - int heigth [ BOARD_WIDTH ]; + int height [ BOARD_WIDTH ]; int column [ BOARD_WIDTH ]; } board_t; diff --git a/ui_ncurses.c b/ui_ncurses.c index 9e01c9f..5f1698f 100644 --- a/ui_ncurses.c +++ b/ui_ncurses.c @@ -61,8 +61,8 @@ #define BOARD_DY 1 #endif -#ifndef SCOREBOARD_HEIGTH -#define SCOREBOARD_HEIGTH 10 +#ifndef SCOREBOARD_HEIGHT +#define SCOREBOARD_HEIGHT 10 #endif void initBoard( void ){ @@ -79,7 +79,7 @@ void initBoard( void ){ BOARD_X + BOARD_DX * ( column + 1 ), colnum ); - for(int row = 0; row < BOARD_HEIGTH; row++){ + for(int row = 0; row < BOARD_HEIGHT; row++){ mvaddstr( BOARD_Y + BOARD_DY * ( row + 1 ), BOARD_X + BOARD_DX * ( column + 1 ), @@ -87,12 +87,12 @@ void initBoard( void ){ ); } mvaddstr( - BOARD_Y + BOARD_DY * ( BOARD_HEIGTH + 1 ), + BOARD_Y + BOARD_DY * ( BOARD_HEIGHT + 1 ), BOARD_X + BOARD_DX * ( column + 1 ), colnum ); } - for(int row = 0; row < BOARD_HEIGTH; row++ ){ + for(int row = 0; row < BOARD_HEIGHT; row++ ){ char rownum[4]; sprintf( rownum, "%2d", row + FIRST_NUMBER ); mvaddstr( @@ -106,7 +106,7 @@ void initBoard( void ){ rownum ); } - for( int y = 0; y < SCOREBOARD_HEIGTH; y++ ){ + for( int y = 0; y < SCOREBOARD_HEIGHT; y++ ){ char *str; switch(y){ case 0: str = "┌───────────────┬────┬────┐"; break; @@ -134,9 +134,9 @@ void updateBoard( const board_t board, const int column ){ - for(int row = 0; row < board.heigth[ column ]; row++){ + for(int row = 0; row < board.height[ column ]; row++){ mvaddstr( - BOARD_Y + BOARD_DY * ( BOARD_HEIGTH - row ), + BOARD_Y + BOARD_DY * ( BOARD_HEIGHT - row ), BOARD_X + 1 + BOARD_DX * ( column + 1 ), board.column[ column ] & 1 << row ? "1" : "0" ); @@ -216,11 +216,11 @@ int askColumn( if( board.player ) addstr( "p1" ); else addstr( "p0" ); refresh(); - for(; board.heigth[ column ] >= BOARD_HEIGTH; ) + for(; board.height[ column ] >= BOARD_HEIGHT; ) column += ( column < BOARD_WIDTH - 1 ); for(;;){ int ch = mvgetch( - BOARD_Y + BOARD_DY * ( BOARD_HEIGTH - board.heigth[ column ] ), + BOARD_Y + BOARD_DY * ( BOARD_HEIGHT - board.height[ column ] ), BOARD_X + 1 + BOARD_DX * ( column + 1 ) ); switch( ch ){ @@ -233,7 +233,7 @@ int askColumn( case KEY_DOWN: return column; } - for(; board.heigth[ column ] >= BOARD_HEIGTH; ) switch( ch ){ + for(; board.height[ column ] >= BOARD_HEIGHT; ) switch( ch ){ case KEY_RIGHT: if( column >= BOARD_WIDTH ) ch = KEY_LEFT; else column++; @@ -277,13 +277,13 @@ int askColumn( switch( move ){ case PUT: #endif /* ! ONLYPUT */ - if( board.heigth [ column ] < BOARD_HEIGTH ) + 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.heigth [ column ] != 0 ) + if( board.height [ column ] != 0 ) return column; else addstr( "Pls enter a column that ain't empty" ); } @@ -309,4 +309,4 @@ move_t askMove( void ){ #undef BOARD_Y #undef BOARD_DX #undef BOARD_DY -#undef SCOREBOARD_HEIGTH +#undef SCOREBOARD_HEIGHT diff --git a/ui_vt100.c b/ui_vt100.c index 37cab86..58338c3 100644 --- a/ui_vt100.c +++ b/ui_vt100.c @@ -23,16 +23,16 @@ #define BOARD_WIDTH_CHARS ( 3 * BOARD_WIDTH + 6 ) #define SCOREBOARD_OFFSET 5 #define SCOREBOARD_WIDTH 27 -#define SCOREBOARD_HEIGTH 9 +#define SCOREBOARD_HEIGHT 9 void initBoard( void ){ - for( int i = SCOREBOARD_HEIGTH - ( BOARD_HEIGTH + 2 ); i > 0; i-- ) + for( int i = SCOREBOARD_HEIGHT - ( BOARD_HEIGTH + 2 ); i > 0; i-- ) putchar( '\n' ); printf( "\n " ); for( int column = 0; column < BOARD_WIDTH; column++ ) printf( "%2d ", column + FIRST_NUMBER ); putchar( '\n' ); - for( int row = BOARD_HEIGTH - 1; row > -1; row-- ){ + for( int row = BOARD_HEIGHT - 1; row > -1; row-- ){ // begin row printf( "%2d " , row + FIRST_NUMBER ); for( int column = 0; column < BOARD_WIDTH; column++ ) @@ -48,7 +48,7 @@ void initBoard( void ){ for( int column = 0; column < BOARD_WIDTH; column++ ) printf( "%2d ", column + FIRST_NUMBER ); #define SCOREBOARD_LINE_END "\033[B\033["XSTR(SCOREBOARD_WIDTH)"D" - printf("\033["XSTR(SCOREBOARD_OFFSET)"C\033["XSTR(SCOREBOARD_HEIGTH)"A" + printf("\033["XSTR(SCOREBOARD_OFFSET)"C\033["XSTR(SCOREBOARD_HEIGHT)"A" "┌───────────────┬────┬────┐"SCOREBOARD_LINE_END "│ player │ 0 │ 1 │"SCOREBOARD_LINE_END "├───────────────┼────┼────┤"SCOREBOARD_LINE_END @@ -70,25 +70,25 @@ void updateBoard( const board_t board, const int column ){ - int heigth = board.heigth [ column ]; + int height = board.heigth [ column ]; #ifndef ONLYPUT switch( move ){ case PUT: // Only print the put one #endif /* ! ONLYPUT */ printf( "\033[%dA\033[%dC%c\033[%dB", - heigth + 3, + height + 3, column * 3 + 4, '0' + !!( board.player ), - heigth + 1 + height + 1 ); #ifndef ONLYPUT break; default: // Print all the pieces in the column and the air above - printf( "\033[%dA", heigth + 4 ); - if( heigth < BOARD_HEIGTH ) printf( "\033[%dC ", column * 3 + 4 ); + printf( "\033[%dA", height + 4 ); + if( height < BOARD_HEIGHT ) printf( "\033[%dC ", column * 3 + 4 ); else printf( "\033[%dC", column * 3 + 5 ); - for( int row = heigth; row --> 0; ) + for( int row = height; row --> 0; ) printf( "\033[B\033[D%c", '0' + !!( board.column [ column ] & ( 1 << row ) ) @@ -138,13 +138,13 @@ int askColumn( switch( move ){ case PUT: #endif /* ! ONLYPUT */ - if( board.heigth [ column ] < BOARD_HEIGTH ) + 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.heigth [ column ] != 0 ) + if( board.height [ column ] != 0 ) return column; else printf( "\033[2Apls enter a column that ain't empty" ); } @@ -166,4 +166,4 @@ move_t askMove( void ){ #undef BOARD_WIDTH_CHARS #undef SCOREBOARD_OFFSET #undef SCOREBOARD_WIDTH -#undef SCOREBOARD_HEIGTH +#undef SCOREBOARD_HEIGHT