Added option to disable command-line options
This commit is contained in:
parent
cbe9d25f11
commit
f59be8398d
1 changed files with 24 additions and 5 deletions
29
connect4.c
29
connect4.c
|
|
@ -20,7 +20,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
@ -39,12 +41,14 @@
|
||||||
#define VERSIONSTRING \
|
#define VERSIONSTRING \
|
||||||
"AnnaConnect version "XSTR(FULLVERSION)", Copyright (C) Anna Snoeijs\n"
|
"AnnaConnect version "XSTR(FULLVERSION)", Copyright (C) Anna Snoeijs\n"
|
||||||
|
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
// The LISENCE file
|
// The LISENCE file
|
||||||
// Not null-terminated so need pointers for both start and end
|
// Not null-terminated so need pointers for both start and end
|
||||||
extern char _binary_LICENSE_start[];
|
extern char _binary_LICENSE_start[];
|
||||||
extern char _binary_LICENSE_end[];
|
extern char _binary_LICENSE_end[];
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
|
|
||||||
int main( int argc, char *argv[] ){
|
int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
||||||
// Initialise variables
|
// Initialise variables
|
||||||
board_t playboard = {
|
board_t playboard = {
|
||||||
.player = 0,
|
.player = 0,
|
||||||
|
|
@ -53,9 +57,10 @@ int main( int argc, char *argv[] ){
|
||||||
.count0 = {0},
|
.count0 = {0},
|
||||||
.count1 = {0},
|
.count1 = {0},
|
||||||
};
|
};
|
||||||
|
wins_t *wins = malloc( sizeof(wins_t) );
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
FILE *outputfile = NULL;
|
FILE *outputfile = NULL;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
wins_t *wins = malloc( sizeof(wins_t) );
|
|
||||||
bool randomMoves = 0;
|
bool randomMoves = 0;
|
||||||
// Parse options
|
// Parse options
|
||||||
for(;;){
|
for(;;){
|
||||||
|
|
@ -158,12 +163,18 @@ int main( int argc, char *argv[] ){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#undef ROWOVERFLOW
|
#undef ROWOVERFLOW
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
// Start the actual program
|
// Start the actual program
|
||||||
printf(
|
printf(
|
||||||
VERSIONSTRING
|
VERSIONSTRING
|
||||||
"AnnaConnect comes with ABSOLUTELY NO WARRANTY\n"
|
"AnnaConnect comes with ABSOLUTELY NO WARRANTY\n"
|
||||||
"This is free software, and you are welcome to redistribute it\n"
|
"This is free software, and you are welcome to redistribute it\n"
|
||||||
"under certain condtions. See `%s --license`\n", argv[0]
|
"under certain condtions."
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
|
" See `%s --license`\n", argv[0]
|
||||||
|
#else /* NO_OPTIONS */
|
||||||
|
"\n"
|
||||||
|
#endif /* NO_OPTIONS */
|
||||||
);
|
);
|
||||||
// board, innit?
|
// board, innit?
|
||||||
// Allocate the board
|
// Allocate the board
|
||||||
|
|
@ -185,11 +196,10 @@ int main( int argc, char *argv[] ){
|
||||||
wins->same.horizontal4 = calloc( playboard.columns, sizeof(column_t) );
|
wins->same.horizontal4 = calloc( playboard.columns, sizeof(column_t) );
|
||||||
wins->same.diagonalUp4 = calloc( playboard.columns, sizeof(column_t) );
|
wins->same.diagonalUp4 = calloc( playboard.columns, sizeof(column_t) );
|
||||||
wins->same.diagonalDown4 = calloc( playboard.columns, sizeof(column_t) );
|
wins->same.diagonalDown4 = calloc( playboard.columns, sizeof(column_t) );
|
||||||
goto init_ui;
|
|
||||||
}
|
}
|
||||||
init_ui:
|
|
||||||
initBoard( playboard );
|
initBoard( playboard );
|
||||||
// Begin loopin
|
// Begin loopin
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
if( outputfile != NULL ){
|
if( outputfile != NULL ){
|
||||||
fprintf(
|
fprintf(
|
||||||
outputfile,
|
outputfile,
|
||||||
|
|
@ -203,21 +213,29 @@ int main( int argc, char *argv[] ){
|
||||||
playboard.columns
|
playboard.columns
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
for(;; playboard.player = !playboard.player ){
|
for(;; playboard.player = !playboard.player ){
|
||||||
columnsint_t column;
|
columnsint_t column;
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
if( randomMoves ){
|
if( randomMoves ){
|
||||||
column = randomColumn( playboard );
|
column = randomColumn( playboard );
|
||||||
}else{
|
}else{
|
||||||
column = askColumn( playboard );
|
column = askColumn( playboard );
|
||||||
};
|
};
|
||||||
|
#else /* NO_OPTIONS */
|
||||||
|
column = askColumn( playboard );
|
||||||
|
#endif /* NO_OPTIONS */
|
||||||
if( column == QUITCOLUMN ) break;
|
if( column == QUITCOLUMN ) break;
|
||||||
playMove( &playboard, column );
|
playMove( &playboard, column );
|
||||||
calcWins( wins, &playboard, column );
|
calcWins( wins, &playboard, column );
|
||||||
updateBoard( playboard, column );
|
updateBoard( playboard, column );
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
if( outputfile != NULL ){
|
if( outputfile != NULL ){
|
||||||
fprintf( outputfile, "%d\n", column );
|
fprintf( outputfile, "%d\n", column );
|
||||||
}
|
}
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
}
|
}
|
||||||
|
#ifndef NO_OPTIONS
|
||||||
if( outputfile != NULL ){
|
if( outputfile != NULL ){
|
||||||
fprintf( outputfile,
|
fprintf( outputfile,
|
||||||
"# Wins\n"
|
"# Wins\n"
|
||||||
|
|
@ -237,5 +255,6 @@ int main( int argc, char *argv[] ){
|
||||||
fclose( outputfile );
|
fclose( outputfile );
|
||||||
printf( "Output is written to %s\n", filename );
|
printf( "Output is written to %s\n", filename );
|
||||||
}
|
}
|
||||||
|
#endif /* ! NO_OPTIONS */
|
||||||
exit_ui();
|
exit_ui();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue