aboutsummaryrefslogtreecommitdiff
path: root/include/actions.c
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-30 16:47:48 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit84ad2e3c12cb505e3c5e3dd29d05edb529b82174 (patch)
tree23c4ab5496bd9b82734eccb6d4f38e29cc8792ee /include/actions.c
parentbda3a7edb76c9fe3dc21cbe5a0836829b705b407 (diff)
Try to squeeze out a little more performance
``Common wisdom'' dictates that placements are often better than stack moves, so we bias the generated move list in this fashion. Seems to be a little faster.
Diffstat (limited to 'include/actions.c')
-rw-r--r--include/actions.c31
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) {