aboutsummaryrefslogtreecommitdiff
path: root/src/ctaklm.c
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2021-01-15 23:45:16 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit5a72da9ae99689a8a3571b23b7a639a4efc58abc (patch)
tree24fb3f4858184f49f337e57662db5c6f42f8700e /src/ctaklm.c
parentf5df4d3710c94822a6602a3e4936287ea5d61bab (diff)
Dragon is not separate, fixed concession, allowing playing as b/w
Diffstat (limited to 'src/ctaklm.c')
-rw-r--r--src/ctaklm.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/ctaklm.c b/src/ctaklm.c
index 40d16fb..3792cfa 100644
--- a/src/ctaklm.c
+++ b/src/ctaklm.c
@@ -210,7 +210,6 @@ handle_turn(char *line) {
// Did it end this turn?
if (new_win) {
switch (won) {
- case WIN_DRAGON: { end_game(line,"R-R"); break; }
case WIN_DRAW: { end_game(line,"1/2-1/2"); break; }
case WIN_FLAT_BLACK: { end_game(line,"0-F"); break; }
case WIN_FLAT_WHITE: { end_game(line,"F-0"); break; }
@@ -240,7 +239,6 @@ static int human;
static void
new_game(uint8_t size) {
reset_state(size);
- human = 1;
printf("New %dx%d game!\n",size,size);
if (gamelog) gamelog = realloc(gamelog, sizeof(char));
else gamelog = malloc(sizeof(char));
@@ -308,7 +306,7 @@ dot(const uint8_t depth) {
}
}
-static void
+static int
ct1986_turn(const uint8_t max_depth) {
// Prepare progress bar
fputs("Computing [", stdout);
@@ -317,21 +315,25 @@ ct1986_turn(const uint8_t max_depth) {
fflush(stdout);
// Run the minimax
float minimax = ct1986_generate(max_depth);
- if (minimax <= -infty) {
+ // Failed to find a move?
+ if ((minimax <= -infty && (ply & 1) == 1)
+ ||(minimax >= infty && (ply & 1) == 0)) {
puts("] Opponent concedes!");
+ return EXIT_FAILURE;
} else {
printf("] Result: %s (%.3f)\n",
ct1986_ptn,
minimax*100.0);
handle_turn(ct1986_ptn);
+ return EXIT_SUCCESS;
}
}
static int
input_is_not_turn(const char *line) {
if (!strncmp(line,"help",5)) {
- puts("Valid commands: auto (board|info), board, help, info,\
-log, square, new [56], <PTN>.");
+ puts("Valid commands: auto (board|info), board, eval, help, info,\
+load, log, new, play <b|w>, square, <PTN>.");
} else if (!strncmp(line,"board",6)) {
print_board();
} else if (!strncmp(line,"info",5)) {
@@ -347,9 +349,13 @@ log, square, new [56], <PTN>.");
}
} else if (!strncmp(line,"log",3)) {
puts(gamelog);
+ } else if (!strncmp(line,"new",3)) {
+ new_game(5);
} else if (!strncmp(line,"load",4)) {
if (strnlen(line,6) >= 6) {
- load_ptn(line+5);
+ if (load_ptn(line+5)) {
+ printf("Errors in file %s\n",line);
+ }
} else {
puts("Usage: load <file.ptn>.");
}
@@ -371,15 +377,17 @@ log, square, new [56], <PTN>.");
&& line[8] >= '1' && line[8] <= '0'+board_size) {
print_square(line[7]-'a', line[8]-'1');
} else {
- printf("Usage: square [a-%c][1-%c]\n",'`'+board_size,'0'+board_size);
+ printf("Usage: square [a-%c][1-%c].\n",'`'+board_size,'0'+board_size);
}
- } else if (!strncmp(line,"new",3)) {
- if (line[3] == 0) {
+ } else if (!strncmp(line,"play",4)) {
+ if (strnlen(line,6) >= 6
+ && ((line[5] == 'b' || line[5] == 'B')
+ || (line[5] == 'w' || line[5] == 'W'))) {
+ // 'b' is even :)
+ human = 1 - (line[5] & 1);
new_game(5);
- } else if (strnlen(line,5) >= 5 && line[4] >= '5' && line[4] <= '6') {
- new_game(line[4]-'0');
} else {
- puts("Usage: new [56].");
+ puts("Usage: play (b|w).\n");
}
} else {
return EXIT_FAILURE;
@@ -394,24 +402,28 @@ main(int argc, char **argv) {
// Set up output function for ct1986
ct1986_display_progress = &dot;
+
+ human = 0;
new_game(5);
+ while (ct1986_turn(4) == 0);
+
char *line;
for (int playing = 1; playing;) {
- while(human && (line = linenoise("ctaklm> ")) != NULL) {
+ while((human == 0) && (line = linenoise("ctaklm> ")) != NULL) {
if (input_is_not_turn(line)) {
int r = handle_turn(line);
if (r == EXIT_SUCCESS && won == 0xFF) {
- human = 0;
+ human = 1;
}
}
free(line);
}
- if (human && line == NULL) {
+ if ((human == 0) && line == NULL) {
playing = 0;
} else {
- ct1986_turn(2);
- human = 1;
+ ct1986_turn(3);
+ human = 0;
}
}
return 0;