Compare commits
No commits in common. "f59be8398dbde340d95f506879a46c526ea064dd" and "15fb694d7b4c8ec3644e33dd0f36da30670aa678" have entirely different histories.
f59be8398d
...
15fb694d7b
2 changed files with 5 additions and 29 deletions
29
connect4.c
29
connect4.c
|
|
@ -20,9 +20,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#ifndef NO_OPTIONS
|
||||
#include <getopt.h>
|
||||
#endif /* ! NO_OPTIONS */
|
||||
#include <string.h>
|
||||
#include "macros.h"
|
||||
#include "config.h"
|
||||
|
|
@ -41,14 +39,12 @@
|
|||
#define VERSIONSTRING \
|
||||
"AnnaConnect version "XSTR(FULLVERSION)", Copyright (C) Anna Snoeijs\n"
|
||||
|
||||
#ifndef NO_OPTIONS
|
||||
// The LISENCE file
|
||||
// Not null-terminated so need pointers for both start and end
|
||||
extern char _binary_LICENSE_start[];
|
||||
extern char _binary_LICENSE_end[];
|
||||
#endif /* ! NO_OPTIONS */
|
||||
|
||||
int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
||||
int main( int argc, char *argv[] ){
|
||||
// Initialise variables
|
||||
board_t playboard = {
|
||||
.player = 0,
|
||||
|
|
@ -57,10 +53,9 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
|||
.count0 = {0},
|
||||
.count1 = {0},
|
||||
};
|
||||
wins_t *wins = malloc( sizeof(wins_t) );
|
||||
#ifndef NO_OPTIONS
|
||||
FILE *outputfile = NULL;
|
||||
char *filename = NULL;
|
||||
wins_t *wins = malloc( sizeof(wins_t) );
|
||||
bool randomMoves = 0;
|
||||
// Parse options
|
||||
for(;;){
|
||||
|
|
@ -163,18 +158,12 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
|||
return -1;
|
||||
}
|
||||
#undef ROWOVERFLOW
|
||||
#endif /* ! NO_OPTIONS */
|
||||
// Start the actual program
|
||||
printf(
|
||||
VERSIONSTRING
|
||||
"AnnaConnect comes with ABSOLUTELY NO WARRANTY\n"
|
||||
"This is free software, and you are welcome to redistribute it\n"
|
||||
"under certain condtions."
|
||||
#ifndef NO_OPTIONS
|
||||
" See `%s --license`\n", argv[0]
|
||||
#else /* NO_OPTIONS */
|
||||
"\n"
|
||||
#endif /* NO_OPTIONS */
|
||||
"under certain condtions. See `%s --license`\n", argv[0]
|
||||
);
|
||||
// board, innit?
|
||||
// Allocate the board
|
||||
|
|
@ -196,10 +185,11 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
|||
wins->same.horizontal4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
wins->same.diagonalUp4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
wins->same.diagonalDown4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
goto init_ui;
|
||||
}
|
||||
init_ui:
|
||||
initBoard( playboard );
|
||||
// Begin loopin
|
||||
#ifndef NO_OPTIONS
|
||||
if( outputfile != NULL ){
|
||||
fprintf(
|
||||
outputfile,
|
||||
|
|
@ -213,29 +203,21 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
|||
playboard.columns
|
||||
);
|
||||
}
|
||||
#endif /* ! NO_OPTIONS */
|
||||
for(;; playboard.player = !playboard.player ){
|
||||
columnsint_t column;
|
||||
#ifndef NO_OPTIONS
|
||||
if( randomMoves ){
|
||||
column = randomColumn( playboard );
|
||||
}else{
|
||||
column = askColumn( playboard );
|
||||
};
|
||||
#else /* NO_OPTIONS */
|
||||
column = askColumn( playboard );
|
||||
#endif /* NO_OPTIONS */
|
||||
if( column == QUITCOLUMN ) break;
|
||||
playMove( &playboard, column );
|
||||
calcWins( wins, &playboard, column );
|
||||
updateBoard( playboard, column );
|
||||
#ifndef NO_OPTIONS
|
||||
if( outputfile != NULL ){
|
||||
fprintf( outputfile, "%d\n", column );
|
||||
}
|
||||
#endif /* ! NO_OPTIONS */
|
||||
}
|
||||
#ifndef NO_OPTIONS
|
||||
if( outputfile != NULL ){
|
||||
fprintf( outputfile,
|
||||
"# Wins\n"
|
||||
|
|
@ -255,6 +237,5 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char *argv[] ){
|
|||
fclose( outputfile );
|
||||
printf( "Output is written to %s\n", filename );
|
||||
}
|
||||
#endif /* ! NO_OPTIONS */
|
||||
exit_ui();
|
||||
}
|
||||
|
|
|
|||
5
makefile
5
makefile
|
|
@ -28,11 +28,6 @@ FLAGS += -flto
|
|||
#FLAGS += -Wno-sign-conversion
|
||||
#FLAGS += -Wformat-truncation=0
|
||||
|
||||
ifneq (, $(EXTRA_FLAGS))
|
||||
FLAGS += $(EXTRA_FLAGS)
|
||||
endif
|
||||
|
||||
|
||||
# Compile flag for defining GITHASH to put at the end of the version string
|
||||
GITFLAG = -D'GITHASH=$(shell git rev-parse --short=1 HEAD)'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue