Ticket #25: arend_7_7.10-remove_interface_wrappers.diff
| File arend_7_7.10-remove_interface_wrappers.diff, 18.0 kB (added by arend, 3 years ago) |
|---|
-
engine/gnugo.h
old new 85 85 86 86 87 87 void gnugo_clear_board(int boardsize); 88 void gnugo_set_komi(float new_komi);89 void gnugo_add_stone(int i, int j, int color);90 void gnugo_remove_stone(int i, int j);91 int gnugo_is_pass(int i, int j);92 88 void gnugo_play_move(int i, int j, int color); 93 int gnugo_undo_move(int n);94 89 int gnugo_play_sgfnode(SGFNode *node, int to_move); 95 90 int gnugo_play_sgftree(SGFNode *root, int *until, SGFNode **curnode); 96 int gnugo_is_legal(int i, int j, int color);97 int gnugo_is_suicide(int i, int j, int color);98 91 99 int gnugo_placehand(int handicap);100 92 int gnugo_sethand(int handicap, SGFNode *root); 101 void gnugo_recordboard(SGFNode *node);102 93 103 94 float gnugo_genmove(int *i, int *j, int color, int *resign); 104 95 105 96 int gnugo_attack(int m, int n, int *i, int *j); 106 97 int gnugo_find_defense(int m, int n, int *i, int *j); 107 98 108 void gnugo_who_wins(int color, FILE *outfile);109 99 float gnugo_estimate_score(float *upper, float *lower); 110 111 float gnugo_get_komi(void);112 void gnugo_get_board(int b[MAX_BOARD][MAX_BOARD]);113 int gnugo_get_boardsize(void);114 int gnugo_get_move_number(void);115 100 116 101 /* ================================================================ */ 117 102 /* Game handling */ -
engine/interface.c
old new 74 74 #endif 75 75 } 76 76 77 /* Set the komi */78 79 void80 gnugo_set_komi(float new_komi)81 {82 komi = new_komi;83 }84 85 /* Place a stone on the board */86 87 void88 gnugo_add_stone(int i, int j, int color)89 {90 add_stone(POS(i, j), color);91 }92 93 /* Remove a stone from the board */94 95 void96 gnugo_remove_stone(int i, int j)97 {98 remove_stone(POS(i, j));99 }100 101 /* Return true if (i,j) is PASS_MOVE */102 103 int104 gnugo_is_pass(int i, int j)105 {106 return is_pass(POS(i, j));107 }108 109 77 /* Play a move and start the clock */ 110 78 111 79 void … … 122 90 clock_push_button(color); 123 91 } 124 92 125 /* Undo n permanent moves. Returns 1 if successful and 0 if it fails.126 * If n moves cannot be undone, no move is undone.127 */128 129 int130 gnugo_undo_move(int n)131 {132 return undo_move(n);133 }134 135 93 136 94 /* 137 95 * Perform the moves and place the stones from the SGF node on the … … 149 107 case SGFAB: 150 108 /* A black stone. */ 151 109 get_moveXY(prop, &i, &j, board_size); 152 gnugo_add_stone(i, j, BLACK);110 add_stone(POS(i, j), BLACK); 153 111 break; 154 112 155 113 case SGFAW: 156 114 /* A white stone. */ 157 115 get_moveXY(prop, &i, &j, board_size); 158 gnugo_add_stone(i, j, WHITE);116 add_stone(POS(i, j), WHITE); 159 117 break; 160 118 161 119 case SGFPL: … … 202 160 switch (prop->name) { 203 161 case SGFAB: 204 162 get_moveXY(prop, &i, &j, board_size); 205 gnugo_add_stone(i, j, BLACK);163 add_stone(POS(i, j), BLACK); 206 164 break; 207 165 208 166 case SGFAW: 209 167 get_moveXY(prop, &i, &j, board_size); 210 gnugo_add_stone(i, j, WHITE);168 add_stone(POS(i, j), WHITE); 211 169 break; 212 170 213 171 case SGFPL: … … 238 196 } 239 197 240 198 241 /* Interface to is_legal(). */242 int243 gnugo_is_legal(int i, int j, int color)244 {245 return is_legal(POS(i, j), color);246 }247 248 249 /* Interface to is_suicide(). */250 int251 gnugo_is_suicide(int i, int j, int color)252 {253 return is_suicide(POS(i, j), color);254 }255 256 257 /* Interface to placehand. Sets up handicap stones and258 * returns the number of placed handicap stones. */259 int260 gnugo_placehand(int handicap)261 {262 return place_fixed_handicap(handicap);263 }264 265 266 /* Interface to sgffile_recordboard */267 void268 gnugo_recordboard(SGFNode *root)269 {270 sgffile_recordboard(root);271 }272 273 199 /* Interface to placehand. Sets up handicap stones and 274 200 * returns the number of placed handicap stones, updating the sgf file. 275 201 */ … … 332 258 } 333 259 334 260 335 /* Interface to who_wins */336 void337 gnugo_who_wins(int color, FILE *outfile)338 {339 who_wins(color, outfile);340 }341 342 343 261 /* Put upper and lower score estimates into *upper, *lower and 344 262 * return the average. A positive score favors white. In computing 345 263 * the upper bound, CRITICAL dragons are awarded to white; in … … 358 276 } 359 277 360 278 361 /* Accessor functions for internal board state. */362 363 /* Report the komi. */364 365 float366 gnugo_get_komi()367 {368 return komi;369 }370 371 /* Place the board into the b array */372 373 void374 gnugo_get_board(int b[MAX_BOARD][MAX_BOARD])375 {376 int i, j;377 for (i = 0; i < board_size; i++)378 for (j = 0; j < board_size; j++)379 b[i][j] = BOARD(i, j);380 }381 382 int383 gnugo_get_boardsize()384 {385 return board_size;386 }387 388 int389 gnugo_get_move_number()390 {391 return movenum;392 }393 394 279 /* ================================================================ */ 395 280 /* Gameinfo */ 396 281 /* ================================================================ */ … … 401 286 */ 402 287 403 288 void 404 gameinfo_clear(Gameinfo *ginfo, int boardsize, float komi)289 gameinfo_clear(Gameinfo *ginfo, int boardsize, float new_komi) 405 290 { 406 291 ginfo->handicap = 0; 407 292 408 293 gnugo_clear_board(boardsize); 409 gnugo_set_komi(komi);294 komi = new_komi; 410 295 ginfo->to_move = BLACK; 411 296 sgftree_clear(&ginfo->game_record); 412 297 … … 450 335 { 451 336 int bsize; 452 337 int handicap; 453 float komi;454 338 455 339 if (!sgfGetIntProperty(head, "SZ", &bsize)) 456 340 bsize = 19; … … 458 342 komi = 5.5; 459 343 460 344 gnugo_clear_board(bsize); 461 gnugo_set_komi(komi);462 345 463 346 if (!sgfGetIntProperty(head, "HA", &handicap) || handicap < 0) 464 347 /* Handicap stones should appear as AW, AB properties in the sgf file. */ … … 505 388 const char *untilstr, int orientation) 506 389 { 507 390 int bs, handicap; 508 float komi;509 391 int next = BLACK; 510 392 511 393 int untilm = -1, untiln = -1; … … 520 402 if (!sgfGetIntProperty(tree->root, "SZ", &bs)) 521 403 bs = 19; 522 404 gnugo_clear_board(bs); 523 gnugo_set_komi(komi);524 405 525 406 /* Now we can safely parse the until string (which depends on board size). */ 526 407 if (untilstr) { … … 575 456 gprintf("Illegal SGF! attempt to add a stone at occupied point %m\n", 576 457 i, j); 577 458 else 578 gnugo_add_stone(i, j, BLACK);459 add_stone(POS(i, j), BLACK); 579 460 break; 580 461 581 462 case SGFAW: … … 585 466 gprintf("Illegal SGF! attempt to add a stone at occupied point %m\n", 586 467 i, j); 587 468 else 588 gnugo_add_stone(i, j, WHITE);469 add_stone(POS(i, j), WHITE); 589 470 break; 590 471 591 472 case SGFPL: -
interface/play_ascii.c
old new 444 444 level, chinese_rules); 445 445 sgfOverwritePropertyInt(sgftree.root, "HA", ginfo->handicap); 446 446 if (ginfo->handicap > 0) 447 gnugo_recordboard(sgftree.root);447 sgffile_recordboard(sgftree.root); 448 448 } 449 449 450 450 … … 513 513 return 0; 514 514 } 515 515 516 if (! gnugo_is_legal(i, j, gameinfo->to_move)) {516 if (!is_legal(POS(i, j), gameinfo->to_move)) { 517 517 printf("\nIllegal move: %s", command); 518 518 return 0; 519 519 } … … 592 592 if (gameinfo->handicap == 0) 593 593 gameinfo->to_move = BLACK; 594 594 else { 595 gameinfo->handicap = gnugo_placehand(gameinfo->handicap);595 gameinfo->handicap = place_fixed_handicap(gameinfo->handicap); 596 596 gameinfo->to_move = WHITE; 597 597 } 598 598 sgf_initialized = 0; … … 709 709 /* Init board. */ 710 710 gnugo_clear_board(sz); 711 711 /* In case max handicap changes on smaller board. */ 712 gameinfo->handicap = gnugo_placehand(gameinfo->handicap);712 gameinfo->handicap = place_fixed_handicap(gameinfo->handicap); 713 713 sgfOverwritePropertyInt(sgftree.root, "SZ", sz); 714 714 sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); 715 715 break; … … 732 732 gnugo_clear_board(board_size); 733 733 /* Place stones on board but don't record sgf 734 734 * in case we change more info. */ 735 gameinfo->handicap = gnugo_placehand(num);735 gameinfo->handicap = place_fixed_handicap(num); 736 736 printf("\nSet handicap to %d\n", gameinfo->handicap); 737 737 gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK); 738 738 break; … … 866 866 867 867 case UNDO: 868 868 case CMD_BACK: 869 if ( gnugo_undo_move(1)) {869 if (undo_move(1)) { 870 870 sgftreeAddComment(&sgftree, "undone"); 871 871 sgftreeBack(&sgftree); 872 872 gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); … … 1031 1031 int state = 0; 1032 1032 1033 1033 if (reason == 0) { /* Two passes, game is over. */ 1034 gnugo_who_wins(gameinfo->computer_player, stdout);1034 who_wins(gameinfo->computer_player, stdout); 1035 1035 printf("\nIf you disagree, we may count the game together.\n"); 1036 1036 1037 1037 sgftreeWriteResult(&sgftree, (white_score + black_score)/2.0, 1); … … 1166 1166 } 1167 1167 } 1168 1168 } 1169 gnugo_who_wins(gameinfo->computer_player, stdout);1169 who_wins(gameinfo->computer_player, stdout); 1170 1170 } 1171 1171 1172 1172 -
interface/play_gmp.c
old new 57 57 mycolor = 0; 58 58 59 59 sgftree_clear(&sgftree); 60 sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(), gnugo_get_komi());60 sgftreeCreateHeaderNode(&sgftree, board_size, komi); 61 61 62 62 ge = gmp_create(0, 1); 63 TRACE("board size=%d\n", gnugo_get_boardsize());63 TRACE("board size=%d\n", board_size); 64 64 65 65 /* 66 66 * The specification of the go modem protocol doesn't even discuss … … 68 68 * command line, keep it. Otherwise, its value will be 0.0 and we 69 69 * use 5.5 in an even game, 0.5 otherwise. 70 70 */ 71 if ( gnugo_get_komi()== 0.0) {71 if (komi == 0.0) { 72 72 if (gameinfo->handicap == 0) 73 gnugo_set_komi(5.5);73 komi = 5.5; 74 74 else 75 gnugo_set_komi(0.5);75 komi = 0.5; 76 76 } 77 77 78 78 if (!simplified) { … … 84 84 } 85 85 else { 86 86 gmp_startGame(ge, board_size, gameinfo->handicap, 87 gnugo_get_komi(), chinese_rules, mycolor, 1);87 komi, chinese_rules, mycolor, 1); 88 88 } 89 89 90 90 do { … … 105 105 gnugo_clear_board(gmp_size(ge)); 106 106 107 107 /* Let's pretend GMP knows about komi in case something will ever change. */ 108 gnugo_set_komi(gmp_komi(ge));108 komi = gmp_komi(ge); 109 109 110 110 #if ORACLE 111 111 if (metamachine && oracle_exists) 112 112 oracle_clear_board(gnugo_get_boardsize()); 113 113 #endif 114 114 115 sgfOverwritePropertyInt(sgftree.root, "SZ", gnugo_get_boardsize());115 sgfOverwritePropertyInt(sgftree.root, "SZ", board_size); 116 116 117 TRACE("size=%d, handicap=%d, komi=%f\n", gnugo_get_boardsize(),118 gameinfo->handicap, gnugo_get_komi());117 TRACE("size=%d, handicap=%d, komi=%f\n", board_size, 118 gameinfo->handicap, komi); 119 119 120 120 if (gameinfo->handicap) 121 121 to_move = WHITE; … … 132 132 } 133 133 134 134 gameinfo->computer_player = mycolor; 135 sgf_write_header(sgftree.root, 1, get_random_seed(), gnugo_get_komi(),135 sgf_write_header(sgftree.root, 1, get_random_seed(), komi, 136 136 level, chinese_rules); 137 137 gameinfo->handicap = gnugo_sethand(gameinfo->handicap, sgftree.root); 138 138 sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); … … 156 156 assert(j > 0); 157 157 158 158 for (k = 0; k < j; k++) { 159 if (! gnugo_undo_move(1)) {159 if (!undo_move(1)) { 160 160 fprintf(stderr, "GNU Go: play_gmp UNDO: can't undo %d moves\n", 161 161 j - k); 162 162 break; … … 190 190 gnugo_play_move(i, j, mycolor); 191 191 sgffile_add_debuginfo(sgftree.lastnode, move_value); 192 192 193 if ( gnugo_is_pass(i, j)) {193 if (is_pass(POS(i, j))) { 194 194 /* pass */ 195 195 sgftreeAddPlay(&sgftree, to_move, -1, -1); 196 196 gmp_sendPass(ge); -
interface/play_solo.c
old new 43 43 float move_value; 44 44 double t1, t2; 45 45 int save_moves = moves; 46 int boardsize = gnugo_get_boardsize();47 46 48 47 struct stats_data totalstats; 49 48 int total_owl_count = 0; … … 57 56 int n = 6 + 2*gg_rand()%5; 58 57 int i, j; 59 58 60 gnugo_set_komi(5.5);59 komi = 5.5; 61 60 62 61 sgftree_clear(&sgftree); 63 sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(), gnugo_get_komi());62 sgftreeCreateHeaderNode(&sgftree, board_size, komi); 64 63 sgf_write_header(sgftree.root, 1, get_random_seed(), 5.5, 65 64 level, chinese_rules); 66 65 67 66 /* Generate some random moves. */ 68 if (board size > 6) {67 if (board_size > 6) { 69 68 do { 70 69 do { 71 i = (gg_rand() % 4) + (gg_rand() % (board size - 4));72 j = (gg_rand() % 4) + (gg_rand() % (board size - 4));73 } while (! gnugo_is_legal(i, j, gameinfo->to_move));70 i = (gg_rand() % 4) + (gg_rand() % (board_size - 4)); 71 j = (gg_rand() % 4) + (gg_rand() % (board_size - 4)); 72 } while (!is_legal(POS(i, j), gameinfo->to_move)); 74 73 75 74 gnugo_play_move(i, j, gameinfo->to_move); 76 75 sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); … … 111 110 t2 = gg_cputime(); 112 111 113 112 /* Two passes and it's over. (EMPTY == BOTH) */ 114 gnugo_who_wins(EMPTY, stdout);113 who_wins(EMPTY, stdout); 115 114 116 115 { 117 116 float score = gnugo_estimate_score(NULL, NULL); -
interface/play_test.c
old new 124 124 SGFProperty *move_prop = NULL; /* remember if we see a move property */ 125 125 int color; /* color of move to be made at this node. */ 126 126 127 int boardsize = gnugo_get_boardsize();128 127 int m, n; /* Move from file. */ 129 128 int i, j; /* Move generated by GNU Go. */ 130 129 … … 138 137 switch (sgf_prop->name) { 139 138 case SGFAB: 140 139 /* add black */ 141 gnugo_add_stone(get_moveX(sgf_prop, boardsize), 142 get_moveY(sgf_prop, boardsize), BLACK); 140 add_stone(POS(get_moveX(sgf_prop, board_size), 141 get_moveY(sgf_prop, board_size)), 142 BLACK); 143 143 break; 144 144 case SGFAW: 145 145 /* add white */ 146 gnugo_add_stone(get_moveX(sgf_prop, boardsize), 147 get_moveY(sgf_prop, boardsize), WHITE); 146 add_stone(POS(get_moveX(sgf_prop, board_size), 147 get_moveY(sgf_prop, board_size)), 148 WHITE); 148 149 break; 149 150 case SGFB: 150 151 case SGFW: … … 157 158 if (!move_prop) 158 159 return; 159 160 160 m = get_moveX(move_prop, board size);161 n = get_moveY(move_prop, board size);161 m = get_moveX(move_prop, board_size); 162 n = get_moveY(move_prop, board_size); 162 163 color = (move_prop->name == SGFW) ? WHITE : BLACK; 163 164 164 165 if (color == color_to_replay || color_to_replay == GRAY) { … … 173 174 printf("GNU Go resigns "); 174 175 else { 175 176 mprintf("GNU Go plays %m ", i, j); 176 if (! gnugo_is_pass(i, j))177 if (!is_pass(POS(i, j))) 177 178 printf("(%.2f) ", potential_moves[POS(i, j)]); 178 179 } 179 180 mprintf("- Game move %m ", m, n); 180 if (! gnugo_is_pass(m, n) && potential_moves[POS(m, n)] > 0.0)181 if (!is_pass(POS(m, n)) && potential_moves[POS(m, n)] > 0.0) 181 182 printf("(%.2f) ", potential_moves[POS(m, n)]); 182 183 printf("\n"); 183 184 … … 190 191 if (resign) 191 192 gg_snprintf(buf, 127, "GNU Go resigns - Game move %s (%.2f)", 192 193 location_to_string(POS(m, n)), 193 gnugo_is_pass(m, n)194 is_pass(POS(m, n)) 194 195 && potential_moves[POS(m, n)] < 0.0 ? 195 196 0 : potential_moves[POS(m, n)]); 196 197 else { 197 198 gg_snprintf(buf, 127, "GNU Go plays %s (%.2f) - Game move %s (%.2f)", 198 199 location_to_string(POS(i, j)), 199 gnugo_is_pass(i, j) ? 0 : potential_moves[POS(i, j)],200 is_pass(POS(i, j)) ? 0 : potential_moves[POS(i, j)], 200 201 location_to_string(POS(m, n)), 201 gnugo_is_pass(m, n)202 is_pass(POS(m, n)) 202 203 && potential_moves[POS(m, n)] < 0.0 ? 203 204 0 : potential_moves[POS(m, n)]); 204 205 sgfCircle(node, i, j); … … 207 208 else 208 209 gg_snprintf(buf, 127, "GNU Go plays the same move %s (%.2f)", 209 210 location_to_string(POS(i, j)), 210 gnugo_is_pass(i, j) ? 0 : potential_moves[POS(i, j)]);211 is_pass(POS(i, j)) ? 0 : potential_moves[POS(i, j)]); 211 212 sgfAddComment(node, buf); 212 213 sgffile_add_debuginfo(node, 0.0); 213 214 }
