added cross-compile file for windows, changed score datatypes to double, added final_score

AuthorKonata <konata@posteo.jp>
Date
Commit6ab83b93df866951f39a51775dfd0886412a15ea
Parentce4e5f4
6 files changed, 42 insertions(+), 17 deletions(-)
Minclude/simple-go/simple-go.h
@@ -27,9 +27,9 @@ typedef struct go_board
2727 typedef struct game_state
2828 {
2929 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;
3333 bool black_turn;
3434 } game_state;
3535
@@ -37,8 +37,8 @@ typedef struct go_score
3737 {
3838 Vector* white_groups;
3939 Vector* black_groups;
40- unsigned long white_points;
41- unsigned long black_points;
40+ double white_points;
41+ double black_points;
4242 } go_score;
4343
4444
@@ -60,8 +60,8 @@ void print_board(const go_board* board);
6060 char* board_to_string(const go_board* board);
6161 void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x);
6262 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);
6565
6666 go_score* score_game(const game_state* board);
6767 void delete_score(go_score* score);
Minclude/simple-go/simple-gtp-func.h
@@ -11,6 +11,7 @@
1111 extern const char* const known_commands_string ;
1212 extern const char* known_commands_array[];
1313
14+char* unkown_command_func(const Vector* arguments, const char* id, game_state* game);
1415 char* protocol_version_func(const Vector* arguments, const char* id, game_state* game);
1516 char* name_func(const Vector* arguments, const char* id, game_state* game);
1617 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)
276276 return belongs;
277277 }
278278
279-unsigned long group_size(go_board* group)
279+go_coordinate group_size(go_board* group)
280280 {
281- unsigned long sum = 0;
281+ go_coordinate sum = 0;
282282 for(go_coordinate y = 0; y < group->size; y++)
283283 {
284284 for(go_coordinate x = 0; x < group->size; x++)
@@ -290,14 +290,14 @@ unsigned long group_size(go_board* group)
290290 return sum;
291291 }
292292
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)
294294 {
295295 assert(board->size == overlay->size);
296296
297297 go_board* tmpoverlay = create_board(board->size);
298298 memcpy(tmpoverlay->field_array, overlay->field_array, board->size*board->size);
299299
300- unsigned long liberties = 0;
300+ go_coordinate liberties = 0;
301301
302302 for(go_coordinate y = 0; y < board->size; y++)
303303 {
@@ -341,7 +341,7 @@ go_score* score_game(const game_state* game)
341341
342342 ret->white_groups = new_vector();
343343 ret->black_groups = new_vector();
344- ret->white_points = game->white_captured;
344+ ret->white_points = game->white_captured + game->komi;
345345 ret->black_points = game->black_captured;
346346
347347 go_board* board = game->board;
Msrc/simple-gtp-func.c
@@ -37,6 +37,11 @@ static char* cmd_success(const char* msg, const char* id)
3737 return ret;
3838 }
3939
40+char* unkown_command_func(const Vector* arguments, const char* id, game_state* game)
41+{
42+ return cmd_error("unknown command", id);
43+}
44+
4045 char* protocol_version_func(const Vector* arguments, const char* id, game_state* game)
4146 {
4247 return cmd_success("2", id);
@@ -166,5 +171,18 @@ char* show_board_func(const Vector* arguments, const char* id, game_state* game)
166171
167172 char* final_score_func(const Vector* arguments, const char* id, game_state* game)
168173 {
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;
170188 }
Msrc/simple-gtp.c
@@ -89,7 +89,7 @@ char* handle_gtp_cmd(const char* msg, game_state* game)
8989 char* id = formatted.id;
9090
9191 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;
9393
9494 if(strcmp(command, "protocol_version") == 0)
9595 {
@@ -114,6 +114,8 @@ char* handle_gtp_cmd(const char* msg, game_state* game)
114114 func_ptr = genmove_func;
115115 } else if(strcmp(command, "showboard") == 0) {
116116 func_ptr = show_board_func;
117+ } else if(strcmp(command, "final_score") == 0) {
118+ func_ptr = final_score_func;
117119 }
118120
119121 ret = func_ptr(arguments, id, game);
Msrc/test.c
@@ -22,7 +22,7 @@ void test1(void)
2222
2323 print_board(test_overlay);
2424
25- printf("liberties: %ld\n", count_liberties(test_board,test_overlay));
25+ printf("liberties: %d\n", count_liberties(test_board,test_overlay));
2626
2727 kill_group(test_board, test_overlay);
2828
@@ -112,6 +112,10 @@ void test3(void)
112112 printf("%s\n", ret);
113113 free(ret);
114114
115+ ret =handle_gtp_cmd("final_score", test_game);
116+ printf("%s\n", ret);
117+ free(ret);
118+
115119 print_board(test_game->board);
116120
117121
@@ -160,9 +164,9 @@ void test5(void)
160164 go_score* score = score_game(game);
161165 print_board(game->board);
162166 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);
164168 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);
166170
167171
168172 delete_score(score);