aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-18 14:52:14 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit9c56a2c16bce2a7011994bb9f4a62c3ad2fef2df (patch)
tree3c3f50a941db217d972950cce324947b6b0ae129 /src
parenta8f69f1262bd76ab311ebe760f314fa6e4526d15 (diff)
Added tunable search depth and self-play
Diffstat (limited to 'src')
-rw-r--r--src/ctaklm.c31
-rw-r--r--src/pptdb.c11
2 files changed, 24 insertions, 18 deletions
diff --git a/src/ctaklm.c b/src/ctaklm.c
index 0d9e53a..d4db469 100644
--- a/src/ctaklm.c
+++ b/src/ctaklm.c
@@ -155,8 +155,9 @@ print_info(void) {
blk,black_count >> 7,rst);
}
-char *gamelog = 0;
-uint8_t auto_board = 0xFF, auto_info = 0xFF;
+static char *gamelog = 0;
+static uint8_t auto_board = 0xFF, auto_info = 0xFF;
+static int human, search_depth;
static void
append_to_gamelog(const char *line, const uint8_t win_line) {
@@ -234,12 +235,11 @@ handle_turn(char *line) {
return EXIT_SUCCESS;
}
-static int human;
-
static void
new_game(uint8_t size) {
reset_state(size);
- printf("New %dx%d game!\n",size,size);
+ printf("New %dx%d game! ct1986 at search_depth %d.\n",
+ size, size, search_depth);
if (gamelog) gamelog = realloc(gamelog, sizeof(char));
else gamelog = malloc(sizeof(char));
gamelog[0] = 0;
@@ -311,7 +311,7 @@ dot(const uint8_t depth) {
}
static int
-ct1986_turn(const uint8_t max_depth) {
+ct1986_turn(const uint8_t search_depth) {
// Prepare progress bar
fputs("Computing [", stdout);
for (int k = 0; k < board_size * board_size; k++) putchar(' ');
@@ -319,7 +319,7 @@ ct1986_turn(const uint8_t max_depth) {
fflush(stdout);
// Run the minimax
sum_depth = 0; num_check = 0;
- float minimax = ct1986_generate(max_depth);
+ float minimax = ct1986_generate(search_depth);
puts("]\033[1C");
// Failed to find a move?
if ((minimax <= -infty && (ply & 1) == 1)
@@ -340,8 +340,8 @@ ct1986_turn(const uint8_t max_depth) {
static int
input_is_not_turn(const char *line) {
if (!strcmp(line,"help")) {
- puts("Valid commands: auto (board|info), board, eval, help, info,\
-load, log, new, play <b|w>, square, <PTN>.");
+ puts("Valid commands: auto (board|info), board, depth [0-9], eval, help,\
+info, load, log, new, play (b|w), self-play, square <col><row>, <PTN>.");
} else if (!strcmp(line,"board")) {
print_board();
} else if (!strcmp(line,"info")) {
@@ -359,6 +359,16 @@ load, log, new, play <b|w>, square, <PTN>.");
puts(gamelog);
} else if (!strcmp(line,"new")) {
new_game(5);
+ } else if (!strcmp(line,"self-play")) {
+ new_game(5);
+ while (ct1986_turn(search_depth) == 0);
+ } else if (!strncmp(line,"depth",5)) {
+ if (strnlen(line,7) == 7 && line[6] >= '0' && line[6] <= '9') {
+ search_depth = line[6] - '0';
+ printf("New search depth: %d.\n",search_depth);
+ } else {
+ puts("Usage: depth [0-9].");
+ }
} else if (!strncmp(line,"load",4)) {
if (strnlen(line,6) >= 6) {
if (load_ptn(line+5)) {
@@ -412,6 +422,7 @@ main(int argc, char **argv) {
ct1986_display_progress = &dot;
human = 0;
+ search_depth = 3;
new_game(5);
char *line;
@@ -428,7 +439,7 @@ main(int argc, char **argv) {
if ((human == 0) && line == NULL) {
playing = 0;
} else {
- ct1986_turn(4);
+ ct1986_turn(search_depth);
human = 0;
}
}
diff --git a/src/pptdb.c b/src/pptdb.c
index 5c5c718..0c8673d 100644
--- a/src/pptdb.c
+++ b/src/pptdb.c
@@ -115,14 +115,9 @@ parse_line(const char *pt, const ssize_t read) {
}
// Generate training data, not too early in the game
if (generate && ply + 4 >= total_plies) {
- /*
- * int dx = (rand()&1)?-1:+1;
- * int dy = (rand()&1)?-1:+1;
- */
- write_input(1,1);
- write_input(1,-1);
- write_input(-1,1);
- write_input(-1,-1);
+ int dx = (rand()&1)?-1:+1;
+ int dy = (rand()&1)?-1:+1;
+ write_input(dx,dy);
}
// Parse next action
while (idx<read && pt[idx++]!=',');