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