diff options
| author | tslil <tslil@posteo.de> | 2021-01-05 14:20:56 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 8a231c52d56e011b42fa854542670c5b41801d47 (patch) | |
| tree | abf3e3bdcc6a153cef0213b61a22fb46dc472587 /src/pptdb.c | |
| parent | f3d3b35248b114b8b5664c6c38952a89fbf98b15 (diff) | |
Separate concerns in pptdb, remove legacy in extract.sh
Diffstat (limited to 'src/pptdb.c')
| -rw-r--r-- | src/pptdb.c | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/src/pptdb.c b/src/pptdb.c index eb39e25..34056c4 100644 --- a/src/pptdb.c +++ b/src/pptdb.c @@ -6,7 +6,7 @@ uint64_t heights[16]; FILE *training_fh = NULL; -int wc_col, bc_col, wc_row, bc_row, result; +int wc_col, bc_col, wc_row, bc_row, result, generate; static void write_input(void) { @@ -100,8 +100,10 @@ parse_line(const char *pt, const ssize_t read) { } } // Generate training data - write_input(); - fprintf(training_fh,"%d,%d\n", result, 1-result); + if (generate) { + write_input(); + fprintf(training_fh,"%d,%d\n", result, 1-result); + } // Parse next action while (idx<read && pt[idx++]!=','); if (idx>=read) return ACT_OK; @@ -131,9 +133,12 @@ main(int argc, char **argv) { playtak_fh = fopen(argv[2], "r"); if (playtak_fh == NULL) exit(EXIT_FAILURE); - snprintf(td_fn, 64, "data/training-%d.csv",size); - training_fh = fopen(td_fn, "w"); - if (training_fh == NULL) exit(EXIT_FAILURE); + if (argc > 3 && (!strncmp("generate", argv[3], 8))) { + generate=1; + snprintf(td_fn, 64, "data/training-%d.csv",size); + training_fh = fopen(td_fn, "w"); + if (training_fh == NULL) exit(EXIT_FAILURE); + } else generate=0; while ((read = getline(&line, &len, playtak_fh)) != -1) { // Reset everything @@ -143,42 +148,48 @@ main(int argc, char **argv) { // Store the result of this game if (line[read-4] == '0') result = 1; else result = 0; - // Parse the line and adjust counts + // Parse the line r = parse_line(line,read-4); - if (r == ACT_ILLEGAL) { - illegal++; - printf("Illegal:\n%s",line); - } else if (r == ACT_OVERFLOW) { - printf("Overflow:\n%s",line); - overflow++; - } else { - win = check_win(); - if (win == WIN_FLAT_BLACK - || win == WIN_FLAT_WHITE - || win == WIN_DRAW) { - flat_wins++; - flat_turns += ply/2+1; + // Adjust counts if we're not generating training data + if (generate == 0) { + if (r == ACT_ILLEGAL) { + illegal++; + printf("Illegal:\n%s",line); + } else if (r == ACT_OVERFLOW) { + printf("Overflow:\n%s",line); + overflow++; } else { - road_wins++; - road_turns += ply/2+1; + win = check_win(); + if (win == WIN_FLAT_BLACK + || win == WIN_FLAT_WHITE + || win == WIN_DRAW) { + flat_wins++; + flat_turns += ply/2+1; + } else { + road_wins++; + road_turns += ply/2+1; + } } } games++; } fclose(playtak_fh); - fclose(training_fh); + if (generate) fclose(training_fh); if (line) free(line); if (illegal || overflow) putchar('\n'); printf("Read %d games\n",games); - printf("Illegals: %d\nOverflows: %d\nRoad wins: %d\nFlat wins: %d\n\ + + if (generate==0) { + printf("Illegals: %d\nOverflows: %d\nRoad wins: %d\nFlat wins: %d\n\ Average turns to road win: %.3f\nAverage turns to flat win: %f\n", - illegal,overflow, road_wins, flat_wins, - (double)(road_turns)/(double)(road_wins), - (double)(flat_turns)/(double)(flat_wins)); - for (int k = 2; k < 16; k++) { - printf("Height %2d: %7ld\n",k,heights[k]); + illegal,overflow, road_wins, flat_wins, + (double)(road_turns)/(double)(road_wins), + (double)(flat_turns)/(double)(flat_wins)); + for (int k = 2; k < 16; k++) { + printf("Height %2d: %7ld\n",k,heights[k]); + } } exit(EXIT_SUCCESS); |
