From f706a6a0546400cb6a1925f25dc010ffce2afd49 Mon Sep 17 00:00:00 2001 From: tslil Date: Sun, 27 Dec 2020 23:21:44 -0500 Subject: Changed representation, implemented most basic things for tak.h --- include/tak.h | 66 ++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) (limited to 'include/tak.h') diff --git a/include/tak.h b/include/tak.h index 5a7f2fa..c7135ab 100644 --- a/include/tak.h +++ b/include/tak.h @@ -1,54 +1,32 @@ #include #include -/* 16 bits arranged as follows: +static uint8_t board_size = 5; - 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 colour_stack_t; +typedef uint8_t data_t; -*/ -typedef uint16_t cell_t; +enum COLOUR { C_WHITE, C_BLACK }; +enum STONE_VARIANT { STONE_FLAT, STONE_STANDING, STONE_CAPSTONE }; +enum MOVE_DIRECTION { M_UP, M_DOWN, M_LEFT, M_RIGHT }; +enum ACTION_RESULT { A_OK, A_ILLEGAL, A_OVERFLOW }; +enum WIN_RESULT { W_NONE, W_ROAD_WHITE, W_ROAD_BLACK, W_FLAT_WHITE, W_FLAT_BLACK }; -#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 +static colour_stack_t *colours = 0; +static data_t *celldat = 0; +static uint8_t white_flats, black_flats, white_caps, black_caps, turn; -#define CELL_COUNT_MAX 0b0101000000000000 -#define CELL_COUNT_INC 0b0000100000000000 -#define CELL_COUNT_SHIFT 11 +uint8_t init_game(void); +void reset_game(void); +void free_game(void); -#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))) +enum ACTION_RESULT +try_place(const int8_t location, const enum COLOUR colour, + const enum STONE_VARIANT stone); -#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) +enum ACTION_RESULT +try_move(const int8_t location, const enum MOVE_DIRECTION direction, + const uint8_t steps, const uint8_t * const drops); -#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 +enum WIN_RESULT +check_win(const enum COLOUR colour); -- cgit v1.2.3