#include #include /* 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