aboutsummaryrefslogtreecommitdiff
path: root/include/action_list.c
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-26 14:38:19 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit277b3150630878f83a6895bea73c6d5d36ed0dbf (patch)
tree5c59f6214d662721e83ff2218cba88a4a096deba /include/action_list.c
parentfb48dd17615d7380d1b78bd6d32ebe7ea989af1f (diff)
Stable negamax-alpha-beta fail-soft
Diffstat (limited to 'include/action_list.c')
-rw-r--r--include/action_list.c63
1 files changed, 48 insertions, 15 deletions
diff --git a/include/action_list.c b/include/action_list.c
index 9ddd74b..30ca918 100644
--- a/include/action_list.c
+++ b/include/action_list.c
@@ -9,10 +9,9 @@
#define CLR_STONE NUM_MASK
static inline void
-action_list_prepend(action_list_t *list, const enum A_TYPE type,
- const int8_t loc, const uint8_t data0,
- const uint8_t data1);
-
+action_list_append(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);
@@ -24,6 +23,30 @@ inline_prev_ply(void);
// Exported method implementations
// ===================================================================
+/*
+ * void action_list_ensure_at_front(const action_node_t *action,
+ * const action_list_t *list) {
+ * action_node_t *copy = action_copy(action), *n = list->head, *nn;
+ * // ensure it's not there already
+ * while (n) {
+ * nn = n->next;
+ * }
+ *
+ * copy->next = list->head;
+ * }
+ */
+
+action_node_t *action_copy(const action_node_t *action) {
+ action_node_t *copy = malloc(sizeof(struct action_node_s));
+ // TODO: trap
+ copy->data0 = action->data0;
+ copy->data1 = action->data1;
+ copy->loc = action->loc;
+ copy->type = action->type;
+ copy->next = NULL;
+ return copy;
+}
+
void action_list_free(action_list_t *list) {
if (list) {
action_node_t *n = list->head, *nn;
@@ -64,9 +87,9 @@ action_list_t *action_list_generate(void) {
cap = ((ply >= 2) && (material & 0x80)),
standing = ((ply >= 2) && flat);
- // Step across the board, reversed because we prepend to the list
- for (int row = board_size - 1; row >= 0; row--) {
- for (int col = board_size - 1; col >= 0; col--) {
+ // Step across the board
+ for (int row = 0; row < board_size; row++) {
+ for (int col = 0; col < board_size; col++) {
// We'll need these at various points: the location of this
// square and the maximum number of stones we could pick up
const int loc = THE_COORDS(col, row);
@@ -132,7 +155,8 @@ action_list_t *action_list_generate(void) {
const uint8_t crush =
(steps == end_stops[dir]) && crushes[dir];
// Store the move
- action_list_prepend(list, A_MOVE, loc,
+
+ action_list_append(list, A_MOVE, loc,
(crush << 7) | gaps,
(dir<<4) | num);
}
@@ -154,12 +178,12 @@ action_list_t *action_list_generate(void) {
else if (material) {
// Empty square, generate placements
if (flat) {
- action_list_prepend(list, A_PLACE, loc, STONE_FLAT, 0);
+ action_list_append(list, A_PLACE, loc, STONE_FLAT, 0);
if (standing)
- action_list_prepend(list, A_PLACE, loc, STONE_STANDING,0);
+ action_list_append(list, A_PLACE, loc, STONE_STANDING,0);
}
if (cap)
- action_list_prepend(list, A_PLACE, loc, STONE_CAPSTONE, 0);
+ action_list_append(list, A_PLACE, loc, STONE_CAPSTONE, 0);
}
}
}
@@ -333,18 +357,27 @@ void action_to_ptn(action_node_t* action, char* out_ptn) {
// ===================================================================
static inline void
-action_list_prepend(action_list_t *list, const enum A_TYPE type,
+action_list_append(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
- list->length++;
+
new->loc = loc;
new->type = type;
new->data0 = data0;
new->data1 = data1;
- new->next = list->head;
- list->head = new;
+ new->next = NULL;
+
+ if (list->length) {
+ list->tail->next = new;
+ list->tail = new;
+ } else {
+ list->head = new;
+ list->tail = new;
+ }
+
+ list->length++;
}
static inline void