aboutsummaryrefslogtreecommitdiff
path: root/src/ct1986.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ct1986.c')
-rw-r--r--src/ct1986.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/ct1986.c b/src/ct1986.c
index 2e57ea6..cb232fc 100644
--- a/src/ct1986.c
+++ b/src/ct1986.c
@@ -39,7 +39,7 @@ end_game(char *line, char *win) {
append_to_gamelog(line, 0);
append_to_gamelog(win, 1);
fputs("Game over: ",lcd);
- fputs(win,lcd);
+ fputs(win, lcd);
fflush(lcd);
}
@@ -49,10 +49,10 @@ handle_turn(char *line) {
uint8_t new_win = (won == 0xFF);
switch (do_ptn(line)) {
// Errors
- case PTN_INVALID: { fputs("Invalid PTN.",lcd); return -1; break; }
- case ACT_ILLEGAL: { fputs("Illegal action.",lcd); return -1; break; }
+ case PTN_INVALID: { fputs("Invalid PTN.", lcd); return -1; break; }
+ case ACT_ILLEGAL: { fputs("Illegal action.", lcd); return -1; break; }
case ACT_OVERFLOW: {
- fputs("Move would cause internal overflow, select another.");
+ fputs("Move would cause internal overflow, select another.", lcd);
return EXIT_FAILURE;
break;
}
@@ -68,7 +68,7 @@ handle_turn(char *line) {
case WIN_ROAD_WHITE: { end_game(line,"R-0"); break; }
}
}
- fputs("Game over, enter `new' to play again.");
+ fputs("Game over, enter `new' to play again.", lcd);
if (! new_win) return EXIT_FAILURE;
break;
}
@@ -86,7 +86,7 @@ handle_turn(char *line) {
static void
new_game(uint8_t size) {
reset_state(size);
- fputs("New 5x5 game! ct1986 at search depth ");
+ fputs("New 5x5 game! ct1986 at search depth ", lcd);
fputc(search_depth + '0', lcd);
fputc('.', lcd);
fflush(lcd);
@@ -106,17 +106,16 @@ ct1986_display_progress(const uint8_t depth) {
static int
ct1986_turn(const uint8_t search_depth) {
// Prepare progress bar
- fputs("Computing ");
+ fputs("Computing ", lcd);
// Run the minimax
float minimax = ct1986_generate(search_depth);
// Failed to find a move?
- if ((minimax <= -infty && (ply & 1) == 1)
- ||(minimax >= infty && (ply & 1) == 0)) {
- fputs("Opponent concedes!");
+ if (minimax <= -infty) {
+ fputs("Opponent concedes!", lcd);
return EXIT_FAILURE;
} else {
- fputs("Result: ");
- fputs(ct1986_ptn);
+ fputs("Result: ", lcd);
+ fputs(ct1986_ptn, lcd);
handle_turn(ct1986_ptn);
return EXIT_SUCCESS;
}
@@ -126,9 +125,9 @@ static int
input_is_not_turn(const char *line) {
if (!strcmp(line,"help")) {
fputs("Valid commands: depth [0-9], help, new, \
-play (b|w), self-play, <PTN>.");
+play (b|w), self-play, <PTN>.", lcd);
} else if (!strcmp(line,"log")) {
- fputs(gamelog);
+ fputs(gamelog, lcd);
} else if (!strcmp(line,"new")) {
new_game(5);
} else if (!strcmp(line,"self-play")) {
@@ -136,11 +135,11 @@ play (b|w), self-play, <PTN>.");
} else if (!strncmp(line,"depth",5)) {
if (strnlen(line,7) == 7 && line[6] >= '0' && line[6] <= '9') {
search_depth = line[6] - '0';
- fputs("New search depth: ",lcd);
+ fputs("New search depth: ", lcd);
fputc(line[6], lcd);
fflush(lcd);
} else {
- fputs("Usage: depth [0-9].",lcd);
+ fputs("Usage: depth [0-9].", lcd);
}
} else if (!strncmp(line,"play",4)) {
if (strnlen(line,7) == 6
@@ -175,7 +174,7 @@ main(int argc, char **argv) {
size_t alloc_size;
for (int playing = 1; playing;) {
- fputs("Welcome to ct1986!\n",lcd); fflush(lcd);
+ fputs("Welcome to ct1986!\n", lcd); fflush(lcd);
fflush(stdout);
while ((human == 0) && (read = getline(&line, &alloc_size, stdin)) != -1) {
if (read) {
@@ -195,5 +194,7 @@ main(int argc, char **argv) {
human = 0;
}
}
- return 0;
+
+ fclose(lcd);
+ return EXIT_SUCCESS;
}