aboutsummaryrefslogtreecommitdiff
path: root/include/tak.h
blob: 0bedde639ba0fb2aff465ffc1b42b7f0e0437ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdint.h>

enum E_RESULT { A_OK, A_ILLEGAL, A_OVERFLOW,
  PTN_VALID, PTN_INVALID, W_NONE, W_DRAW, W_DRAGON,
  W_ROAD_WHITE, W_ROAD_BLACK, W_FLAT_WHITE, W_FLAT_BLACK };

// -------------------------------------------------------------------
// State management

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 };

typedef uint8_t data_t;
typedef uint16_t colour_stack_t;

uint8_t board_size;
data_t celldat[36];
colour_stack_t colours[36];
enum COLOUR current_colour;
uint8_t white_flats, black_flats, white_caps, black_caps, turn;

void reset_state(const uint8_t new_board_size);
void next_turn(void);

enum E_RESULT
try_place(const int8_t location, const enum COLOUR colour,
          const enum STONE_VARIANT stone);

enum E_RESULT
try_move(const int8_t location, const enum MOVE_DIRECTION direction,
         const uint8_t steps, const uint8_t drops[5]);

enum E_RESULT
check_win(void);

// -------------------------------------------------------------------
// PTN related

enum E_RESULT
parse_place(const uint8_t board_size, char *ptn,
            uint8_t *out_location, enum STONE_VARIANT *out_stone);

enum E_RESULT
parse_move(const uint8_t board_size, char *ptn,
           uint8_t *out_location, enum MOVE_DIRECTION *out_direction,
           uint8_t *out_steps, uint8_t out_drops[5]);

void
generate_place(const uint8_t board_size, const uint8_t in_location,
               const enum STONE_VARIANT in_stone, char out_ptn[4]);

void
generate_move(const uint8_t board_size, const uint8_t in_location,
              const enum MOVE_DIRECTION in_direction,
              const uint8_t in_steps, const uint8_t in_drops[5],
              char out_ptn[10]);

// -------------------------------------------------------------------
// Game driver

enum E_RESULT
do_ptn(char *ptn);