added cross-compile file for windows, changed score datatypes to double, added final_score
Minclude/simple-go/simple-go.h
| @@ -27,9 +27,9 @@ typedef struct go_board | |||
|---|---|---|---|
| 27 | 27 | typedef struct game_state | |
| 28 | 28 | { | |
| 29 | 29 | go_board* board; | |
| 30 | - | float komi; | |
| 31 | - | unsigned long white_captured; | |
| 32 | - | unsigned long black_captured; | |
| 30 | + | double komi; | |
| 31 | + | double white_captured; | |
| 32 | + | double black_captured; | |
| 33 | 33 | bool black_turn; | |
| 34 | 34 | } game_state; | |
| 35 | 35 | ||
| @@ -37,8 +37,8 @@ typedef struct go_score | |||
|---|---|---|---|
| 37 | 37 | { | |
| 38 | 38 | Vector* white_groups; | |
| 39 | 39 | Vector* black_groups; | |
| 40 | - | unsigned long white_points; | |
| 41 | - | unsigned long black_points; | |
| 40 | + | double white_points; | |
| 41 | + | double black_points; | |
| 42 | 42 | } go_score; | |
| 43 | 43 | ||
| 44 | 44 | ||
| @@ -60,8 +60,8 @@ void print_board(const go_board* board); | |||
|---|---|---|---|
| 60 | 60 | char* board_to_string(const go_board* board); | |
| 61 | 61 | void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x); | |
| 62 | 62 | go_symbol group_belongs(const go_board* board, const go_board* overlay); | |
| 63 | - | unsigned long count_liberties(const go_board* board, const go_board* overlay); | |
| 64 | - | unsigned long group_size(go_board* group); | |
| 63 | + | go_coordinate count_liberties(const go_board* board, const go_board* overlay); | |
| 64 | + | go_coordinate group_size(go_board* group); | |
| 65 | 65 | ||
| 66 | 66 | go_score* score_game(const game_state* board); | |
| 67 | 67 | void delete_score(go_score* score); | |
Minclude/simple-go/simple-gtp-func.h
| @@ -11,6 +11,7 @@ | |||
|---|---|---|---|
| 11 | 11 | extern const char* const known_commands_string ; | |
| 12 | 12 | extern const char* known_commands_array[]; | |
| 13 | 13 | ||
| 14 | + | char* unkown_command_func(const Vector* arguments, const char* id, game_state* game); | |
| 14 | 15 | char* protocol_version_func(const Vector* arguments, const char* id, game_state* game); | |
| 15 | 16 | char* name_func(const Vector* arguments, const char* id, game_state* game); | |
| 16 | 17 | char* version_func(const Vector* arguments, const char* id, game_state* game); | |
Msrc/simple-go.c
| @@ -276,9 +276,9 @@ go_symbol group_belongs(const go_board* board, const go_board* overlay) | |||
|---|---|---|---|
| 276 | 276 | return belongs; | |
| 277 | 277 | } | |
| 278 | 278 | ||
| 279 | - | unsigned long group_size(go_board* group) | |
| 279 | + | go_coordinate group_size(go_board* group) | |
| 280 | 280 | { | |
| 281 | - | unsigned long sum = 0; | |
| 281 | + | go_coordinate sum = 0; | |
| 282 | 282 | for(go_coordinate y = 0; y < group->size; y++) | |
| 283 | 283 | { | |
| 284 | 284 | for(go_coordinate x = 0; x < group->size; x++) | |
| @@ -290,14 +290,14 @@ unsigned long group_size(go_board* group) | |||
|---|---|---|---|
| 290 | 290 | return sum; | |
| 291 | 291 | } | |
| 292 | 292 | ||
| 293 | - | unsigned long count_liberties(const go_board* board, const go_board* overlay) | |
| 293 | + | go_coordinate count_liberties(const go_board* board, const go_board* overlay) | |
| 294 | 294 | { | |
| 295 | 295 | assert(board->size == overlay->size); | |
| 296 | 296 | ||
| 297 | 297 | go_board* tmpoverlay = create_board(board->size); | |
| 298 | 298 | memcpy(tmpoverlay->field_array, overlay->field_array, board->size*board->size); | |
| 299 | 299 | ||
| 300 | - | unsigned long liberties = 0; | |
| 300 | + | go_coordinate liberties = 0; | |
| 301 | 301 | ||
| 302 | 302 | for(go_coordinate y = 0; y < board->size; y++) | |
| 303 | 303 | { | |
| @@ -341,7 +341,7 @@ go_score* score_game(const game_state* game) | |||
|---|---|---|---|
| 341 | 341 | ||
| 342 | 342 | ret->white_groups = new_vector(); | |
| 343 | 343 | ret->black_groups = new_vector(); | |
| 344 | - | ret->white_points = game->white_captured; | |
| 344 | + | ret->white_points = game->white_captured + game->komi; | |
| 345 | 345 | ret->black_points = game->black_captured; | |
| 346 | 346 | ||
| 347 | 347 | go_board* board = game->board; | |
Msrc/simple-gtp-func.c
| @@ -37,6 +37,11 @@ static char* cmd_success(const char* msg, const char* id) | |||
|---|---|---|---|
| 37 | 37 | return ret; | |
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | + | char* unkown_command_func(const Vector* arguments, const char* id, game_state* game) | |
| 41 | + | { | |
| 42 | + | return cmd_error("unknown command", id); | |
| 43 | + | } | |
| 44 | + | ||
| 40 | 45 | char* protocol_version_func(const Vector* arguments, const char* id, game_state* game) | |
| 41 | 46 | { | |
| 42 | 47 | return cmd_success("2", id); | |
| @@ -166,5 +171,18 @@ char* show_board_func(const Vector* arguments, const char* id, game_state* game) | |||
|---|---|---|---|
| 166 | 171 | ||
| 167 | 172 | char* final_score_func(const Vector* arguments, const char* id, game_state* game) | |
| 168 | 173 | { | |
| 169 | - | return NULL; | |
| 174 | + | go_score* score = score_game(game); | |
| 175 | + | char* result = calloc(10,1); | |
| 176 | + | ||
| 177 | + | if(score->white_points > score->black_points) | |
| 178 | + | sprintf(result,"%c%c%.1f", 'W', '+', score->white_points-score->black_points); | |
| 179 | + | else | |
| 180 | + | sprintf(result,"%c%c%.1f", 'B', '+', score->black_points-score->white_points); | |
| 181 | + | ||
| 182 | + | char* tmp = cmd_success(result, id); | |
| 183 | + | ||
| 184 | + | free(result); | |
| 185 | + | delete_score(score); | |
| 186 | + | ||
| 187 | + | return tmp; | |
| 170 | 188 | } | |
Msrc/simple-gtp.c
| @@ -89,7 +89,7 @@ char* handle_gtp_cmd(const char* msg, game_state* game) | |||
|---|---|---|---|
| 89 | 89 | char* id = formatted.id; | |
| 90 | 90 | ||
| 91 | 91 | char* ret; | |
| 92 | - | char* (*func_ptr)(const Vector*, const char*, game_state*); | |
| 92 | + | char* (*func_ptr)(const Vector*, const char*, game_state*) = unkown_command_func; | |
| 93 | 93 | ||
| 94 | 94 | if(strcmp(command, "protocol_version") == 0) | |
| 95 | 95 | { | |
| @@ -114,6 +114,8 @@ char* handle_gtp_cmd(const char* msg, game_state* game) | |||
|---|---|---|---|
| 114 | 114 | func_ptr = genmove_func; | |
| 115 | 115 | } else if(strcmp(command, "showboard") == 0) { | |
| 116 | 116 | func_ptr = show_board_func; | |
| 117 | + | } else if(strcmp(command, "final_score") == 0) { | |
| 118 | + | func_ptr = final_score_func; | |
| 117 | 119 | } | |
| 118 | 120 | ||
| 119 | 121 | ret = func_ptr(arguments, id, game); | |
Msrc/test.c
| @@ -22,7 +22,7 @@ void test1(void) | |||
|---|---|---|---|
| 22 | 22 | ||
| 23 | 23 | print_board(test_overlay); | |
| 24 | 24 | ||
| 25 | - | printf("liberties: %ld\n", count_liberties(test_board,test_overlay)); | |
| 25 | + | printf("liberties: %d\n", count_liberties(test_board,test_overlay)); | |
| 26 | 26 | ||
| 27 | 27 | kill_group(test_board, test_overlay); | |
| 28 | 28 | ||
| @@ -112,6 +112,10 @@ void test3(void) | |||
|---|---|---|---|
| 112 | 112 | printf("%s\n", ret); | |
| 113 | 113 | free(ret); | |
| 114 | 114 | ||
| 115 | + | ret =handle_gtp_cmd("final_score", test_game); | |
| 116 | + | printf("%s\n", ret); | |
| 117 | + | free(ret); | |
| 118 | + | ||
| 115 | 119 | print_board(test_game->board); | |
| 116 | 120 | ||
| 117 | 121 | ||
| @@ -160,9 +164,9 @@ void test5(void) | |||
|---|---|---|---|
| 160 | 164 | go_score* score = score_game(game); | |
| 161 | 165 | print_board(game->board); | |
| 162 | 166 | printf("White groups: %ld\n", score->white_groups->length); | |
| 163 | - | printf("White points: %ld\n", score->white_points); | |
| 167 | + | printf("White points: %lf\n", score->white_points); | |
| 164 | 168 | printf("Black groups: %ld\n", score->black_groups->length); | |
| 165 | - | printf("Black points: %ld\n", score->black_points); | |
| 169 | + | printf("Black points: %lf\n", score->black_points); | |
| 166 | 170 | ||
| 167 | 171 | ||
| 168 | 172 | delete_score(score); | |