simple-go.h
Raw
1#ifndef SIMPLE_GO_H
2#define SIMPLE_GO_H
3#include <stdlib.h>
4#include <stdint.h>
5#include <stdbool.h>
6#include <stdio.h>
7#include <assert.h>
8#include <string.h>
9#include <cutils/cutils.h>
10
11#define BLACK 'b'
12#define WHITE 'w'
13#define EMPTY '.'
14#define GROUP '#'
15#define NO_FIELD '\0'
16#define COUNTED '+'
17
18#define VERSIONSTR "1.1"
19
20typedef size_t go_coordinate;
21typedef char go_symbol;
22
23typedef struct go_board
24{
25 go_symbol* field_array;
26 go_coordinate size;
27} go_board;
28
29typedef struct game_state
30{
31 go_board* board;
32 double komi;
33 double white_captured;
34 double black_captured;
35 bool black_turn;
36} game_state;
37
38typedef struct go_score
39{
40 Vector* white_groups;
41 Vector* black_groups;
42 double white_points;
43 double black_points;
44} go_score;
45
46
47go_board* create_board(go_coordinate size);
48void delete_board(go_board* board);
49game_state* create_game(go_coordinate size, float komi);
50void delete_game(game_state* game);
51
52bool check_bounds(const go_board* board, go_coordinate y, go_coordinate x);
53char get_board_at(const go_board* board, go_coordinate y, go_coordinate x);
54void set_board_at(go_board* board, go_coordinate y, go_coordinate x, char item);
55
56void kill_group(game_state* game, const go_board* overlay);
57bool group_killable(game_state* game, go_coordinate y, go_coordinate x);
58bool group_attachable(const game_state* game, go_coordinate y, go_coordinate x);
59bool play_at(game_state* game, go_coordinate y, go_coordinate x, go_symbol color);
60
61void print_board(const go_board* board);
62char* board_to_string(const go_board* board);
63void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x);
64go_symbol group_belongs(const go_board* board, const go_board* overlay);
65go_coordinate count_liberties(const go_board* board, const go_board* overlay);
66go_coordinate group_size(go_board* group);
67
68go_score* score_game(const game_state* board);
69void delete_score(go_score* score);
70
71
72
73
74
75
76#endif //SIMPLE_GO_H
77