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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
This file is part of ctak.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TAK_H
#define TAK_H
#include <stdint.h>
// ===================================================================
// Types
// ===================================================================
enum ACT_RESULT { ACT_OK, ACT_ILLEGAL, ACT_OVERFLOW, ACT_INVALID_PTN, GAME_END };
enum PTN_RESULT { PTN_OK, PTN_INVALID };
enum TPS_RESULT { TPS_OK, TPS_INVALID };
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 WIN_TYPE { WIN_DRAW,
WIN_FLAT_WHITE, WIN_FLAT_BLACK,
WIN_ROAD_WHITE, WIN_ROAD_BLACK };
typedef uint8_t data_t;
typedef uint16_t colour_stack_t;
#define NUM_SHIFT 4
#define NUM_MASK (0xF<<NUM_SHIFT) // 0b11110000
#define NUM_INC (0x1<<NUM_SHIFT) // 0b00010000
#define STONE_MASK 3 // 0b00000011
#define STONE_AT(l) (celldat[(l)] & STONE_MASK)
#define COUNT_AT(l) (celldat[(l)] >> NUM_SHIFT)
#define THE_COORDS(col,row) ((col)+(row)*board_size)
// ===================================================================
// Variables
// ===================================================================
// NOTE: We only support one capstone per player and 5s or 6s games.
extern enum WIN_TYPE won;
extern uint8_t board_size;
extern data_t celldat[36];
extern colour_stack_t colours[36];
extern enum COLOUR current_colour;
extern uint8_t white_count, black_count, ply;
// ===================================================================
// Methods
// ===================================================================
// -------------------------------------------------------------------
// Game state
void reset_state(const uint8_t new_board_size);
void next_ply(void);
enum ACT_RESULT
try_place(const int8_t location, const enum COLOUR colour,
const enum STONE_VARIANT stone);
enum ACT_RESULT
try_move(const int8_t location, const enum MOVE_DIRECTION direction,
const uint8_t steps, const uint8_t drops[5]);
enum WIN_TYPE
check_win(void);
// -------------------------------------------------------------------
// PTN related
enum PTN_RESULT
parse_place(char *in_ptn, uint8_t *out_location,
enum STONE_VARIANT *out_stone);
enum PTN_RESULT
parse_move(char *in_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 in_location,
const enum STONE_VARIANT in_stone, char out_ptn[4]);
void
generate_move(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 ACT_RESULT
do_ptn(char *ptn);
#endif
|