diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-28 13:54:10 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 6e6cdc4d9f0d7e4afdda67c97e7d7f13959e6134 (patch) | |
| tree | 15322705ce1dd73c1eb863678360a0e403490337 /include/actions.c | |
| parent | 55b45cc666c2ef883efe3831b96ac40623622582 (diff) | |
| parent | 1be9fac33c8227564079356c63840d227c88725f (diff) | |
Merge branch 'zobrist'
Diffstat (limited to 'include/actions.c')
| -rw-r--r-- | include/actions.c | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/include/actions.c b/include/actions.c index 9b3534b..5085330 100644 --- a/include/actions.c +++ b/include/actions.c @@ -8,15 +8,6 @@ #define CLR_STONE NUM_MASK -#define TYPE_SHIFT 24 -#define LOC_SHIFT 16 -#define DATA0_SHIFT 8 - -#define GET_TYPE(a) (enum A_TYPE)((a)>>TYPE_SHIFT) -#define GET_LOC(a) (int8_t)(((a)>>LOC_SHIFT) & 0xFF) -#define GET_DATA0(a) (uint8_t)(((a)>>DATA0_SHIFT) & 0xFF) -#define GET_DATA1(a) (uint8_t)((a) & 0xFF) - static inline void list_append(action_list_t *list, const enum A_TYPE type, const int8_t loc, const uint8_t data0, @@ -65,13 +56,13 @@ void action_list_free(action_list_t *list) { } // Keep track of move offsets -static int8_t deltas[4]; +int8_t move_deltas[4]; void action_list_init(void) { - deltas[0] = +board_size; - deltas[1] = -board_size; - deltas[2] = -1; - deltas[3] = +1; + move_deltas[0] = +board_size; + move_deltas[1] = -board_size; + move_deltas[2] = -1; + move_deltas[3] = +1; } action_list_t *action_list_generate(void) { @@ -117,7 +108,7 @@ action_list_t *action_list_generate(void) { // Now we check for caps and walls const uint8_t cap_top = STONE_AT(loc) == STONE_CAPSTONE; for (int d = 0; d < 4; d++){ - const int delta = deltas[d]; + const int delta = move_deltas[d]; const int stop = end_stops[d]; end_stops[d] = 0; for (int k = 1; k <= stop; k++) { @@ -196,10 +187,10 @@ action_list_t *action_list_generate(void) { } void action_take(const action_t action) { - const int8_t loc = GET_LOC(action); - if (GET_TYPE(action) == A_PLACE) { + const int8_t loc = A_GET_LOC(action); + if (A_GET_TYPE(action) == A_PLACE) { const uint8_t black = (current_colour == C_BLACK); - switch (GET_DATA0(action)) { + switch (A_GET_DATA0(action)) { case STONE_FLAT: { if (black) black_count--; else white_count--; @@ -226,10 +217,10 @@ void action_take(const action_t action) { // not interested in whether we crushed, it will work out by // anyway because we overwrite the top stone type. See (*) later // for when we do need to know. - const uint8_t gaps = GET_DATA0(action) & 0x7F, - num = GET_DATA1(action) & 0x0F, // unpack - dir = GET_DATA1(action) >> 4; - int8_t delta = deltas[dir]; + const uint8_t gaps = A_GET_DATA0(action) & 0x7F, + num = A_GET_DATA1(action) & 0x0F, // unpack + dir = A_GET_DATA1(action) >> 4; + int8_t delta = move_deltas[dir]; // Use the Kernighan method to count the set bits int8_t steps = 1; @@ -275,11 +266,11 @@ void action_undo(const action_t action) { // Previous ply inline_prev_ply(); - const int8_t loc = GET_LOC(action); - if (GET_TYPE(action) == A_PLACE) { + const int8_t loc = A_GET_LOC(action); + if (A_GET_TYPE(action) == A_PLACE) { const uint8_t black = (current_colour == C_BLACK); celldat[loc] = 0; - if (GET_DATA0(action) == STONE_CAPSTONE) { + if (A_GET_DATA0(action) == STONE_CAPSTONE) { if (black) black_count |= 0x80; else white_count |= 0x80; } else { @@ -289,11 +280,11 @@ void action_undo(const action_t action) { } else { // See action_take for comments, this is the time reversal, but // there is one caveat -- undoing a crush! (*) - const uint8_t gaps = GET_DATA0(action) & 0x7F, - crush = GET_DATA0(action) & 0x80, - num = GET_DATA1(action) & 0x0F, - dir = GET_DATA1(action) >> 4; - const int8_t delta = deltas[dir]; + const uint8_t gaps = A_GET_DATA0(action) & 0x7F, + crush = A_GET_DATA0(action) & 0x80, + num = A_GET_DATA1(action) & 0x0F, + dir = A_GET_DATA1(action) >> 4; + const int8_t delta = move_deltas[dir]; int8_t steps = 1; uint8_t gap_bit = 1, total = 1; @@ -326,13 +317,13 @@ void action_undo(const action_t action) { } void action_to_ptn(const action_t action, char* out_ptn) { - const int8_t loc = GET_LOC(action); - if (GET_TYPE(action) == A_PLACE) { - generate_place(loc, GET_DATA0(action), out_ptn); + const int8_t loc = A_GET_LOC(action); + if (A_GET_TYPE(action) == A_PLACE) { + generate_place(loc, A_GET_DATA0(action), out_ptn); } else { - const uint8_t gaps = GET_DATA0(action) & 0x7F, - num = GET_DATA1(action) & 0x0F, // unpack - dir = GET_DATA1(action) >> 4; + const uint8_t gaps = A_GET_DATA0(action) & 0x7F, + num = A_GET_DATA1(action) & 0x0F, // unpack + dir = A_GET_DATA1(action) >> 4; uint8_t drops[board_size]; // we only ever need board_size-1 in // drops actually, the last spot is to @@ -365,10 +356,7 @@ list_append(action_list_t *list, const enum A_TYPE type, // TODO: trap errno new->next = NULL; - new->action = (type << TYPE_SHIFT) - | (loc << LOC_SHIFT) - | (data0 << DATA0_SHIFT) - | data1; + new->action = A_BUILD(type, loc, data0, data1); if (list->length) { list->tail->next = new; |
