simple-go.h
| 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 | |
| 20 | typedef size_t go_coordinate; |
| 21 | typedef char go_symbol; |
| 22 | |
| 23 | typedef struct go_board |
| 24 | { |
| 25 | go_symbol* field_array; |
| 26 | go_coordinate size; |
| 27 | } go_board; |
| 28 | |
| 29 | typedef 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 | |
| 38 | typedef 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 | |
| 47 | go_board* create_board(go_coordinate size); |
| 48 | void delete_board(go_board* board); |
| 49 | game_state* create_game(go_coordinate size, float komi); |
| 50 | void delete_game(game_state* game); |
| 51 | |
| 52 | bool check_bounds(const go_board* board, go_coordinate y, go_coordinate x); |
| 53 | char get_board_at(const go_board* board, go_coordinate y, go_coordinate x); |
| 54 | void set_board_at(go_board* board, go_coordinate y, go_coordinate x, char item); |
| 55 | |
| 56 | void kill_group(game_state* game, const go_board* overlay); |
| 57 | bool group_killable(game_state* game, go_coordinate y, go_coordinate x); |
| 58 | bool group_attachable(const game_state* game, go_coordinate y, go_coordinate x); |
| 59 | bool play_at(game_state* game, go_coordinate y, go_coordinate x, go_symbol color); |
| 60 | |
| 61 | void print_board(const go_board* board); |
| 62 | char* board_to_string(const go_board* board); |
| 63 | void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x); |
| 64 | go_symbol group_belongs(const go_board* board, const go_board* overlay); |
| 65 | go_coordinate count_liberties(const go_board* board, const go_board* overlay); |
| 66 | go_coordinate group_size(go_board* group); |
| 67 | |
| 68 | go_score* score_game(const game_state* board); |
| 69 | void delete_score(go_score* score); |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | #endif //SIMPLE_GO_H |
| 77 |