From 1d1b28c294143f7a918db7a646b5564674616e44 Mon Sep 17 00:00:00 2001 From: tslil Date: Fri, 7 May 2021 22:19:31 -0400 Subject: quick hach --- Makefile | 4 ++-- include/actions.c | 6 +++--- include/actions.h | 2 +- include/negamax.c | 2 +- src/pptdb.c | 37 ++++++++++++++++++++++++++++++++----- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 8b4ab58..af483bf 100644 --- a/Makefile +++ b/Makefile @@ -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 #include +#include + +#include 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;idxlength); + 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) 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