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
typedef struct game_state
{
go_board* board;
float komi;
unsigned long white_captured;
unsigned long black_captured;
double komi;
double white_captured;
double black_captured;
bool black_turn;
} game_state;
@@ -37,8 +37,8 @@ typedef struct go_score
{
Vector* white_groups;
Vector* black_groups;
unsigned long white_points;
unsigned long black_points;
double white_points;
double black_points;
} go_score;
@@ -60,8 +60,8 @@ void print_board(const go_board* board);
char* board_to_string(const go_board* board);
void find_group(const go_board* board, go_board* overlay, go_coordinate y, go_coordinate x);
go_symbol group_belongs(const go_board* board, const go_board* overlay);
unsigned long count_liberties(const go_board* board, const go_board* overlay);
unsigned long group_size(go_board* group);
go_coordinate count_liberties(const go_board* board, const go_board* overlay);
go_coordinate group_size(go_board* group);
go_score* score_game(const game_state* board);
void delete_score(go_score* score);
▾Minclude/simple-go/simple-gtp-func.h
@@ -11,6 +11,7 @@
extern const char* const known_commands_string ;
extern const char* known_commands_array[];
char* unkown_command_func(const Vector* arguments, const char* id, game_state* game);
char* protocol_version_func(const Vector* arguments, const char* id, game_state* game);
char* name_func(const Vector* arguments, const char* id, game_state* game);
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)
return belongs;
}
unsigned long group_size(go_board* group)
go_coordinate group_size(go_board* group)
{
unsigned long sum = 0;
go_coordinate sum = 0;
for(go_coordinate y = 0; y < group->size; y++)
{
for(go_coordinate x = 0; x < group->size; x++)
@@ -290,14 +290,14 @@ unsigned long group_size(go_board* group)
return sum;
}
unsigned long count_liberties(const go_board* board, const go_board* overlay)
go_coordinate count_liberties(const go_board* board, const go_board* overlay)
{
assert(board->size == overlay->size);
go_board* tmpoverlay = create_board(board->size);
memcpy(tmpoverlay->field_array, overlay->field_array, board->size*board->size);
unsigned long liberties = 0;
go_coordinate liberties = 0;
for(go_coordinate y = 0; y < board->size; y++)
{
@@ -341,7 +341,7 @@ go_score* score_game(const game_state* game)
ret->white_groups = new_vector();
ret->black_groups = new_vector();
ret->white_points = game->white_captured;
ret->white_points = game->white_captured + game->komi;
ret->black_points = game->black_captured;
go_board* board = game->board;
▾Msrc/simple-gtp-func.c
@@ -37,6 +37,11 @@ static char* cmd_success(const char* msg, const char* id)
return ret;
}
char* unkown_command_func(const Vector* arguments, const char* id, game_state* game)
{
return cmd_error("unknown command", id);
}
char* protocol_version_func(const Vector* arguments, const char* id, game_state* game)
{
return cmd_success("2", id);
@@ -166,5 +171,18 @@ char* show_board_func(const Vector* arguments, const char* id, game_state* game)
char* final_score_func(const Vector* arguments, const char* id, game_state* game)
{
return NULL;
go_score* score = score_game(game);
char* result = calloc(10,1);
if(score->white_points > score->black_points)
sprintf(result,"%c%c%.1f", 'W', '+', score->white_points-score->black_points);
else
sprintf(result,"%c%c%.1f", 'B', '+', score->black_points-score->white_points);
char* tmp = cmd_success(result, id);
free(result);
delete_score(score);
return tmp;
}
▾Msrc/simple-gtp.c
@@ -89,7 +89,7 @@ char* handle_gtp_cmd(const char* msg, game_state* game)
char* id = formatted.id;
char* ret;
char* (*func_ptr)(const Vector*, const char*, game_state*);
char* (*func_ptr)(const Vector*, const char*, game_state*) = unkown_command_func;
if(strcmp(command, "protocol_version") == 0)
{
@@ -114,6 +114,8 @@ char* handle_gtp_cmd(const char* msg, game_state* game)
func_ptr = genmove_func;
} else if(strcmp(command, "showboard") == 0) {
func_ptr = show_board_func;
} else if(strcmp(command, "final_score") == 0) {
func_ptr = final_score_func;
}
ret = func_ptr(arguments, id, game);
▾Msrc/test.c
@@ -22,7 +22,7 @@ void test1(void)
print_board(test_overlay);
printf("liberties: %ld\n", count_liberties(test_board,test_overlay));
printf("liberties: %d\n", count_liberties(test_board,test_overlay));
kill_group(test_board, test_overlay);
@@ -112,6 +112,10 @@ void test3(void)
printf("%s\n", ret);
free(ret);
ret =handle_gtp_cmd("final_score", test_game);
printf("%s\n", ret);
free(ret);
print_board(test_game->board);
@@ -160,9 +164,9 @@ void test5(void)
go_score* score = score_game(game);
print_board(game->board);
printf("White groups: %ld\n", score->white_groups->length);
printf("White points: %ld\n", score->white_points);
printf("White points: %lf\n", score->white_points);
printf("Black groups: %ld\n", score->black_groups->length);
printf("Black points: %ld\n", score->black_points);
printf("Black points: %lf\n", score->black_points);
delete_score(score);