diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-20 21:14:10 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 36cecb722fb66d35cdbf69ebcf2aa6f49bfc082b (patch) | |
| tree | 2cf054ba8093a3be3860b284f549dc0b57e134e1 /src/ct1986.c | |
| parent | 55870e6acf15dc0ee92a469ea5fefb6c6a088d2a (diff) | |
Vertical line is just incremented %2, i'll have to manually buffer
charlcd.c:621
case '\n':
/*
* flush the remainder of the current line and
* go to the beginning of the next line
*/
for (; priv->addr.x < lcd->bwidth; priv->addr.x++)
lcd->ops->write_data(lcd, ' ');
priv->addr.x = 0;
priv->addr.y = (priv->addr.y + 1) % lcd->height;
charlcd_gotoxy(lcd);
break;
Diffstat (limited to 'src/ct1986.c')
| -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); |
