diff options
| author | tslil <tslil@posteo.de> | 2021-05-07 22:19:31 -0400 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 1d1b28c294143f7a918db7a646b5564674616e44 (patch) | |
| tree | c9a4fa49fd0b39bc6752f455d785363f6aadf345 | |
| parent | 29536c86457d83967c23a900574182b3898f04dd (diff) | |
quick hachstats
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | include/actions.c | 6 | ||||
| -rw-r--r-- | include/actions.h | 2 | ||||
| -rw-r--r-- | include/negamax.c | 2 | ||||
| -rw-r--r-- | src/pptdb.c | 37 |
5 files changed, 39 insertions, 12 deletions
@@ -2,7 +2,7 @@ IDIR=include DEFINES=-DDETERMINISTIC CFLAGS=-O3 -Wall -Wextra -Wpedantic -std=c99 -D_DEFAULT_SOURCE $(DEFINES) -I$(IDIR) -CTAK=include/tak.c +CTAK=include/tak.c include/actions.c CTAK_OBJS=$(CTAK:.c=.o) SRCS=$(filter-out include/lcdlib.c,$(wildcard include/*.c)) OBJS=$(SRCS:.c=.o) @@ -23,7 +23,7 @@ cttei: src/cttei.o $(OBJS) $(CC) $(CFLAGS) src/cttei.o $(OBJS) -o cttei pptdb: src/pptdb.o $(CTAK_OBJS) - $(CC) $(CFLAGS) src/pptdb.o $(CTAK_OBJS) -o pptdb + $(CC) $(CFLAGS) src/pptdb.o $(CTAK_OBJS) -o pptdb -lm clean: rm -f ctlm ct1986 cttei pptdb diff --git a/include/actions.c b/include/actions.c index 374f4f9..6c2eb8c 100644 --- a/include/actions.c +++ b/include/actions.c @@ -80,9 +80,9 @@ void action_list_free(action_list_t *list) { // Keep track of move offsets int8_t move_deltas[4]; -void action_list_init(void) { - move_deltas[0] = +board_size; - move_deltas[1] = -board_size; +void action_list_init(const uint8_t size) { + move_deltas[0] = +size; + move_deltas[1] = -size; move_deltas[2] = -1; move_deltas[3] = +1; } diff --git a/include/actions.h b/include/actions.h index 75c881e..de64b71 100644 --- a/include/actions.h +++ b/include/actions.h @@ -64,7 +64,7 @@ extern int8_t move_deltas[4]; // Methods // =================================================================== -void action_list_init(void); +void action_list_init(const uint8_t size); void action_list_free(action_list_t *list); action_list_t *action_list_generate(void); diff --git a/include/negamax.c b/include/negamax.c index a970b83..e83d43b 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -40,7 +40,7 @@ static float negamax(const uint8_t cur_depth, const uint8_t init_depth, void negamax_init(const uint8_t new_board_size) { board_size = new_board_size; - action_list_init(); + action_list_init(new_board_size); zobrist_init(); tt_init(); } diff --git a/src/pptdb.c b/src/pptdb.c index 79f60c5..f3d19bf 100644 --- a/src/pptdb.c +++ b/src/pptdb.c @@ -23,6 +23,9 @@ #include <string.h> #include <tak.h> +#include <actions.h> + +#include <math.h> int generate; uint64_t heights[16]; @@ -74,15 +77,22 @@ write_input(const int dx, const int dy, const uint8_t swap) { // Warning: performs _no_ checks on input whatsoever static enum ACT_RESULT -parse_line(const char *pt, const ssize_t read) { +parse_line(const char *pt, const ssize_t read, float *out_avg_actions) { ssize_t idx; enum ACT_RESULT r; int total_plies = 0; + float avg_actions = 0; + action_list_t *actions; + for (idx=0;idx<read;idx++) { if (pt[idx]==',') total_plies++; } for(idx=0;;) { + actions = action_list_generate(); + avg_actions += (float)(actions->length); + action_list_free(actions); + if (pt[idx] == 'P') { // P [A-F][1-6] [CF]?, idx+=2; @@ -142,9 +152,12 @@ parse_line(const char *pt, const ssize_t read) { } // Parse next action while (idx<read && pt[idx++]!=','); - if (idx>=read) return ACT_OK; + if (idx>=read) goto count_this; next_ply(); } + count_this: + avg_actions /= (float) total_plies; + *out_avg_actions = avg_actions; return ACT_OK; } @@ -172,6 +185,11 @@ int main(int argc, char **argv) { const uint8_t size = argv[1][0]-'0'; +#define LAZY_MAX_GAMES 1000000 + float avg_actions[LAZY_MAX_GAMES]; + for (uint32_t k=0; k<LAZY_MAX_GAMES; k++) avg_actions[k]=0; + action_list_init(size); + playtak_fh = fopen(argv[2], "r"); if (playtak_fh == NULL) exit(EXIT_FAILURE); @@ -190,7 +208,7 @@ int main(int argc, char **argv) { if (line[read-4] == '0') outcome_black = 0.9; else outcome_black = -0.9; // Parse the line - r = parse_line(line,read-4); + r = parse_line(line,read-4, avg_actions+games); // Adjust counts if we're not generating training data if (generate == 0) { if (r == ACT_ILLEGAL) { @@ -227,16 +245,25 @@ int main(int argc, char **argv) { printf("Read %d games\n",games); if (generate==0) { + float sum = 0; + for (uint32_t k=0; k<games; k++) sum+=avg_actions[k]; + const float mean = sum/(float)games; + float variance = 0; + for (uint32_t k=0; k<games; k++) variance+=(avg_actions[k]-mean)*(avg_actions[k]-mean); + variance /= (float) games; + printf("Illegals: %d\nOverflows: %d\n\ Black wins: %.3f%%\n\ Road wins: %d\nFlat wins: %d\n\ Average turns to road win: %.3f\n\ -Average turns to flat win: %.3f\n", +Average turns to flat win: %.3f\n\ +Mean avaiable actions per ply per game: %.3f ± %.3f σ\n", illegal, overflow, (double)black_wins / (double)(black_wins+white_wins) * 100, road_wins, flat_wins, (double)(road_turns)/(double)(road_wins), - (double)(flat_turns)/(double)(flat_wins)); + (double)(flat_turns)/(double)(flat_wins), + mean, sqrt(variance)); for (int k = 2; k < 16; k++) { printf("Height %2d: %7ld\n",k,heights[k]); } |
