diff options
Diffstat (limited to 'include/actions.c')
| -rw-r--r-- | include/actions.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/include/actions.c b/include/actions.c index 800a2d4..316b19f 100644 --- a/include/actions.c +++ b/include/actions.c @@ -31,6 +31,11 @@ list_append(action_list_t *list, const enum A_TYPE type, const uint8_t data1); static inline void +list_prepend(action_list_t *list, const enum A_TYPE type, + const int8_t loc, const uint8_t data0, + const uint8_t data1); + +static inline void inline_next_ply(void); static inline void @@ -82,6 +87,8 @@ void action_list_init(void) { move_deltas[3] = +1; } +// We bias place over move by prepending place actions and appending +// move actions to the generated list action_list_t *action_list_generate(void) { action_list_t *list = malloc(sizeof(struct action_list_s)); @@ -198,12 +205,12 @@ action_list_t *action_list_generate(void) { else if (material) { // Empty square, generate placements if (flat) { - list_append(list, A_PLACE, loc, STONE_FLAT, 0); + list_prepend(list, A_PLACE, loc, STONE_FLAT, 0); if (standing) - list_append(list, A_PLACE, loc, STONE_STANDING,0); + list_prepend(list, A_PLACE, loc, STONE_STANDING,0); } if (cap) - list_append(list, A_PLACE, loc, STONE_CAPSTONE, 0); + list_prepend(list, A_PLACE, loc, STONE_CAPSTONE, 0); } } } @@ -397,6 +404,24 @@ list_append(action_list_t *list, const enum A_TYPE type, } static inline void +list_prepend(action_list_t *list, const enum A_TYPE type, + const int8_t loc, const uint8_t data0, + const uint8_t data1) { + action_node_t *new = malloc(sizeof(action_list_t)); + // TODO: trap errno + + new->next = list->head; + list->head = new; + new->action = A_BUILD(type, loc, data0, data1); + + if (list->length == 0) { + list->tail = new; + } + + list->length++; +} + +static inline void inline_next_ply(void) { ply++; if (ply == 2) { |
