diff options
| -rw-r--r-- | src/ct1986.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/ct1986.c b/src/ct1986.c index 4cbe2a7..b930b13 100644 --- a/src/ct1986.c +++ b/src/ct1986.c @@ -5,7 +5,7 @@ #include <tak.h> #include <minimax_cnn1986.h> -const char* esc = "[L"; +const char* esc = "\x1B[L"; FILE *lcd = NULL; static char *gamelog = 0; @@ -13,7 +13,7 @@ static int human, search_depth; static void write_line(const char *line) { - fputs(line, lcd); + fprintf(lcd, "%s\n", line); fflush(lcd); } @@ -100,27 +100,22 @@ inline void ct1986_display_progress(const uint8_t depth) { if (depth == 0) { perc++; - // back four spaces - for (int k=0;k<4;k++) { - fprintf(lcd, "%sl", esc); - fflush(lcd); - } - // clear line - fprintf(lcd, "%sk", esc); + // back four spaces and clear line, followed by perc% + fprintf(lcd, "%sl%sl%sl%sl%sk%3d%%", + esc, esc, esc, esc, esc, + perc*4); fflush(lcd); - // write percentage - fprintf(lcd, "%3d%%", perc*4); } } static int ct1986_turn(const uint8_t search_depth) { // Prepare progress bar - fputs("Computing.. ", lcd); fflush(lcd); + fputs("Computing: ", lcd); fflush(lcd); // Run the minimax perc = 0; float minimax = ct1986_generate(search_depth); - fputc('\n', lcd); + fputc('\n', lcd); fflush(lcd); // Failed to find a move? if (minimax <= -infty) { fprintf(lcd, "%s concedes!\n", (ply & 1) ? "Black" : "White"); @@ -168,15 +163,19 @@ main(int argc, char **argv) { human = 0; search_depth = 1; new_game(5); + fprintf(lcd, "%sB", esc); + fflush(lcd); char *line = NULL; ssize_t read; size_t alloc_size; for (int playing = 1; playing;) { - write_line("Loaded ct1986!\n"); - while ((human == 0) && (read = getline(&line, &alloc_size, stdin)) != -1) { - if (read) { + while (human == 0) { + if (ply & 1) write_line("Black: "); + else write_line("White: "); + read = getline(&line, &alloc_size, stdin); + if (read > 0) { line[read - 1] = 0; if (input_is_not_turn(line)) { int r = handle_turn(line); @@ -184,14 +183,13 @@ main(int argc, char **argv) { human = 1; } } + } else if (read == -1) { + playing = 0; + break; } } - if ((human == 0) && (read == -1)) { - playing = 0; - } else { - ct1986_turn(search_depth); - human = 0; - } + ct1986_turn(search_depth); + human = 0; } fclose(lcd); |
