diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-18 12:04:53 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | b9f6706a656b56a65dd97b01327c8bbc550ca717 (patch) | |
| tree | c00c2d49809f163e73e4dde4853b3012208d5874 | |
| parent | c1750c0cb93a7b4ba70e1342eaa7c62e659f1dc5 (diff) | |
Nicer info, corrected strncmp --> strcmp in places
| -rw-r--r-- | src/ctaklm.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/ctaklm.c b/src/ctaklm.c index 443e1dc..0d9e53a 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -320,17 +320,18 @@ ct1986_turn(const uint8_t max_depth) { // Run the minimax sum_depth = 0; num_check = 0; float minimax = ct1986_generate(max_depth); - printf("] (%.0f, %.2f)\n", - num_check, sum_depth/num_check); + puts("]\033[1C"); // 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", + printf("Result: %s (%.2f, %.1e, %.2f)\n", ct1986_ptn, - minimax*100.0); + minimax*100.0, + num_check, + sum_depth/num_check); handle_turn(ct1986_ptn); return EXIT_SUCCESS; } @@ -338,14 +339,14 @@ ct1986_turn(const uint8_t max_depth) { static int input_is_not_turn(const char *line) { - if (!strncmp(line,"help",5)) { + if (!strcmp(line,"help")) { puts("Valid commands: auto (board|info), board, eval, help, info,\ load, log, new, play <b|w>, square, <PTN>."); - } else if (!strncmp(line,"board",6)) { + } else if (!strcmp(line,"board")) { print_board(); - } else if (!strncmp(line,"info",5)) { + } else if (!strcmp(line,"info")) { print_info(); - } else if (!strncmp(line,"eval",5)) { + } else if (!strcmp(line,"eval")) { float eval = ct1986_evaluate_black_win()*100; if (ply & 1) { printf("Black heuristic chance: %s%.2f%s\n", @@ -354,9 +355,9 @@ load, log, new, play <b|w>, square, <PTN>."); printf("White heruistic chance: %s%.2f%s\n", wht, 100-eval, rst); } - } else if (!strncmp(line,"log",3)) { + } else if (!strcmp(line,"log")) { puts(gamelog); - } else if (!strncmp(line,"new",3)) { + } else if (!strcmp(line,"new")) { new_game(5); } else if (!strncmp(line,"load",4)) { if (strnlen(line,6) >= 6) { @@ -367,11 +368,11 @@ load, log, new, play <b|w>, square, <PTN>."); puts("Usage: load <file.ptn>."); } } else if (!strncmp(line,"auto",4)) { - if (!strncmp(line,"auto board",10)) { + if (!strcmp(line,"auto board")) { auto_board = ~auto_board; printf("Automatic board display %s.\n", (auto_board) ? "Enabled" : "Disabled"); - } else if (!strncmp(line,"auto info",9)) { + } else if (!strcmp(line,"auto info")) { auto_info = ~auto_info; printf("Automatic info display %s.\n", (auto_info) ? "Enabled" : "Disabled"); @@ -379,7 +380,7 @@ load, log, new, play <b|w>, square, <PTN>."); puts("Usage: auto (board|info)."); } } else if (!strncmp(line,"square",6)) { - if (strnlen(line, 9) >= 9 + if (strnlen(line, 10) == 9 && line[7] >= 'a' && line[7] <= '`'+board_size && line[8] >= '1' && line[8] <= '0'+board_size) { print_square(line[7]-'a', line[8]-'1'); @@ -387,7 +388,7 @@ load, log, new, play <b|w>, square, <PTN>."); printf("Usage: square [a-%c][1-%c].\n",'`'+board_size,'0'+board_size); } } else if (!strncmp(line,"play",4)) { - if (strnlen(line,6) >= 6 + if (strnlen(line,7) == 6 && ((line[5] == 'b' || line[5] == 'B') || (line[5] == 'w' || line[5] == 'W'))) { // 'b' is even :) @@ -427,7 +428,7 @@ main(int argc, char **argv) { if ((human == 0) && line == NULL) { playing = 0; } else { - ct1986_turn(3); + ct1986_turn(4); human = 0; } } |
