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)

Remove some trivial functions from engine/interface.c

  • engine/gnugo.h

    old new  
    8585 
    8686 
    8787void 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); 
    9288void gnugo_play_move(int i, int j, int color); 
    93 int  gnugo_undo_move(int n); 
    9489int  gnugo_play_sgfnode(SGFNode *node, int to_move); 
    9590int  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); 
    9891 
    99 int  gnugo_placehand(int handicap); 
    10092int  gnugo_sethand(int handicap, SGFNode *root); 
    101 void gnugo_recordboard(SGFNode *node); 
    10293 
    10394float gnugo_genmove(int *i, int *j, int color, int *resign); 
    10495 
    10596int  gnugo_attack(int m, int n, int *i, int *j); 
    10697int  gnugo_find_defense(int m, int n, int *i, int *j); 
    10798 
    108 void  gnugo_who_wins(int color, FILE *outfile); 
    10999float 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); 
    115100 
    116101/* ================================================================ */ 
    117102/*                           Game handling                          */ 
  • engine/interface.c

    old new  
    7474#endif 
    7575} 
    7676 
    77 /* Set the komi */ 
    78  
    79 void 
    80 gnugo_set_komi(float new_komi) 
    81 { 
    82   komi = new_komi; 
    83 } 
    84  
    85 /* Place a stone on the board */ 
    86  
    87 void 
    88 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 void 
    96 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 int 
    104 gnugo_is_pass(int i, int j) 
    105 { 
    106   return is_pass(POS(i, j)); 
    107 } 
    108  
    10977/* Play a move and start the clock */ 
    11078 
    11179void 
     
    12290  clock_push_button(color); 
    12391} 
    12492 
    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 int 
    130 gnugo_undo_move(int n) 
    131 { 
    132   return undo_move(n); 
    133 } 
    134  
    13593 
    13694/* 
    13795 * Perform the moves and place the stones from the SGF node on the  
     
    149107    case SGFAB: 
    150108      /* A black stone. */ 
    151109      get_moveXY(prop, &i, &j, board_size); 
    152       gnugo_add_stone(i, j, BLACK); 
     110      add_stone(POS(i, j), BLACK); 
    153111      break; 
    154112 
    155113    case SGFAW: 
    156114      /* A white stone. */ 
    157115      get_moveXY(prop, &i, &j, board_size); 
    158       gnugo_add_stone(i, j, WHITE); 
     116      add_stone(POS(i, j), WHITE); 
    159117      break; 
    160118 
    161119    case SGFPL: 
     
    202160      switch (prop->name) { 
    203161      case SGFAB: 
    204162        get_moveXY(prop, &i, &j, board_size); 
    205         gnugo_add_stone(i, j, BLACK); 
     163        add_stone(POS(i, j), BLACK); 
    206164        break; 
    207165 
    208166      case SGFAW: 
    209167        get_moveXY(prop, &i, &j, board_size); 
    210         gnugo_add_stone(i, j, WHITE); 
     168        add_stone(POS(i, j), WHITE); 
    211169        break; 
    212170 
    213171      case SGFPL: 
     
    238196} 
    239197 
    240198 
    241 /* Interface to is_legal(). */ 
    242 int 
    243 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 int 
    251 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 and 
    258  * returns the number of placed handicap stones. */ 
    259 int 
    260 gnugo_placehand(int handicap) 
    261 { 
    262   return place_fixed_handicap(handicap); 
    263 } 
    264  
    265  
    266 /* Interface to sgffile_recordboard */ 
    267 void 
    268 gnugo_recordboard(SGFNode *root) 
    269 { 
    270   sgffile_recordboard(root); 
    271 } 
    272  
    273199/* Interface to placehand. Sets up handicap stones and 
    274200 * returns the number of placed handicap stones, updating the sgf file. 
    275201 */ 
     
    332258} 
    333259 
    334260 
    335 /* Interface to who_wins */ 
    336 void 
    337 gnugo_who_wins(int color, FILE *outfile) 
    338 { 
    339   who_wins(color, outfile); 
    340 } 
    341  
    342  
    343261/* Put upper and lower score estimates into *upper, *lower and 
    344262 * return the average. A positive score favors white. In computing 
    345263 * the upper bound, CRITICAL dragons are awarded to white; in 
     
    358276} 
    359277 
    360278 
    361 /* Accessor functions for internal board state. */ 
    362  
    363 /* Report the komi. */ 
    364  
    365 float 
    366 gnugo_get_komi() 
    367 { 
    368   return komi; 
    369 } 
    370  
    371 /* Place the board into the b array */ 
    372  
    373 void 
    374 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 int 
    383 gnugo_get_boardsize() 
    384 { 
    385   return board_size; 
    386 } 
    387  
    388 int 
    389 gnugo_get_move_number() 
    390 { 
    391   return movenum; 
    392 } 
    393  
    394279/* ================================================================ */ 
    395280/*                             Gameinfo                             */ 
    396281/* ================================================================ */ 
     
    401286 */ 
    402287 
    403288void 
    404 gameinfo_clear(Gameinfo *ginfo, int boardsize, float komi) 
     289gameinfo_clear(Gameinfo *ginfo, int boardsize, float new_komi) 
    405290{ 
    406291  ginfo->handicap = 0; 
    407292   
    408293  gnugo_clear_board(boardsize); 
    409   gnugo_set_komi(komi)
     294  komi = new_komi
    410295  ginfo->to_move = BLACK; 
    411296  sgftree_clear(&ginfo->game_record); 
    412297 
     
    450335{ 
    451336  int bsize; 
    452337  int handicap; 
    453   float komi; 
    454338   
    455339  if (!sgfGetIntProperty(head, "SZ", &bsize)) 
    456340    bsize = 19; 
     
    458342    komi = 5.5; 
    459343   
    460344  gnugo_clear_board(bsize); 
    461   gnugo_set_komi(komi); 
    462345   
    463346  if (!sgfGetIntProperty(head, "HA", &handicap) || handicap < 0) 
    464347    /* Handicap stones should appear as AW, AB properties in the sgf file. */ 
     
    505388                          const char *untilstr, int orientation) 
    506389{ 
    507390  int bs, handicap; 
    508   float komi; 
    509391  int next = BLACK; 
    510392   
    511393  int untilm = -1, untiln = -1; 
     
    520402  if (!sgfGetIntProperty(tree->root, "SZ", &bs)) 
    521403    bs = 19; 
    522404  gnugo_clear_board(bs); 
    523   gnugo_set_komi(komi); 
    524405 
    525406  /* Now we can safely parse the until string (which depends on board size). */ 
    526407  if (untilstr) { 
     
    575456          gprintf("Illegal SGF! attempt to add a stone at occupied point %m\n", 
    576457                  i, j); 
    577458        else 
    578           gnugo_add_stone(i, j, BLACK); 
     459          add_stone(POS(i, j), BLACK); 
    579460        break; 
    580461               
    581462      case SGFAW: 
     
    585466          gprintf("Illegal SGF! attempt to add a stone at occupied point %m\n", 
    586467                  i, j); 
    587468        else 
    588           gnugo_add_stone(i, j, WHITE); 
     469          add_stone(POS(i, j), WHITE); 
    589470        break; 
    590471               
    591472      case SGFPL: 
  • interface/play_ascii.c

    old new  
    444444                   level, chinese_rules); 
    445445  sgfOverwritePropertyInt(sgftree.root, "HA", ginfo->handicap); 
    446446  if (ginfo->handicap > 0) 
    447     gnugo_recordboard(sgftree.root); 
     447    sgffile_recordboard(sgftree.root); 
    448448} 
    449449 
    450450 
     
    513513    return 0; 
    514514  } 
    515515   
    516   if (!gnugo_is_legal(i, j, gameinfo->to_move)) { 
     516  if (!is_legal(POS(i, j), gameinfo->to_move)) { 
    517517    printf("\nIllegal move: %s", command); 
    518518    return 0; 
    519519  } 
     
    592592    if (gameinfo->handicap == 0) 
    593593      gameinfo->to_move = BLACK; 
    594594    else { 
    595       gameinfo->handicap = gnugo_placehand(gameinfo->handicap); 
     595      gameinfo->handicap = place_fixed_handicap(gameinfo->handicap); 
    596596      gameinfo->to_move = WHITE; 
    597597    } 
    598598    sgf_initialized = 0; 
     
    709709          /* Init board. */ 
    710710          gnugo_clear_board(sz); 
    711711          /* In case max handicap changes on smaller board. */ 
    712           gameinfo->handicap = gnugo_placehand(gameinfo->handicap); 
     712          gameinfo->handicap = place_fixed_handicap(gameinfo->handicap); 
    713713          sgfOverwritePropertyInt(sgftree.root, "SZ", sz); 
    714714          sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); 
    715715          break; 
     
    732732          gnugo_clear_board(board_size); 
    733733          /* Place stones on board but don't record sgf  
    734734           * in case we change more info. */ 
    735           gameinfo->handicap = gnugo_placehand(num); 
     735          gameinfo->handicap = place_fixed_handicap(num); 
    736736          printf("\nSet handicap to %d\n", gameinfo->handicap); 
    737737          gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK); 
    738738          break; 
     
    866866 
    867867        case UNDO: 
    868868        case CMD_BACK: 
    869           if (gnugo_undo_move(1)) { 
     869          if (undo_move(1)) { 
    870870            sgftreeAddComment(&sgftree, "undone"); 
    871871            sgftreeBack(&sgftree); 
    872872            gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); 
     
    10311031  int state = 0; 
    10321032 
    10331033  if (reason == 0) {            /* Two passes, game is over. */ 
    1034     gnugo_who_wins(gameinfo->computer_player, stdout); 
     1034    who_wins(gameinfo->computer_player, stdout); 
    10351035    printf("\nIf you disagree, we may count the game together.\n"); 
    10361036 
    10371037    sgftreeWriteResult(&sgftree, (white_score + black_score)/2.0, 1); 
     
    11661166      } 
    11671167    } 
    11681168  } 
    1169   gnugo_who_wins(gameinfo->computer_player, stdout); 
     1169  who_wins(gameinfo->computer_player, stdout); 
    11701170} 
    11711171 
    11721172 
  • interface/play_gmp.c

    old new  
    5757    mycolor = 0; 
    5858 
    5959  sgftree_clear(&sgftree); 
    60   sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(), gnugo_get_komi()); 
     60  sgftreeCreateHeaderNode(&sgftree, board_size, komi); 
    6161 
    6262  ge = gmp_create(0, 1); 
    63   TRACE("board size=%d\n", gnugo_get_boardsize()); 
     63  TRACE("board size=%d\n", board_size); 
    6464 
    6565  /*  
    6666   * The specification of the go modem protocol doesn't even discuss 
     
    6868   * command line, keep it. Otherwise, its value will be 0.0 and we 
    6969   * use 5.5 in an even game, 0.5 otherwise. 
    7070   */ 
    71   if (gnugo_get_komi() == 0.0) { 
     71  if (komi == 0.0) { 
    7272    if (gameinfo->handicap == 0) 
    73       gnugo_set_komi(5.5)
     73      komi = 5.5
    7474    else 
    75       gnugo_set_komi(0.5)
     75      komi = 0.5
    7676  } 
    7777 
    7878  if (!simplified) { 
     
    8484  } 
    8585  else { 
    8686    gmp_startGame(ge, board_size, gameinfo->handicap, 
    87                   gnugo_get_komi(), chinese_rules, mycolor, 1); 
     87                  komi, chinese_rules, mycolor, 1); 
    8888  } 
    8989 
    9090  do { 
     
    105105  gnugo_clear_board(gmp_size(ge)); 
    106106 
    107107  /* 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); 
    109109 
    110110#if ORACLE 
    111111  if (metamachine && oracle_exists) 
    112112    oracle_clear_board(gnugo_get_boardsize()); 
    113113#endif 
    114114 
    115   sgfOverwritePropertyInt(sgftree.root, "SZ", gnugo_get_boardsize()); 
     115  sgfOverwritePropertyInt(sgftree.root, "SZ", board_size); 
    116116 
    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); 
    119119 
    120120  if (gameinfo->handicap) 
    121121    to_move = WHITE; 
     
    132132  } 
    133133 
    134134  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
    136136                   level, chinese_rules); 
    137137  gameinfo->handicap = gnugo_sethand(gameinfo->handicap, sgftree.root); 
    138138  sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); 
     
    156156        assert(j > 0); 
    157157         
    158158        for (k = 0; k < j; k++) { 
    159           if (!gnugo_undo_move(1)) { 
     159          if (!undo_move(1)) { 
    160160            fprintf(stderr, "GNU Go: play_gmp UNDO: can't undo %d moves\n", 
    161161                    j - k); 
    162162            break; 
     
    190190      gnugo_play_move(i, j, mycolor); 
    191191      sgffile_add_debuginfo(sgftree.lastnode, move_value); 
    192192       
    193       if (gnugo_is_pass(i, j)) { 
     193      if (is_pass(POS(i, j))) { 
    194194        /* pass */ 
    195195        sgftreeAddPlay(&sgftree, to_move, -1, -1); 
    196196        gmp_sendPass(ge); 
  • interface/play_solo.c

    old new  
    4343  float move_value; 
    4444  double t1, t2; 
    4545  int save_moves = moves; 
    46   int boardsize = gnugo_get_boardsize(); 
    4746 
    4847  struct stats_data totalstats; 
    4948  int total_owl_count = 0; 
     
    5756  int n = 6 + 2*gg_rand()%5; 
    5857  int i, j; 
    5958 
    60   gnugo_set_komi(5.5)
     59  komi = 5.5
    6160 
    6261  sgftree_clear(&sgftree); 
    63   sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(), gnugo_get_komi()); 
     62  sgftreeCreateHeaderNode(&sgftree, board_size, komi); 
    6463  sgf_write_header(sgftree.root, 1, get_random_seed(), 5.5, 
    6564                   level, chinese_rules); 
    6665  
    6766  /* Generate some random moves. */ 
    68   if (boardsize > 6) { 
     67  if (board_size > 6) { 
    6968    do { 
    7069      do { 
    71         i = (gg_rand() % 4) + (gg_rand() % (boardsize - 4)); 
    72         j = (gg_rand() % 4) + (gg_rand() % (boardsize - 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)); 
    7473 
    7574      gnugo_play_move(i, j, gameinfo->to_move); 
    7675      sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); 
     
    111110  t2 = gg_cputime(); 
    112111   
    113112  /* Two passes and it's over. (EMPTY == BOTH) */ 
    114   gnugo_who_wins(EMPTY, stdout); 
     113  who_wins(EMPTY, stdout); 
    115114 
    116115  { 
    117116    float score = gnugo_estimate_score(NULL, NULL); 
  • interface/play_test.c

    old new  
    124124  SGFProperty *move_prop = NULL; /* remember if we see a move property */ 
    125125  int color; /* color of move to be made at this node. */ 
    126126   
    127   int boardsize = gnugo_get_boardsize(); 
    128127  int m, n; /* Move from file. */ 
    129128  int i, j; /* Move generated by GNU Go. */ 
    130129 
     
    138137    switch (sgf_prop->name) { 
    139138    case SGFAB: 
    140139      /* 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); 
    143143      break; 
    144144    case SGFAW: 
    145145      /* 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); 
    148149      break; 
    149150    case SGFB: 
    150151    case SGFW: 
     
    157158  if (!move_prop) 
    158159    return; 
    159160 
    160   m = get_moveX(move_prop, boardsize); 
    161   n = get_moveY(move_prop, boardsize); 
     161  m = get_moveX(move_prop, board_size); 
     162  n = get_moveY(move_prop, board_size); 
    162163  color = (move_prop->name == SGFW) ? WHITE : BLACK; 
    163164 
    164165  if (color == color_to_replay || color_to_replay == GRAY) { 
     
    173174        printf("GNU Go resigns "); 
    174175      else { 
    175176        mprintf("GNU Go plays %m ", i, j); 
    176         if (!gnugo_is_pass(i, j)) 
     177        if (!is_pass(POS(i, j))) 
    177178          printf("(%.2f) ", potential_moves[POS(i, j)]); 
    178179      } 
    179180      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) 
    181182        printf("(%.2f) ", potential_moves[POS(m, n)]); 
    182183      printf("\n"); 
    183184 
     
    190191      if (resign) 
    191192        gg_snprintf(buf, 127, "GNU Go resigns - Game move %s (%.2f)", 
    192193                    location_to_string(POS(m, n)), 
    193                     gnugo_is_pass(m, n
     194                    is_pass(POS(m, n)
    194195                    && potential_moves[POS(m, n)] < 0.0 ? 
    195196                        0 : potential_moves[POS(m, n)]); 
    196197      else {       
    197198        gg_snprintf(buf, 127, "GNU Go plays %s (%.2f) - Game move %s (%.2f)", 
    198199                    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)], 
    200201                    location_to_string(POS(m, n)), 
    201                     gnugo_is_pass(m, n
     202                    is_pass(POS(m, n)
    202203                    && potential_moves[POS(m, n)] < 0.0 ? 
    203204                        0 : potential_moves[POS(m, n)]); 
    204205        sgfCircle(node, i, j); 
     
    207208    else 
    208209      gg_snprintf(buf, 127, "GNU Go plays the same move %s (%.2f)", 
    209210                 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)]); 
    211212    sgfAddComment(node, buf); 
    212213    sgffile_add_debuginfo(node, 0.0); 
    213214  }