From f0139acd1d648dd1db93ee3d3b75546fb7b24c77 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sun, 29 Jan 2023 20:49:04 +0100 Subject: switch to returning an array of actions instead of a linked list - attempts to keep the same move ordering as the list method - saves ~170msec on a depth 7 search for a given board configuration - there is room to improve the pre-allocation size estimates, these bounds are not obviously tight and it may or may not be faster to have tighter bounds or even some form of estimation --- include/actions.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'include/actions.h') diff --git a/include/actions.h b/include/actions.h index 1550cce..0127119 100644 --- a/include/actions.h +++ b/include/actions.h @@ -43,15 +43,6 @@ typedef uint32_t action_t; ((type) | (loc) << A_LOC_SHIFT | (data0) << A_DATA0_SHIFT | \ (data1) << A_DATA1_SHIFT) -typedef struct action_node_s { - struct action_node_s *next; - action_t action; -} action_node_t; - -typedef struct action_list_s { - struct action_node_s *head, *tail; - uint32_t length; -} action_list_t; // =================================================================== // Variables @@ -63,11 +54,14 @@ extern int8_t move_deltas[4]; // Methods // =================================================================== -void action_list_init(const uint8_t board_size); -void action_list_free(action_list_t *list); -action_list_t *action_list_generate(tak_state_p state); +void actions_init(const uint8_t board_size); +void actions_free(action_t *actions); -int action_move_to_front(const action_t action, action_list_t *list); +action_t *actions_generate(tak_state_p state, uint32_t *num_actions); +char action_in_list(action_t action, action_t *actions, + const uint32_t num_actions); +void action_move_to_front(action_t action, action_t *actions, + const uint32_t num_actions); void action_take(tak_state_p state, const action_t action); void action_undo(tak_state_p state, const action_t action); -- cgit v1.3.1