aboutsummaryrefslogtreecommitdiff
path: root/src/pptdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pptdb.c')
-rw-r--r--src/pptdb.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/pptdb.c b/src/pptdb.c
index 7995219..5e49c26 100644
--- a/src/pptdb.c
+++ b/src/pptdb.c
@@ -11,37 +11,35 @@ FILE *training_fh = NULL;
static void
write_input(void) {
- // Four numbers for capstone coords (col,row)
+ // 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 layers of board_size * board_size:
- float t; int h; uint16_t mask;
+ /* 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;
for (int k = 0; k < board_size * board_size; k++) {
+ const int h = COUNT_AT(k);
// stacks encoded as balanced ternary
t = 0;
- h = COUNT_AT(k);
-
- if (h>0) {
- mask = 1<<(h-1);
- while (h-->0) {
- t += (colours[k] & mask) ? +1 : -1;
- t/=3;
- mask >>= 1;
- }
- }
- fprintf(training_fh,"%.6f,",t);
- }
- float val;
- for (int k = 0; k < board_size * board_size; k++) {
- val = 0;
- if (COUNT_AT(k)) {
- if (STONE_AT(k) == STONE_STANDING) val = (colours[k] & 1) ? +1/3 : -1/3;
- else if (STONE_AT(k) == STONE_CAPSTONE) val = (colours[k] & 1) ? +1.0 : -1.0;
- else val = (colours[k] & 1) ? +2/3 : -2/3;
+ mask = 1<<(h-1);
+ for (int j = 0; j < h; j++) {
+ t += (colours[k] & mask) ? +1 : -1;
+ t /= 3;
+ mask >>=1;
}
- fprintf(training_fh,"%.6f,",val);
+ // 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 */
}
}
@@ -93,15 +91,17 @@ parse_line(const char *pt, const ssize_t read) {
if (r != ACT_OK) return r;
- // Measure height of stacks exceeding 1
- for (int k = 0; k < board_size * board_size; k++) {
- if (COUNT_AT(k)>1) heights[COUNT_AT(k)]+=1;
+ if (generate == 0) {
+ // Measure height of stacks exceeding 1
+ for (int k = 0; k < board_size * board_size; k++) {
+ if (COUNT_AT(k)>1) heights[COUNT_AT(k)]+=1;
+ }
}
}
// Generate training data, not too early in the game
if (generate && ply > 10) {
write_input();
- fprintf(training_fh,"%d\n", result);
+ fprintf(training_fh,"%d,%d\n", result, 1-result);
}
// Parse next action
while (idx<read && pt[idx++]!=',');
@@ -139,12 +139,11 @@ main(int argc, char **argv) {
training_fh = fopen(td_fn, "w");
if (training_fh == NULL) exit(EXIT_FAILURE);
// Write header
- fputs("\"White flats\",\"Black flats\",",training_fh);
- for (int k = 0; k < size*size; k++)
+ /* fputs("\"Player\",\"White flats\",\"Black flats\",",training_fh); */
+ for (int k = 0; k < size*size; k++) {
fprintf(training_fh,"\"Stack %d\",",k);
- for (int k = 0; k < size*size; k++)
- fprintf(training_fh,"\"Wall %d\",",k);
- fputs("\"Outcome\"\n",training_fh);
+ }
+ fputs("\"White win\",\"Black win\"\n",training_fh);
} else generate=0;
while ((read = getline(&line, &len, playtak_fh)) != -1) {