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
18typedef unsigned int go_coordinate;
19typedef char go_symbol;
20
21typedef struct go_board
22{
23 go_symbol* field_array;
24 go_coordinate size;
25} go_board;
26
27typedef struct game_state
28{
29 go_board* board;
30 float komi;
31 unsigned long white_captured;
32 unsigned long black_captured;
33 bool black_turn;
34} game_state;
35
36typedef struct go_score
37{
38 Vector* white_groups;
39 Vector* black_groups;
40 unsigned long white_points;
41 unsigned long black_points;
42} go_score;
43
44
45go_board* create_board(go_coordinate size);
46void delete_board(go_board* board);
47game_state* create_game(go_coordinate size, float komi);
48void delete_game(game_state* game);
49
50bool check_bounds(const go_board* board, go_coordinate y, go_coordinate x);
51char get_board_at(const go_board* board, go_coordinate y, go_coordinate x);
52void set_board_at(go_board* board, go_coordinate y, go_coordinate x, char item);
53
54void kill_group(go_board* board, const go_board* overlay);
55bool group_killable(game_state* game, go_coordinate y, go_coordinate x);
56bool group_attachable(const game_state* game, go_coordinate y, go_coordinate x);
57bool play_at(game_state* game, go_coordinate y, go_coordinate x, go_symbol color);
58
59void print_board(const go_board* board);
60char* board_to_string(const go_board* board);
61void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x);
62go_symbol group_belongs(const go_board* board, const go_board* overlay);
63unsigned long count_liberties(const go_board* board, const go_board* overlay);
64unsigned long group_size(go_board* group);
65
66go_score* score_game(const game_state* board);
67void delete_score(go_score* score);
68
69
70
71
72
73
74#endif //SIMPLE_GO_H
75