test.c
Raw
1#include <simple-go/simple-go.h>
2#include <simple-go/simple-gtp.h>
3
4void test1(void)
5{
6 puts("test1 running");
7 go_board* test_board = create_board(5);
8
9 set_board_at(test_board, 2, 2, WHITE);
10 set_board_at(test_board, 2, 3, WHITE);
11 set_board_at(test_board, 1, 3, WHITE);
12 set_board_at(test_board, 3, 3, WHITE);
13 set_board_at(test_board, 4, 4, WHITE);
14 set_board_at(test_board, 3, 1, WHITE);
15 set_board_at(test_board, 3, 2, BLACK);
16
17 print_board(test_board);
18 putchar('\n');
19
20 go_board* test_overlay = create_board(5);
21 find_group(test_board, test_overlay, 2, 2);
22
23 print_board(test_overlay);
24
25 printf("liberties: %ld\n", count_liberties(test_board,test_overlay));
26
27 kill_group(test_board, test_overlay);
28
29 print_board(test_board);
30
31 delete_board(test_board);
32 delete_board(test_overlay);
33 puts("test1 finished");
34}
35
36void test2(void)
37{
38 puts("test2 running");
39 game_state* test_game = create_game(5, 0);
40 go_board* test_board = test_game->board;
41 set_board_at(test_board, 2, 3, WHITE);
42 set_board_at(test_board, 3, 2, WHITE);
43 set_board_at(test_board, 1, 2, WHITE);
44 set_board_at(test_board, 2, 1, WHITE);
45 set_board_at(test_board, 1, 1, BLACK);
46
47 play_at(test_game, 2, 2, NO_FIELD);
48 print_board(test_game->board);
49
50 set_board_at(test_board, 2, 1, EMPTY);
51
52 play_at(test_game, 2, 2, NO_FIELD);
53 print_board(test_game->board);
54
55
56 play_at(test_game, 2, 1, NO_FIELD);
57 print_board(test_game->board);
58
59 delete_game(test_game);
60 puts("test2 finished");
61}
62
63void test3(void)
64{
65 puts("test3 running");
66
67 game_state* test_game = create_game(11, 0);
68
69 char* ret =handle_gtp_cmd("play white a 11", test_game);
70 printf("%s\n", ret);
71 free(ret);
72 print_board(test_game->board);
73
74 ret =handle_gtp_cmd("showboard", test_game);
75 printf("%s\n", ret);
76 free(ret);
77
78 ret =handle_gtp_cmd("version", test_game);
79 printf("%s\n", ret);
80 free(ret);
81
82 ret =handle_gtp_cmd("komi -6.5", test_game);
83 printf("%s\n", ret);
84 printf("%f\n", test_game->komi);
85 free(ret);
86
87 ret =handle_gtp_cmd("protocol_version", test_game);
88 printf("%s\n", ret);
89 free(ret);
90
91 ret =handle_gtp_cmd("known_command play", test_game);
92 printf("%s\n", ret);
93 free(ret);
94
95 ret =handle_gtp_cmd("known_command what", test_game);
96 printf("%s\n", ret);
97 free(ret);
98
99 ret =handle_gtp_cmd("list_commands", test_game);
100 printf("%s\n", ret);
101 free(ret);
102
103 ret =handle_gtp_cmd("1clear_board", test_game);
104 printf("%s\n", ret);
105 free(ret);
106
107 ret =handle_gtp_cmd("2boardsize 26", test_game);
108 printf("%s\n", ret);
109 free(ret);
110
111 ret =handle_gtp_cmd("genmove", test_game);
112 printf("%s\n", ret);
113 free(ret);
114
115 print_board(test_game->board);
116
117
118 delete_game(test_game);
119
120 puts("test3 finished");
121}
122
123void test4(void)
124{
125 puts("test4 running");
126
127 game_state* test_game = create_game(19, 6.5);
128 go_board* test_board = test_game->board;
129 set_board_at(test_board, 2, 3, WHITE);
130 set_board_at(test_board, 2, 5, WHITE);
131 set_board_at(test_board, 1, 4, WHITE);
132 set_board_at(test_board, 3, 4, BLACK);
133 play_at(test_game, 2,4, NO_FIELD);
134
135 print_board(test_game->board);
136
137 delete_game(test_game);
138 puts("test4 finished");
139}
140
141void test5(void)
142{
143 puts("test5 running");
144 game_state* game = create_game(19,0);
145 set_board_at(game->board, 2, 3, WHITE);
146 set_board_at(game->board, 2, 5, WHITE);
147 set_board_at(game->board, 1, 4, WHITE);
148 set_board_at(game->board, 3, 4, WHITE);
149
150 set_board_at(game->board, 5, 6, WHITE);
151 set_board_at(game->board, 5, 8, WHITE);
152 set_board_at(game->board, 4, 7, WHITE);
153 set_board_at(game->board, 6, 7, BLACK);
154
155 set_board_at(game->board, 5, 2, BLACK);
156 set_board_at(game->board, 5, 4, BLACK);
157 set_board_at(game->board, 4, 3, BLACK);
158 set_board_at(game->board, 6, 3, BLACK);
159
160 go_score* score = score_game(game);
161 print_board(game->board);
162 printf("White groups: %ld\n", score->white_groups->length);
163 printf("White points: %ld\n", score->white_points);
164 printf("Black groups: %ld\n", score->black_groups->length);
165 printf("Black points: %ld\n", score->black_points);
166
167
168 delete_score(score);
169 delete_game(game);
170 puts("test5 finished");
171}
172
173
174int main(int argc, char** argv)
175{
176
177 test1();
178 test2();
179 test3();
180 test4();
181 test5();
182
183}
184