Ticket #29: large_scale_statistics.diff

File large_scale_statistics.diff, 6.2 kB (added by arend, 3 years ago)

For reference: patch to collect statistics on large scale attack success depending on original number of owl attack reading notes

  • interface/play_gtp.c

     
    455455  if (stones_on_board(BLACK | WHITE) > 0) 
    456456    update_random_seed(); 
    457457 
    458   board_size = boardsize; 
    459   clear_board(); 
     458  gnugo_clear_board(boardsize); 
    460459  gtp_internal_set_boardsize(boardsize); 
    461460  reset_engine(); 
    462461  return gtp_success(""); 
     
    497496  if (stones_on_board(BLACK | WHITE) > 0) 
    498497    update_random_seed(); 
    499498 
    500   clear_board(); 
    501   init_timers(); 
     499  gnugo_clear_board(board_size); 
    502500   
    503501  return gtp_success(""); 
    504502} 
  • engine/value_moves.c

     
    384384  verbose = save_verbose; 
    385385} 
    386386 
     387static int small_successes[11]; 
     388static int small_failures[11]; 
     389static int big_successes[11]; 
     390static int big_failures[11]; 
     391static int small_successes_node_count[11]; 
     392static int small_failures_node_count[11]; 
     393static int big_successes_node_count[11]; 
     394static int big_failures_node_count[11]; 
     395 
     396void 
     397clear_large_scale_statistics(void) 
     398{ 
     399  int i; 
     400  for (i = 0; i < 11; i++) { 
     401    small_successes[i] = 0; 
     402    small_failures[i] = 0; 
     403    big_successes[i] = 0; 
     404    big_failures[i] = 0; 
     405    small_successes_node_count[i] = 0; 
     406    small_failures_node_count[i] = 0; 
     407    big_successes_node_count[i] = 0; 
     408    big_failures_node_count[i] = 0; 
     409  } 
     410  fprintf(stderr, "Cleared large scale statistics.\n"); 
     411} 
     412 
     413static void 
     414report_large_scale_statistic(int data[11]) 
     415{ 
     416  int i, sum; 
     417  for (i = 0; i < 11; i++) 
     418    fprintf(stderr, "%6d ", data[i]); 
     419  fprintf(stderr, "\nCumulated: "); 
     420  sum = 0; 
     421  for (i = 0; i < 11; i++) { 
     422    sum += data[i]; 
     423    fprintf(stderr, "%6d ", sum); 
     424  } 
     425} 
     426 
     427void 
     428report_large_scale_statistics(void) 
     429{ 
     430  int i; 
     431  fprintf(stderr, "============================ Large scale statistics =============\nStatistics for close attacks (node limit = 350):\nnode count:"); 
     432  for (i = 0; i < 11; i++) 
     433    fprintf(stderr, "<=%4d ", i*100); 
     434  fprintf(stderr, "\nSuccesses: "); 
     435  report_large_scale_statistic(big_successes); 
     436  fprintf(stderr, "\nNodes:     "); 
     437  report_large_scale_statistic(big_successes_node_count); 
     438  fprintf(stderr, "\nFailures:  "); 
     439  report_large_scale_statistic(big_failures); 
     440  fprintf(stderr, "\nNodes:     "); 
     441  report_large_scale_statistic(big_failures_node_count); 
     442 
     443  fprintf(stderr, "\n\nStatistics for wide attacks (node limit = 150):\nnode count:"); 
     444  for (i = 0; i < 11; i++) 
     445    fprintf(stderr, "<=%4d ", i*100); 
     446  fprintf(stderr, "\nSuccesses: "); 
     447  report_large_scale_statistic(small_successes); 
     448  fprintf(stderr, "\nNodes:     "); 
     449  report_large_scale_statistic(small_successes_node_count); 
     450  fprintf(stderr, "\nFailures:  "); 
     451  report_large_scale_statistic(small_failures); 
     452  fprintf(stderr, "\nNodes:     "); 
     453  report_large_scale_statistic(small_failures_node_count); 
     454  fprintf(stderr, "\n============================ Large scale statistics =============\n"); 
     455} 
    387456 
    388457 
    389458/* Try whether the move at (pos) for (color) is also an owl attack on 
     
    400469  int acode; 
    401470  int save_verbose = verbose; 
    402471  int save_owl_node_limit = owl_node_limit; 
     472  int index = gg_min((DRAGON2(target).owl_attack_node_count * 10 ) / owl_node_limit, 10); 
    403473   
    404474  ASSERT1(board[target] == OTHER_COLOR(color), pos); 
    405475  ASSERT1(!owl_attack_move_reason_known(pos, target), pos); 
     
    430500  if (acode >= DRAGON2(target).owl_attack_code 
    431501      && acode == WIN) { 
    432502    add_owl_attack_move(pos, target, kworm, acode); 
     503    if (dist <=1 ) { 
     504      big_successes[index] += 1; 
     505      big_successes_node_count[index] += owl_nodes_used; 
     506    } 
     507    else { 
     508      small_successes[index] += 1; 
     509      small_successes_node_count[index] += owl_nodes_used; 
     510    } 
    433511    DEBUG(DEBUG_LARGE_SCALE | DEBUG_MOVE_REASONS, 
    434512          "Move at %1m owl-attacks %1m on a large scale(%s).\n",  
    435513          pos, target, result_to_string(acode)); 
    436514  } 
    437   else 
     515  else { 
     516    if (dist <=1 ) { 
     517      big_failures[index] += 1; 
     518      big_failures_node_count[index] += owl_nodes_used; 
     519    } 
     520    else { 
     521      small_failures[index] += 1; 
     522      small_failures_node_count[index] += owl_nodes_used; 
     523    } 
    438524    DEBUG(DEBUG_LARGE_SCALE, 
    439525          "Move at %1m isn't a clean large scale attack on %1m (%s).\n", 
    440526          pos, target, result_to_string(acode)); 
     527  } 
    441528   
    442529  DEBUG(DEBUG_LARGE_SCALE, "  owl nodes used = %d, dist = %d\n",  
    443530        owl_nodes_used, dist); 
  • engine/liberty.h

    only in patch2:
    unchanged:
     
    899899  int owl_attack_point;    /* vital point for attack                         */ 
    900900  int owl_attack_code;     /* ko result code                                 */ 
    901901  int owl_attack_certain;  /* 0 if owl reading node limit is reached         */ 
     902  int owl_attack_node_count; 
    902903  int owl_second_attack_point;/* if attacker gets both attack points, wins   */ 
    903904  int owl_defense_point;   /* vital point for defense                        */ 
    904905  int owl_defense_code;    /* ko result code                                 */ 
  • engine/interface.c

     
    5454 
    5555  clear_approxlib_cache(); 
    5656  clear_accuratelib_cache(); 
     57 
     58  clear_large_scale_statistics(); 
    5759} 
    5860 
    5961 
     
    6870  board_size = boardsize; 
    6971  clear_board(); 
    7072  init_timers(); 
     73  report_large_scale_statistics(); 
    7174#if 0 
    7275  if (metamachine && oracle_exists) 
    7376    oracle_clear_board(boardsize); 
  • engine/dragon.c

     
    222222        int acode = 0; 
    223223        int dcode = 0; 
    224224        int kworm = NO_MOVE; 
     225        int owl_nodes_before = get_owl_node_counter(); 
    225226        start_timer(3); 
    226227        acode = owl_attack(str, &attack_point,  
    227228                           &DRAGON2(str).owl_attack_certain, &kworm); 
     229        DRAGON2(str).owl_attack_node_count 
     230          = get_owl_node_counter() - owl_nodes_before; 
    228231        if (acode != 0) { 
    229232          DRAGON2(str).owl_attack_point = attack_point; 
    230233          DRAGON2(str).owl_attack_code = acode;