From e8315ed893157a87c8f2c3935667ffcc97b2c95e Mon Sep 17 00:00:00 2001 From: tslil Date: Fri, 8 Jan 2021 00:54:07 -0500 Subject: Closing in on something reasonable for roads --- src/pptdb.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 18 deletions(-) (limited to 'src/pptdb.c') diff --git a/src/pptdb.c b/src/pptdb.c index 5e49c26..92155b5 100644 --- a/src/pptdb.c +++ b/src/pptdb.c @@ -9,38 +9,61 @@ uint64_t heights[16]; int result, generate; FILE *training_fh = NULL; +const int max_depth = 8; + static void write_input(void) { // Whose turn is it? /* fprintf(training_fh,"%d,",current_colour == C_BLACK); */ + // Two numbers for flats remaining /* fprintf(training_fh,"%.6f,%.6f,", */ /* (float)(white_count & 127)/max_flats, */ /* (float)(black_count & 127)/max_flats); */ // Two data points for each square - float t; uint16_t mask; + /* float t; uint16_t mask; */ + + float val; + uint16_t mask = 1; + for (int k = 0; k < board_size * board_size; k++) { + val = 0; + if (COUNT_AT(k)>0) { + if (STONE_AT(k) == STONE_STANDING) { + val = (colours[k] & mask) ? +0.25 : -0.25; + } else if (STONE_AT(k) == STONE_CAPSTONE) { + val = (colours[k] & mask) ? +1.00 : -1.00; + } else { + val = (colours[k] & mask) ? +0.50 : -0.50; + } + } + fprintf(training_fh,"%.2f,", val); + } + + for (int depth = 1; depth < max_depth; depth++) { + for (int k = 0; k < board_size * board_size; k++) { + val = 0; + if (COUNT_AT(k)>depth) val = (colours[k] & mask) ? +0.50 : -0.50; + fprintf(training_fh,"%.2f,", val); + } + mask <<= 1; + } + + /* + float t; for (int k = 0; k < board_size * board_size; k++) { - const int h = COUNT_AT(k); // stacks encoded as balanced ternary + const int h = COUNT_AT(k); t = 0; - mask = 1<<(h-1); - for (int j = 0; j < h; j++) { + mask = 1<>=1; } - // top stone in [-1, +1] ordered as |standing| < |flat| < |cap| - /* val = 0; */ - /* if (COUNT_AT(k)) { */ - /* if (STONE_AT(k) == STONE_STANDING) val = (colours[k] & 1) ? +1/4 : -1/4; */ - /* else if (STONE_AT(k) == STONE_CAPSTONE) val = (colours[k] & 1) ? +1.0 : -1.0; */ - /* else val = (colours[k] & 1) ? +1/2 : -1/2; */ - /* } */ - fprintf(training_fh,"%.8f,", - t*2); - /* (h > 0) ? ((colours[k] & 2) ? +2/3 : -2/3) : 0.0, */ - /* val */ + fprintf(training_fh,"%.8f,",2*t); } + */ + } // Warning: performs _no_ checks on input whatsoever @@ -99,7 +122,7 @@ parse_line(const char *pt, const ssize_t read) { } } // Generate training data, not too early in the game - if (generate && ply > 10) { + if (generate && current_colour == C_BLACK && ply > 15) { write_input(); fprintf(training_fh,"%d,%d\n", result, 1-result); } @@ -140,9 +163,19 @@ main(int argc, char **argv) { if (training_fh == NULL) exit(EXIT_FAILURE); // Write header /* fputs("\"Player\",\"White flats\",\"Black flats\",",training_fh); */ + + for (int depth = 0; depth < max_depth; depth++) { + for (int k = 0; k < size*size; k++) { + fprintf(training_fh,"\"Stack %d %d\",",depth,k); + } + } + + /* for (int k = 0; k < size*size; k++) { - fprintf(training_fh,"\"Stack %d\",",k); + fprintf(training_fh,"\"BT %d\",",k); } + */ + fputs("\"White win\",\"Black win\"\n",training_fh); } else generate=0; -- cgit v1.2.3