Added command-line option for setting size of board
This commit is contained in:
parent
e47d63b430
commit
72b6290798
6 changed files with 101 additions and 74 deletions
80
connect4.c
80
connect4.c
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
@ -25,7 +26,7 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
#define VERSION 0.0.5
|
#define VERSION 0.1.0
|
||||||
|
|
||||||
#define VERSIONSTRING \
|
#define VERSIONSTRING \
|
||||||
"AnnaConnect version "XSTR(VERSION)", Copyright (C) Anna Snoeijs\n"
|
"AnnaConnect version "XSTR(VERSION)", Copyright (C) Anna Snoeijs\n"
|
||||||
|
|
@ -36,19 +37,37 @@ extern char _binary_LICENSE_start[];
|
||||||
extern char _binary_LICENSE_end[];
|
extern char _binary_LICENSE_end[];
|
||||||
|
|
||||||
int main( int argc, char *argv[] ){
|
int main( int argc, char *argv[] ){
|
||||||
|
// Initialise variables
|
||||||
|
wins_t wins = {
|
||||||
|
.count0 = {
|
||||||
|
.total = 0,
|
||||||
|
.vertical = 0,
|
||||||
|
.horizontal = 0,
|
||||||
|
.diagonalUp = 0,
|
||||||
|
.diagonalDown = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
wins.count1 = wins.count0;
|
||||||
|
board_t playboard = {
|
||||||
|
.player = 0,
|
||||||
|
.rows = BOARD_HEIGHT,
|
||||||
|
.columns = BOARD_WIDTH
|
||||||
|
};
|
||||||
// Parse options
|
// Parse options
|
||||||
for(;;){
|
for(;;){
|
||||||
// Allowed options
|
// Allowed options
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "license", no_argument, NULL, 'l' },
|
{ "license", no_argument, NULL, 'l' },
|
||||||
{ "version", no_argument, NULL, '\0' },
|
{ "version", no_argument, NULL, '\0' },
|
||||||
|
{ "columns", required_argument, NULL, 'c' },
|
||||||
|
{ "rows", required_argument, NULL, 'r' },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
// Index of current option
|
// Index of current option
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
// Get next option
|
// Get next option
|
||||||
char c = getopt_long( argc, argv, "hl", long_options, &option_index );
|
char c = getopt_long( argc, argv, "hlc:r:", long_options, &option_index );
|
||||||
if( c == -1 ) break;
|
if( c == -1 ) break;
|
||||||
// Handle option
|
// Handle option
|
||||||
switch( c ){
|
switch( c ){
|
||||||
|
|
@ -86,6 +105,12 @@ int main( int argc, char *argv[] ){
|
||||||
putchar( *p );
|
putchar( *p );
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
case 'c': // --columns
|
||||||
|
playboard.columns = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'r': // --rows
|
||||||
|
playboard.rows = atoi(optarg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for unhandled options
|
// Check for unhandled options
|
||||||
|
|
@ -95,6 +120,14 @@ int main( int argc, char *argv[] ){
|
||||||
printf( "%s ", argv[optind++] );
|
printf( "%s ", argv[optind++] );
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
}
|
}
|
||||||
|
if( playboard.rows < 1 ){
|
||||||
|
fprintf( stderr, "ERR: AMOUT OF ROWS MUST BE AT LEAST 1\n" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if( playboard.rows >= 32 ){
|
||||||
|
fprintf( stderr, "ERR: AMOUT OF ROWS MUST BE LESS THAN 32\n" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// Start the actual program
|
// Start the actual program
|
||||||
printf(
|
printf(
|
||||||
VERSIONSTRING
|
VERSIONSTRING
|
||||||
|
|
@ -103,30 +136,19 @@ int main( int argc, char *argv[] ){
|
||||||
"under certain condtions. See `%s --license`\n", argv[0]
|
"under certain condtions. See `%s --license`\n", argv[0]
|
||||||
);
|
);
|
||||||
// board, innit?
|
// board, innit?
|
||||||
initBoard();
|
playboard.height = calloc( playboard.columns, sizeof(int) );
|
||||||
board_t playboard = {
|
playboard.column = calloc( playboard.columns, sizeof(int) );
|
||||||
.player = 0,
|
wins.win0 = calloc( playboard.columns, sizeof(int) );
|
||||||
.column = {0},
|
wins.win1 = calloc( playboard.columns, sizeof(int) );
|
||||||
.height = {0},
|
wins.same.vertical2 = calloc( playboard.columns, sizeof(int) );
|
||||||
};
|
wins.same.horizontal2 = calloc( playboard.columns, sizeof(int) );
|
||||||
wins_t wins = {
|
wins.same.diagonalUp2 = calloc( playboard.columns, sizeof(int) );
|
||||||
.count0 = {
|
wins.same.diagonalDown2 = calloc( playboard.columns, sizeof(int) );
|
||||||
.total = 0,
|
wins.same.vertical4 = calloc( playboard.columns, sizeof(int) );
|
||||||
.vertical = 0,
|
wins.same.horizontal4 = calloc( playboard.columns, sizeof(int) );
|
||||||
.horizontal = 0,
|
wins.same.diagonalUp4 = calloc( playboard.columns, sizeof(int) );
|
||||||
.diagonalUp = 0,
|
wins.same.diagonalDown4 = calloc( playboard.columns, sizeof(int) );
|
||||||
.diagonalDown = 0,
|
initBoard( playboard );
|
||||||
},
|
|
||||||
.count1 = {
|
|
||||||
.total = 0,
|
|
||||||
.vertical = 0,
|
|
||||||
.horizontal = 0,
|
|
||||||
.diagonalUp = 0,
|
|
||||||
.diagonalDown = 0,
|
|
||||||
},
|
|
||||||
.win0 = {0},
|
|
||||||
.win1 = {0},
|
|
||||||
};
|
|
||||||
// Begin loopin
|
// Begin loopin
|
||||||
for(;; playboard.player = !playboard.player ){
|
for(;; playboard.player = !playboard.player ){
|
||||||
move_t move = askMove();
|
move_t move = askMove();
|
||||||
|
|
|
||||||
6
logic.c
6
logic.c
|
|
@ -62,7 +62,7 @@ void calcWins(
|
||||||
// First the simplest win, the humble tower
|
// First the simplest win, the humble tower
|
||||||
wins->count0.vertical = 0;
|
wins->count0.vertical = 0;
|
||||||
wins->count1.vertical = 0;
|
wins->count1.vertical = 0;
|
||||||
for( int i = 0; i < BOARD_WIDTH; i++ ){
|
for( int i = 0; i < board.columns; i++ ){
|
||||||
// Check for lil towers
|
// Check for lil towers
|
||||||
wins->same.vertical2 [ i ] =
|
wins->same.vertical2 [ i ] =
|
||||||
~( board.column [ i ]
|
~( board.column [ i ]
|
||||||
|
|
@ -89,7 +89,7 @@ void calcWins(
|
||||||
wins->count0.diagonalDown = 0;
|
wins->count0.diagonalDown = 0;
|
||||||
wins->count1.diagonalDown = 0;
|
wins->count1.diagonalDown = 0;
|
||||||
// First connect 2
|
// First connect 2
|
||||||
for( int i = 0; i < BOARD_WIDTH - 1; i++ ){
|
for( int i = 0; i < board.columns - 1; i++ ){
|
||||||
wins->same.horizontal2 [ i ] =
|
wins->same.horizontal2 [ i ] =
|
||||||
~( board.column [ i ]
|
~( board.column [ i ]
|
||||||
^ board.column [ i + 1 ] )
|
^ board.column [ i + 1 ] )
|
||||||
|
|
@ -114,7 +114,7 @@ void calcWins(
|
||||||
& ~1; // A diagonal line down ain't starts at the floor innit?
|
& ~1; // A diagonal line down ain't starts at the floor innit?
|
||||||
}
|
}
|
||||||
// Then stitch the twos together and count
|
// Then stitch the twos together and count
|
||||||
for( int i = 0; i < BOARD_WIDTH - 3; i++ ){
|
for( int i = 0; i < board.columns - 3; i++ ){
|
||||||
wins->same.horizontal4 [ i ] =
|
wins->same.horizontal4 [ i ] =
|
||||||
wins->same.horizontal2 [ i ]
|
wins->same.horizontal2 [ i ]
|
||||||
& wins->same.horizontal2 [ i + 1 ]
|
& wins->same.horizontal2 [ i + 1 ]
|
||||||
|
|
|
||||||
27
types.h
27
types.h
|
|
@ -1,6 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
@ -10,19 +11,21 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int player;
|
int player;
|
||||||
int height [ BOARD_WIDTH ];
|
int *height;
|
||||||
int column [ BOARD_WIDTH ];
|
int *column;
|
||||||
|
uint8_t rows;
|
||||||
|
uint8_t columns;
|
||||||
} board_t;
|
} board_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int vertical2 [ BOARD_WIDTH ];
|
int *vertical2;
|
||||||
int horizontal2 [ BOARD_WIDTH - 1 ];
|
int *horizontal2;
|
||||||
int diagonalUp2 [ BOARD_WIDTH - 1 ];
|
int *diagonalUp2;
|
||||||
int diagonalDown2 [ BOARD_WIDTH - 1 ];
|
int *diagonalDown2;
|
||||||
int vertical4 [ BOARD_WIDTH ];
|
int *vertical4;
|
||||||
int horizontal4 [ BOARD_WIDTH - 3 ];
|
int *horizontal4;
|
||||||
int diagonalUp4 [ BOARD_WIDTH - 3 ];
|
int *diagonalUp4;
|
||||||
int diagonalDown4 [ BOARD_WIDTH - 3 ];
|
int *diagonalDown4;
|
||||||
} directions_t;
|
} directions_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -36,7 +39,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
wincount_t count0;
|
wincount_t count0;
|
||||||
wincount_t count1;
|
wincount_t count1;
|
||||||
int win0 [ BOARD_WIDTH ];
|
int *win0;
|
||||||
int win1 [ BOARD_WIDTH ];
|
int *win1;
|
||||||
directions_t same;
|
directions_t same;
|
||||||
} wins_t;
|
} wins_t;
|
||||||
|
|
|
||||||
4
ui.h
4
ui.h
|
|
@ -4,7 +4,9 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
extern void initBoard( void );
|
extern void initBoard(
|
||||||
|
const board_t board
|
||||||
|
);
|
||||||
|
|
||||||
extern void updateBoard(
|
extern void updateBoard(
|
||||||
const wins_t wins,
|
const wins_t wins,
|
||||||
|
|
|
||||||
36
ui_ncurses.c
36
ui_ncurses.c
|
|
@ -65,13 +65,13 @@
|
||||||
#define SCOREBOARD_HEIGHT 10
|
#define SCOREBOARD_HEIGHT 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initBoard( void ){
|
void initBoard( const board_t board ){
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
nonl();
|
nonl();
|
||||||
echo();
|
echo();
|
||||||
for( int column = 0; column < BOARD_WIDTH; column++ ){
|
for( int column = 0; column < board.columns; column++ ){
|
||||||
char colnum[4];
|
char colnum[4];
|
||||||
sprintf( colnum, "%2d", column + FIRST_NUMBER );
|
sprintf( colnum, "%2d", column + FIRST_NUMBER );
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
|
|
@ -79,7 +79,7 @@ void initBoard( void ){
|
||||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||||
colnum
|
colnum
|
||||||
);
|
);
|
||||||
for(int row = 0; row < BOARD_HEIGHT; row++){
|
for(int row = 0; row < board.rows; row++){
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||||
|
|
@ -87,14 +87,14 @@ void initBoard( void ){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( BOARD_HEIGHT + 1 ),
|
BOARD_Y + BOARD_DY * ( board.rows + 1 ),
|
||||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||||
colnum
|
colnum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for(int row = 0; row < BOARD_HEIGHT; row++ ){
|
for(int row = 0; row < board.rows; row++ ){
|
||||||
char rownum[4];
|
char rownum[4];
|
||||||
sprintf( rownum, "%2d", row + FIRST_NUMBER );
|
sprintf( rownum, "%2d", board.rows - row + FIRST_NUMBER - 1 );
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||||
BOARD_X,
|
BOARD_X,
|
||||||
|
|
@ -102,7 +102,7 @@ void initBoard( void ){
|
||||||
);
|
);
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||||
BOARD_X + BOARD_DX * ( BOARD_WIDTH + 1 ),
|
BOARD_X + BOARD_DX * ( board.columns + 1 ),
|
||||||
rownum
|
rownum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +139,7 @@ void updateBoard(
|
||||||
switch( move ){
|
switch( move ){
|
||||||
case PUT:
|
case PUT:
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( BOARD_HEIGHT - height + 1 ),
|
BOARD_Y + BOARD_DY * ( board.rows - height + 1 ),
|
||||||
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||||
board.column[ column ] & 1 << ( height - 1 ) ? "1" : "0"
|
board.column[ column ] & 1 << ( height - 1 ) ? "1" : "0"
|
||||||
);
|
);
|
||||||
|
|
@ -147,7 +147,7 @@ void updateBoard(
|
||||||
default:
|
default:
|
||||||
for( int row = 0; row < height; row++ ){
|
for( int row = 0; row < height; row++ ){
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
BOARD_Y + BOARD_DY * ( BOARD_HEIGHT - row ),
|
BOARD_Y + BOARD_DY * ( board.rows - row ),
|
||||||
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||||
board.column[ column ] & 1 << row ? "1" : "0"
|
board.column[ column ] & 1 << row ? "1" : "0"
|
||||||
);
|
);
|
||||||
|
|
@ -227,16 +227,16 @@ int askColumn(
|
||||||
if( board.player ) addstr( "p1" );
|
if( board.player ) addstr( "p1" );
|
||||||
else addstr( "p0" );
|
else addstr( "p0" );
|
||||||
refresh();
|
refresh();
|
||||||
for(; board.height[ column ] >= BOARD_HEIGHT; )
|
for(; board.height[ column ] >= board.rows; )
|
||||||
column += ( column < BOARD_WIDTH - 1 );
|
column += ( column < board.columns - 1 );
|
||||||
for(;;){
|
for(;;){
|
||||||
int ch = mvgetch(
|
int ch = mvgetch(
|
||||||
BOARD_Y + BOARD_DY * ( BOARD_HEIGHT - board.height[ column ] ),
|
BOARD_Y + BOARD_DY * ( board.rows - board.height[ column ] ),
|
||||||
BOARD_X + 1 + BOARD_DX * ( column + 1 )
|
BOARD_X + 1 + BOARD_DX * ( column + 1 )
|
||||||
);
|
);
|
||||||
switch( ch ){
|
switch( ch ){
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
column += ( column < BOARD_WIDTH - 1 );
|
column += ( column < board.columns - 1 );
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
column -= ( column > 0 );
|
column -= ( column > 0 );
|
||||||
|
|
@ -246,9 +246,9 @@ int askColumn(
|
||||||
}
|
}
|
||||||
switch( move ){
|
switch( move ){
|
||||||
case PUT:
|
case PUT:
|
||||||
for(; board.height[ column ] >= BOARD_HEIGHT; ) switch( ch ){
|
for(; board.height[ column ] >= board.rows; ) switch( ch ){
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if( column >= BOARD_WIDTH ) ch = KEY_LEFT;
|
if( column >= board.columns ) ch = KEY_LEFT;
|
||||||
else column++;
|
else column++;
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
|
|
@ -260,7 +260,7 @@ int askColumn(
|
||||||
case POP:
|
case POP:
|
||||||
for(; board.height[ column ] <= 0; ) switch( ch ){
|
for(; board.height[ column ] <= 0; ) switch( ch ){
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if( column >= BOARD_WIDTH ) ch = KEY_LEFT;
|
if( column >= board.columns ) ch = KEY_LEFT;
|
||||||
else column++;
|
else column++;
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
|
|
@ -296,10 +296,10 @@ int askColumn(
|
||||||
INPUT_X
|
INPUT_X
|
||||||
);
|
);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
if( column >= 0 && column < BOARD_WIDTH )
|
if( column >= 0 && column < board.columns )
|
||||||
switch( move ){
|
switch( move ){
|
||||||
case PUT:
|
case PUT:
|
||||||
if( board.height [ column ] < BOARD_HEIGHT )
|
if( board.height [ column ] < board.columns )
|
||||||
return column;
|
return column;
|
||||||
else addstr( "Pls enter a column that ain't full" );
|
else addstr( "Pls enter a column that ain't full" );
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
22
ui_vt100.c
22
ui_vt100.c
|
|
@ -21,22 +21,22 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#define BOARD_WIDTH_CHARS ( 3 * BOARD_WIDTH + 6 )
|
#define BOARD_WIDTH_CHARS ( 3 * board.columns + 6 )
|
||||||
#define SCOREBOARD_OFFSET 5
|
#define SCOREBOARD_OFFSET 5
|
||||||
#define SCOREBOARD_WIDTH 27
|
#define SCOREBOARD_WIDTH 27
|
||||||
#define SCOREBOARD_HEIGHT 9
|
#define SCOREBOARD_HEIGHT 9
|
||||||
|
|
||||||
void initBoard( void ){
|
void initBoard( const board_t board ){
|
||||||
for( int i = SCOREBOARD_HEIGHT - ( BOARD_HEIGHT + 2 ); i > 0; i-- )
|
for( int i = SCOREBOARD_HEIGHT - ( board.rows + 2 ); i > 0; i-- )
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
printf( "\n " );
|
printf( "\n " );
|
||||||
for( int column = 0; column < BOARD_WIDTH; column++ )
|
for( int column = 0; column < board.columns; column++ )
|
||||||
printf( "%2d ", column + FIRST_NUMBER );
|
printf( "%2d ", column + FIRST_NUMBER );
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
for( int row = BOARD_HEIGHT - 1; row > -1; row-- ){
|
for( int row = board.rows - 1; row > -1; row-- ){
|
||||||
// begin row
|
// begin row
|
||||||
printf( "%2d " , row + FIRST_NUMBER );
|
printf( "%2d " , row + FIRST_NUMBER );
|
||||||
for( int column = 0; column < BOARD_WIDTH; column++ )
|
for( int column = 0; column < board.columns; column++ )
|
||||||
printf( "[ ]" );
|
printf( "[ ]" );
|
||||||
// end of row
|
// end of row
|
||||||
printf( "%2d" , row + FIRST_NUMBER );
|
printf( "%2d" , row + FIRST_NUMBER );
|
||||||
|
|
@ -46,7 +46,7 @@ void initBoard( void ){
|
||||||
}
|
}
|
||||||
// end of board
|
// end of board
|
||||||
printf( " " );
|
printf( " " );
|
||||||
for( int column = 0; column < BOARD_WIDTH; column++ )
|
for( int column = 0; column < board.columns; column++ )
|
||||||
printf( "%2d ", column + FIRST_NUMBER );
|
printf( "%2d ", column + FIRST_NUMBER );
|
||||||
#define SCOREBOARD_LINE_END "\033[B\033["XSTR(SCOREBOARD_WIDTH)"D"
|
#define SCOREBOARD_LINE_END "\033[B\033["XSTR(SCOREBOARD_WIDTH)"D"
|
||||||
printf("\033["XSTR(SCOREBOARD_OFFSET)"C\033["XSTR(SCOREBOARD_HEIGHT)"A"
|
printf("\033["XSTR(SCOREBOARD_OFFSET)"C\033["XSTR(SCOREBOARD_HEIGHT)"A"
|
||||||
|
|
@ -85,7 +85,7 @@ void updateBoard(
|
||||||
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 );
|
||||||
if( height < BOARD_HEIGHT ) printf( "\033[%dC ", column * 3 + 4 );
|
if( height < board.rows ) printf( "\033[%dC ", column * 3 + 4 );
|
||||||
else printf( "\033[%dC", column * 3 + 5 );
|
else printf( "\033[%dC", column * 3 + 5 );
|
||||||
for( int row = height; row --> 0; )
|
for( int row = height; row --> 0; )
|
||||||
printf(
|
printf(
|
||||||
|
|
@ -101,7 +101,7 @@ void updateBoard(
|
||||||
"%3d │%3d\033[B\033[8D"
|
"%3d │%3d\033[B\033[8D"
|
||||||
"%3d │%3d\033[2B\033[8D"
|
"%3d │%3d\033[2B\033[8D"
|
||||||
"%3d │%3d\033[2B"
|
"%3d │%3d\033[2B"
|
||||||
,BOARD_WIDTH_CHARS + SCOREBOARD_WIDTH - 8
|
,( 3 * board.columns + 6 ) + SCOREBOARD_WIDTH - 8
|
||||||
,wins.count0.vertical, wins.count1.vertical
|
,wins.count0.vertical, wins.count1.vertical
|
||||||
,wins.count0.horizontal, wins.count1.horizontal
|
,wins.count0.horizontal, wins.count1.horizontal
|
||||||
,wins.count0.diagonalUp, wins.count1.diagonalUp
|
,wins.count0.diagonalUp, wins.count1.diagonalUp
|
||||||
|
|
@ -138,10 +138,10 @@ int askColumn(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
column -= FIRST_NUMBER;
|
column -= FIRST_NUMBER;
|
||||||
if( column >= 0 && column < BOARD_WIDTH )
|
if( column >= 0 && column < board.columns )
|
||||||
switch( move ){
|
switch( move ){
|
||||||
case PUT:
|
case PUT:
|
||||||
if( board.height [ column ] < BOARD_HEIGHT )
|
if( board.height [ column ] < board.rows )
|
||||||
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" );
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue