test.c
| 1 | #include "simple-go.h" |
| 2 | #include "simple-gtp.h" |
| 3 | |
| 4 | void 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 | |
| 36 | void 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); |
| 48 | print_board(test_game->board); |
| 49 | |
| 50 | set_board_at(test_board, 2, 1, EMPTY); |
| 51 | |
| 52 | play_at(test_game, 2, 2); |
| 53 | print_board(test_game->board); |
| 54 | |
| 55 | |
| 56 | play_at(test_game, 2, 1); |
| 57 | print_board(test_game->board); |
| 58 | |
| 59 | delete_game(test_game); |
| 60 | puts("test2 finished"); |
| 61 | } |
| 62 | |
| 63 | void 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 10", test_game); |
| 70 | printf("%s\n", ret); |
| 71 | free(ret); |
| 72 | print_board(test_game->board); |
| 73 | |
| 74 | ret =handle_gtp_cmd("version", test_game); |
| 75 | printf("%s\n", ret); |
| 76 | free(ret); |
| 77 | |
| 78 | ret =handle_gtp_cmd("komi -6.5", test_game); |
| 79 | printf("%s\n", ret); |
| 80 | printf("%f\n", test_game->komi); |
| 81 | free(ret); |
| 82 | |
| 83 | ret =handle_gtp_cmd("protocol_version", test_game); |
| 84 | printf("%s\n", ret); |
| 85 | free(ret); |
| 86 | |
| 87 | ret =handle_gtp_cmd("known_command play", test_game); |
| 88 | printf("%s\n", ret); |
| 89 | free(ret); |
| 90 | |
| 91 | ret =handle_gtp_cmd("known_command what", test_game); |
| 92 | printf("%s\n", ret); |
| 93 | free(ret); |
| 94 | |
| 95 | ret =handle_gtp_cmd("list_commands", test_game); |
| 96 | printf("%s\n", ret); |
| 97 | free(ret); |
| 98 | |
| 99 | ret =handle_gtp_cmd("1clear_board", test_game); |
| 100 | printf("%s\n", ret); |
| 101 | free(ret); |
| 102 | |
| 103 | ret =handle_gtp_cmd("2boardsize 26", test_game); |
| 104 | printf("%s\n", ret); |
| 105 | free(ret); |
| 106 | |
| 107 | ret =handle_gtp_cmd("genmove", test_game); |
| 108 | printf("%s\n", ret); |
| 109 | free(ret); |
| 110 | |
| 111 | print_board(test_game->board); |
| 112 | |
| 113 | |
| 114 | delete_game(test_game); |
| 115 | |
| 116 | puts("test3 finished"); |
| 117 | } |
| 118 | |
| 119 | void test4(void) |
| 120 | { |
| 121 | puts("test4 running"); |
| 122 | |
| 123 | game_state* test_game = create_game(19, 6.5); |
| 124 | go_board* test_board = test_game->board; |
| 125 | set_board_at(test_board, 2, 3, WHITE); |
| 126 | set_board_at(test_board, 2, 5, WHITE); |
| 127 | set_board_at(test_board, 1, 4, WHITE); |
| 128 | set_board_at(test_board, 3, 4, BLACK); |
| 129 | play_at(test_game, 2,4); |
| 130 | |
| 131 | print_board(test_game->board); |
| 132 | |
| 133 | delete_game(test_game); |
| 134 | puts("test4 finished"); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | int main(int argc, char** argv) |
| 139 | { |
| 140 | test1(); |
| 141 | test2(); |
| 142 | test3(); |
| 143 | test4(); |
| 144 | |
| 145 | } |
| 146 |