diff options
| author | tslil <tslil@posteo.de> | 2020-12-22 22:40:31 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 49d4f7867927a47d9a9b598236f76b509cc9b7b5 (patch) | |
| tree | 5001e2d8e8366200a9f61e939429f4629a6dff9d /include/tak.h | |
Init
Diffstat (limited to 'include/tak.h')
| -rw-r--r-- | include/tak.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/tak.h b/include/tak.h new file mode 100644 index 0000000..5a7f2fa --- /dev/null +++ b/include/tak.h @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <stdint.h> + +/* 16 bits arranged as follows: + + MSB : capstone or standing stone + 14-11: number of stones in the cell, 0x0-0xA valid, 0xF means empty + 0-10 : stack, LSB is top + +*/ +typedef uint16_t cell_t; + +#define CELL_EMPTY_VALUE 0b0111100000000000 +#define CELL_MASK_CAPSTAND 0b1000000000000000 +#define CELL_MASK_COUNT CELL_EMPTY_VALUE +#define CELL_MASK_STACK 0b0000011111111111 +#define CELL_MASK_NOTSTACK 0b1111100000000000 + +#define CELL_COUNT_MAX 0b0101000000000000 +#define CELL_COUNT_INC 0b0000100000000000 +#define CELL_COUNT_SHIFT 11 + +#define CELL_IS_EMPTY(x) ((x) == CELL_EMPTY_VALUE) +#define CELL_IS_CAPSTAND(x) ((x) & CELL_MASK_CAPSTAND) +#define CELL_TOP_IS_BLACK(x) ((x) & 1) +#define CELL_TOP_IS_WHITE(x) (~(CELL_TOP_IS_BLACK(x))) + +#define CELL_SET_TOP_BLACK(x) ((x) |= 0x0001) +#define CELL_SET_TOP_WHITE(x) ((x) &= 0xFFFE) +#define CELL_SET_CAPSTAND(x) ((x) |= CELL_MASK_CAPSTAND) + +#define CELL_GET_COUNT(x) ((uint8_t)(((x) & CELL_MASK_COUNT) >> CELL_COUNT_SHIFT)) +#define CELL_GET_STACK(x) ((x) & CELL_MASK_STACK) +#define CELL_GET_NOTSTACK(x) ((x) & CELL_MASK_NOTSTACK) + +enum ACTION_RESULT { A_OK, A_ILLEGAL, A_OVERFLOW }; + +typedef cell_t* board_t; +typedef uint64_t bit_board_t; // 8x8 board is exactly 8 bytes :) + +#define BITBOARD_SET(bb,location) ((bb) |= 1ULL << (location)) +#define BITBOARD_RST(bb,location) ((bb) &= ~(1ULL << (location))) + +enum STONE_VARIANT { STONE_FLAT, STONE_STANDING, STONE_CAPSTONE }; +#define STONE_IS_CAPSTAND(s) ((s == STONE_CAPSTONE) || (s == STONE_STANDING)) + +// Taking actions +enum ACTION_RESULT try_place_stone(board_t board, bit_board_t *capstand, + const uint8_t location, const uint8_t colour, + const enum STONE_VARIANT stone); + +// enum ACTION_RESULT move_stack(board_t *board, bit_board *capstand, uint8_t source, uint); + +// Querying things |
