diff options
| author | tslil <tslil@posteo.de> | 2021-01-15 23:45:16 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 5a72da9ae99689a8a3571b23b7a639a4efc58abc (patch) | |
| tree | 24fb3f4858184f49f337e57662db5c6f42f8700e | |
| parent | f5df4d3710c94822a6602a3e4936287ea5d61bab (diff) | |
Dragon is not separate, fixed concession, allowing playing as b/w
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | extract.sh | 8 | ||||
| -rw-r--r-- | include/ct1986.c | 4 | ||||
| -rw-r--r-- | include/tak.c | 10 | ||||
| -rw-r--r-- | include/tak.h | 2 | ||||
| -rw-r--r-- | src/ctaklm.c | 48 |
6 files changed, 41 insertions, 33 deletions
@@ -1,6 +1,6 @@ IDIR=include TPDIR=3rd-party -CFLAGS=-Os -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -I$(IDIR) -I$(TPDIR) +CFLAGS=-O3 -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -I$(IDIR) -I$(TPDIR) LIBS= SRCS=$(wildcard include/*.c) $(wildcard 3rd-party/*.c) @@ -5,10 +5,8 @@ db_file=games_anon.db query() { query="(size == $1) and (result != '1-0') and (result != '0-1') and (result != '0-0') and (result != '1/2-1/2')" selct="" - # for player in fwwwwibib archvenison NohatCoder nqeron ManaT rabbitboy84 applemonkeyman Tayacan AaaarghBot; do - # for player in NohatCoder AaaarghBot; do - for player in; do - # selct="$selct(player_black == '$player') or " + for player in fwwwwibib archvenison NohatCoder nqeron ManaT rabbitboy84 applemonkeyman Tayacan AaaarghBot applemonkeyman; do + # for player in; do selct="$selct(player_black == '$player') or (player_white == '$player') or " done; if [ -n "$selct" ]; then @@ -60,5 +58,5 @@ make pptdb for size in 5; do echo extract $size notation,result - process $size 20000 validation + process $size 200000 training done diff --git a/include/ct1986.c b/include/ct1986.c index 1c3fa79..c80e32a 100644 --- a/include/ct1986.c +++ b/include/ct1986.c @@ -133,11 +133,11 @@ static enum WIN_TYPE w; if (w < 0xFF) { \ /* Somebody won, assign weights accordingly */ \ if (min == 0) { \ - if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK || w == WIN_DRAGON) \ + if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) \ val = infty; \ else val = -infty; \ } else { \ - if (w == WIN_ROAD_WHITE || w == WIN_FLAT_WHITE || w == WIN_DRAGON) \ + if (w == WIN_ROAD_WHITE || w == WIN_FLAT_WHITE) \ val = -infty; \ else val = infty; \ } \ diff --git a/include/tak.c b/include/tak.c index 2ddb78b..d8d0a8e 100644 --- a/include/tak.c +++ b/include/tak.c @@ -330,14 +330,12 @@ check_win(void) { rb = check_road_colour(C_BLACK); rw = check_road_colour(C_WHITE); - if (rb == WIN_ROAD_BLACK) { - if (rw == WIN_ROAD_WHITE) { - return WIN_DRAGON; - } else { - return WIN_ROAD_BLACK; - } + if (rb == WIN_ROAD_BLACK && rw == WIN_ROAD_WHITE) { + return (ply & 1) ? rb : rw; // Dragons } else if (rw == WIN_ROAD_WHITE) { return rw; + } else if (rb == WIN_ROAD_BLACK) { + return rb; } // Do we do a flat count? diff --git a/include/tak.h b/include/tak.h index 27984a1..ad0b994 100644 --- a/include/tak.h +++ b/include/tak.h @@ -14,7 +14,7 @@ enum STONE_VARIANT { STONE_FLAT, STONE_STANDING, STONE_CAPSTONE }; enum MOVE_DIRECTION { M_UP, M_DOWN, M_LEFT, M_RIGHT }; enum WIN_TYPE { WIN_DRAW, WIN_FLAT_WHITE, WIN_FLAT_BLACK, - WIN_ROAD_WHITE, WIN_ROAD_BLACK, WIN_DRAGON}; + WIN_ROAD_WHITE, WIN_ROAD_BLACK }; typedef uint8_t data_t; typedef uint16_t colour_stack_t; 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 = ˙ + + 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; |
