Index: doc/api.texi =================================================================== RCS file: /cvsroot/gnugo/gnugo/doc/api.texi,v retrieving revision 1.13 diff -u -r1.13 api.texi --- doc/api.texi 16 Apr 2004 16:21:46 -0000 1.13 +++ doc/api.texi 4 Nov 2004 15:33:33 -0000 @@ -277,7 +277,7 @@ Interface to placehand. Sets up handicap stones and returns the number of placed handicap stones, updating the sgf file @end quotation -@item @code{int gnugo_genmove(int *i, int *j, int color)} +@item @code{float gnugo_genmove(int *i, int *j, int color, int *resign)} @findex gnugo_genmove @quotation Interface to @code{genmove()}. Index: engine/aftermath.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/aftermath.c,v retrieving revision 1.49 diff -u -r1.49 aftermath.c --- engine/aftermath.c 28 Apr 2004 16:37:30 -0000 1.49 +++ engine/aftermath.c 4 Nov 2004 15:33:33 -0000 @@ -30,6 +30,30 @@ static SGFTree *aftermath_sgftree; +static int do_aftermath_genmove(int color, + int under_control[BOARDMAX], + int do_capture_dead_stones); + +/* External interface to do_aftermath_genmove(). + * + * If the suggested move turn out not to be allowed we just return + * pass. This is not ideal but also not a big deal. If + * do_aftermath_genmove() is ever redesigned that would be a good time + * to integrate allowed_moves. + */ + +int +aftermath_genmove(int color, int do_capture_dead_stones, + int allowed_moves[BOARDMAX]) +{ + int move = do_aftermath_genmove(color, NULL, do_capture_dead_stones); + if (move != PASS_MOVE && allowed_moves && !allowed_moves[move]) + move = PASS_MOVE; + + return move; +} + + /* Generate a move to definitely settle the position after the game * has been finished. The purpose of this is to robustly determine * life and death status and to distinguish between life in seki and @@ -96,10 +120,10 @@ * genmove_conservative(). For this function to be meaningful, the * genmove() call should return pass. */ -int -aftermath_genmove(int *aftermath_move, int color, - int under_control[BOARDMAX], - int do_capture_dead_stones) +static int +do_aftermath_genmove(int color, + int under_control[BOARDMAX], + int do_capture_dead_stones) { int k; int other = OTHER_COLOR(color); @@ -270,9 +294,8 @@ if (best_scoring_move != NO_MOVE && safe_move(best_scoring_move, color) == WIN) { - *aftermath_move = best_scoring_move; DEBUG(DEBUG_AFTERMATH, "Closing edge at %1m\n", best_scoring_move); - return 1; + return best_scoring_move; } /* Case 1. */ @@ -288,8 +311,7 @@ findlib(pos, 1, &lib); /* Make sure we don't play into a ko or a (proper) snapback. */ if (countstones(pos) > 1 || !is_self_atari(lib, color)) { - *aftermath_move = lib; - return 1; + return lib; } } } @@ -376,8 +398,7 @@ } } } - *aftermath_move = move; - return 1; + return move; } /* Case 5. @@ -610,9 +631,8 @@ if (!move_ok) score[move] = 0; else { - *aftermath_move = move; DEBUG(DEBUG_AFTERMATH, "Splitting eyespace at %1m\n", move); - return 1; + return move; } } } @@ -734,9 +754,8 @@ if (!self_atari_ok && !confirm_safety(move, color, NULL, NULL)) continue; - *aftermath_move = move; DEBUG(DEBUG_AFTERMATH, "Filling opponent liberty at %1m\n", move); - return 1; + return move; } } @@ -767,15 +786,14 @@ || DRAGON2(pos).safety == TACTICALLY_DEAD) && worm[pos].attack_codes[0] != 0 && !is_illegal_ko_capture(worm[pos].attack_points[0], color)) { - *aftermath_move = worm[pos].attack_points[0]; DEBUG(DEBUG_AFTERMATH, "Tactically attack %1m at %1m\n", - pos, *aftermath_move); - return 1; + pos, worm[pos].attack_points[0]); + return worm[pos].attack_points[0]; } } /* No move found. */ - return -1; + return PASS_MOVE; } /* This is a substitute for genmove_conservative() which only does @@ -785,16 +803,17 @@ * important not to miss the move. */ static int -reduced_genmove(int *move, int color) +reduced_genmove(int color) { - float val; + float value; int save_verbose; float upper_bound, lower_bound; float our_score; + int move; /* no move is found yet. */ - *move = NO_MOVE; - val = -1; + move = PASS_MOVE; + value = 0.0; /* Prepare pattern matcher and reading code. */ reset_engine(); @@ -844,19 +863,17 @@ gg_assert(stackp == 0); /* Review the move reasons and estimate move values. */ - if (review_move_reasons(move, &val, color, 0.0, our_score, NULL)) - TRACE("Move generation likes %1m with value %f\n", *move, val); + if (review_move_reasons(&move, &value, color, 0.0, our_score, NULL)) + TRACE("Move generation likes %1m with value %f\n", move, value); gg_assert(stackp == 0); /* If no move is found then pass. */ - if (val < 0.0) { + if (move == PASS_MOVE) TRACE("I pass.\n"); - *move = NO_MOVE; - } else - TRACE("reduced_genmove() recommends %1m with value %f\n", *move, val); + TRACE("reduced_genmove() recommends %1m with value %f\n", move, value); - return val; + return move; } /* Preliminary function for playing through the aftermath. */ @@ -877,15 +894,15 @@ while (pass < 2 && moves < board_size * board_size) { int reading_nodes = get_reading_node_counter(); int owl_nodes = get_owl_node_counter(); - int move_val = reduced_genmove(&move, color_to_play); - if (move_val < 0) { + move = reduced_genmove(color_to_play); + if (move == PASS_MOVE) { int save_verbose = verbose; if (verbose > 0) verbose--; - move_val = aftermath_genmove(&move, color_to_play, - (color_to_play == WHITE ? - a->white_control : a->black_control), - 0); + move = do_aftermath_genmove(color_to_play, + (color_to_play == WHITE ? + a->white_control : a->black_control), + 0); verbose = save_verbose; } play_move(move, color_to_play); Index: engine/fuseki.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/fuseki.c,v retrieving revision 1.23 diff -u -r1.23 fuseki.c --- engine/fuseki.c 3 Sep 2004 15:40:08 -0000 1.23 +++ engine/fuseki.c 4 Nov 2004 15:33:33 -0000 @@ -207,7 +207,7 @@ /* Announce move, but check for politeness first. */ static void -announce_move(int move, int val, int color) +announce_move(int move, int value, int color) { int i, j; /* This shouldn't happen. */ @@ -238,8 +238,8 @@ move = POS(board_size - 1 - j, board_size - 1 - i); } - if (set_minimum_move_value(move, val)) - TRACE("Fuseki Player suggests %1m with value %d\n", move, val); + if (set_minimum_move_value(move, value)) + TRACE("Fuseki Player suggests %1m with value %d\n", move, value); } Index: engine/genmove.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/genmove.c,v retrieving revision 1.95 diff -u -r1.95 genmove.c --- engine/genmove.c 16 Sep 2004 13:12:04 -0000 1.95 +++ engine/genmove.c 4 Nov 2004 15:33:33 -0000 @@ -37,8 +37,8 @@ #define NEEDS_UPDATE(x) (x != position_number ? (x = position_number, 1) : 0) static int get_level(int *level); -static int do_genmove(int *move, int color, float pure_threat_value, - int allowed_moves[BOARDMAX]); +static int do_genmove(int color, float pure_threat_value, + int allowed_moves[BOARDMAX], float *value, int *resign); /* Position numbers for which various examinations were last made. */ static int worms_examined = -1; @@ -220,33 +220,31 @@ /* - * Generate computer move for COLOR. + * Generate computer move for color. * - * Return the generated move in (*i, *j). + * Return the generated move. */ int -genmove(int *i, int *j, int color) +genmove(int color, float *value, int *resign) { - int move; - int retval; + int move = PASS_MOVE; + if (resign) + *resign = 0; #if ORACLE if (metamachine) { - retval = metamachine_genmove(i, j, color); + move = metamachine_genmove(color, value); gg_assert(stackp == 0); - if (*i != -1) - return 1; + if (move != PASS_MOVE) + return move; } #endif - retval = do_genmove(&move, color, 0.4, NULL); - gg_assert(retval < 0 || ON_BOARD1(move)); - - if (i) *i = I(move); - if (j) *j = J(move); + move = do_genmove(color, 0.4, NULL, value, resign); + gg_assert(move == PASS_MOVE || ON_BOARD(move)); - return retval; + return move; } @@ -256,32 +254,16 @@ */ int -genmove_conservative(int *i, int *j, int color) +genmove_conservative(int color, float *value) { - int move; - int retval; - - retval = do_genmove(&move, color, 0.0, NULL); - - if (i) *i = I(move); - if (j) *j = J(move); - - return retval; + return do_genmove(color, 0.0, NULL, value, NULL); } int -genmove_restricted(int *i, int *j, int color, int allowed_moves[BOARDMAX]) +genmove_restricted(int color, int allowed_moves[BOARDMAX]) { - int move; - int retval; - - retval = do_genmove(&move, color, 0.0, allowed_moves); - - if (i) *i = I(move); - if (j) *j = J(move); - - return retval; + return do_genmove(color, 0.0, allowed_moves, NULL, NULL); } /* This function collects move reasons can be generated immediately from @@ -309,24 +291,32 @@ */ static int -do_genmove(int *move, int color, float pure_threat_value, - int allowed_moves[BOARDMAX]) +do_genmove(int color, float pure_threat_value, + int allowed_moves[BOARDMAX], float *value, int *resign) { - float val; float upper_bound, lower_bound; float average_score, our_score; int save_verbose; int save_depth; + int move; + float dummy_value; + + if (!value) + value = &dummy_value; start_timer(0); clearstats(); + + /* Usually we would not recommend resignation. */ + if (resign) + *resign = 0; /* Prepare our table of moves considered. */ memset(potential_moves, 0, sizeof(potential_moves)); /* no move is found yet. */ - *move = NO_MOVE; - val = -1; + move = PASS_MOVE; + *value = 0.0; if (get_level(&level)) fprintf(stderr, "level = %d\n", level); @@ -345,9 +335,10 @@ if (play_mirror_go && (mirror_stones_limit < 0 || stones_on_board(WHITE | BLACK) <= mirror_stones_limit) - && find_mirror_move(move, color)) { - TRACE("genmove() recommends mirror move at %1m\n", *move); - return 1.0; + && find_mirror_move(&move, color)) { + TRACE("genmove() recommends mirror move at %1m\n", move); + *value = 1.0; + return move; } /* Find out information about the worms and dragons. */ @@ -442,9 +433,9 @@ gg_assert(stackp == 0); /* Review the move reasons and estimate move values. */ - if (review_move_reasons(move, &val, color, + if (review_move_reasons(&move, value, color, pure_threat_value, our_score, allowed_moves)) - TRACE("Move generation likes %1m with value %f\n", *move, val); + TRACE("Move generation likes %1m with value %f\n", move, *value); gg_assert(stackp == 0); time_report(1, "review move reasons", NO_MOVE, 1.0); @@ -452,28 +443,28 @@ * dragon dangerous and change its status from DEAD to * UNKNOWN. This may generate a move. */ - if (val < 0.4 * our_score && !doing_scoring && !limit_search) { + if (*value < 0.4 * our_score && !doing_scoring && !limit_search) { if (revise_thrashing_dragon(color, our_score, 15.0)) { shapes(color); if (!disable_endgame_patterns) endgame_shapes(color); - if (review_move_reasons(move, &val, color, pure_threat_value, our_score, - allowed_moves)) { + if (review_move_reasons(&move, value, color, pure_threat_value, + our_score, allowed_moves)) { TRACE("Upon reconsideration move generation likes %1m with value %f\n", - *move, val); + move, *value); } } time_report(1, "move reasons with revised thrashing status", NO_MOVE, 1.0); } /* If the move value is 6 or lower, we look for endgame patterns too. */ - if (val <= 6.0 && !disable_endgame_patterns && !limit_search) { + if (*value <= 6.0 && !disable_endgame_patterns && !limit_search) { endgame_shapes(color); endgame(color); gg_assert(stackp == 0); - if (review_move_reasons(move, &val, color, pure_threat_value, our_score, + if (review_move_reasons(&move, value, color, pure_threat_value, our_score, allowed_moves)) - TRACE("Move generation likes %1m with value %f\n", *move, val); + TRACE("Move generation likes %1m with value %f\n", move, *value); gg_assert(stackp == 0); time_report(1, "endgame", NO_MOVE, 1.0); } @@ -482,15 +473,15 @@ * status of the opponent group from DEAD to UNKNOWN, then * run shapes and endgame_shapes again. This may turn up a move. */ - if (val < 0.0) { + if (move == PASS_MOVE) { if (revise_thrashing_dragon(color, our_score, 0.0) || revise_semeai(color)) { shapes(color); endgame_shapes(color); - if (review_move_reasons(move, &val, color, pure_threat_value, our_score, - allowed_moves)) { + if (review_move_reasons(&move, value, color, pure_threat_value, + our_score, allowed_moves)) { TRACE("Upon reconsideration move generation likes %1m with value %f\n", - *move, val); + move, *value); } } time_report(1, "move reasons with revised semeai or thrashing status", @@ -500,13 +491,13 @@ /* If still no move, fill a remaining liberty. This should pick up * all missing dame points. */ - if (val < 0.0 - && fill_liberty(move, color) - && (!allowed_moves || allowed_moves[*move])) { - val = 1.0; - TRACE("Filling a liberty at %1m\n", *move); - record_top_move(*move, val); - move_considered(*move, val); + if (move == PASS_MOVE + && fill_liberty(&move, color) + && (!allowed_moves || allowed_moves[move])) { + *value = 1.0; + TRACE("Filling a liberty at %1m\n", move); + record_top_move(move, *value); + move_considered(move, *value); time_report(1, "fill liberty", NO_MOVE, 1.0); } @@ -514,50 +505,40 @@ * opponent stones, or if the opponent is trying to live inside * our territory and we are clearly ahead, generate an aftermath move. */ + if (move == PASS_MOVE && !doing_scoring) { + if (play_out_aftermath + || capture_all_dead + || (thrashing_dragon && our_score > 15.0)) + move = aftermath_genmove(color, 0, allowed_moves); + + /* If we're instructed to capture all dead opponent stones, generate + * a capturing move. + */ + if (move == PASS_MOVE && capture_all_dead) + move = aftermath_genmove(color, 1, allowed_moves); - if (val < 0.0 - && !doing_scoring - && (play_out_aftermath - || capture_all_dead - || (thrashing_dragon && our_score > 15.0)) - && aftermath_genmove(move, color, NULL, 0) > 0 - && (!allowed_moves || allowed_moves[*move])) { - ASSERT1(is_legal(*move, color), *move); - val = 1.0; - TRACE("Aftermath move at %1m\n", *move); - record_top_move(*move, val); - move_considered(*move, val); - time_report(1, "aftermath_genmove", NO_MOVE, 1.0); - } - - /* If we're instructed to capture all dead opponent stones, generate - * a capturing move. - */ - if (val < 0.0 - && !doing_scoring - && capture_all_dead - && aftermath_genmove(move, color, NULL, 1) > 0 - && (!allowed_moves || allowed_moves[*move])) { - ASSERT1(is_legal(*move, color), *move); - val = 1.0; - TRACE("Aftermath move at %1m\n", *move); - move_considered(*move, val); - time_report(1, "aftermath_genmove", NO_MOVE, 1.0); + if (move != PASS_MOVE) { + ASSERT1(is_legal(move, color), move); + *value = 1.0; + TRACE("Aftermath move at %1m\n", move); + record_top_move(move, *value); + move_considered(move, *value); + time_report(1, "aftermath_genmove", NO_MOVE, 1.0); + } } /* If no move is found then pass. */ - if (val < 0.0) { + if (move == PASS_MOVE) { TRACE("I pass.\n"); - *move = NO_MOVE; } else { - TRACE("genmove() recommends %1m with value %f\n", *move, val); + TRACE("genmove() recommends %1m with value %f\n", move, *value); /* Maybe time to resign... */ - if (resign_allowed && val < 10.0 && should_resign(color, our_score)) { + if (resign && resign_allowed + && *value < 10.0 && should_resign(color, our_score)) { TRACE("... though, genmove() thinks the position is hopeless\n"); - /* Signal resignation by negating the move value */ - val = -val; + *resign = 1; } } @@ -566,11 +547,11 @@ showstats(); if (showtime) { - double spent = time_report(0, "TIME to generate move at ", *move, 1.0); + double spent = time_report(0, "TIME to generate move at ", move, 1.0); total_time += spent; if (spent > slowest_time) { slowest_time = spent; - slowest_move = *move; + slowest_move = move; slowest_movenum = movenum + 1; } } @@ -582,7 +563,7 @@ gg_assert(test_gray_border() < 0); gg_assert(depth == save_depth); - return val; + return move; } @@ -593,12 +574,12 @@ */ void -move_considered(int move, float val) +move_considered(int move, float value) { int i = I(move); int j = J(move); - if (val > potential_moves[i][j]) { - potential_moves[i][j] = val; + if (value > potential_moves[i][j]) { + potential_moves[i][j] = value; } } Index: engine/gnugo.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v retrieving revision 1.113 diff -u -r1.113 gnugo.h --- engine/gnugo.h 24 Aug 2004 14:39:53 -0000 1.113 +++ engine/gnugo.h 4 Nov 2004 15:33:33 -0000 @@ -99,7 +99,7 @@ int gnugo_sethand(int handicap, SGFNode *root); void gnugo_recordboard(SGFNode *node); -int gnugo_genmove(int *i, int *j, int color); +float gnugo_genmove(int *i, int *j, int color, int *resign); int gnugo_attack(int m, int n, int *i, int *j); int gnugo_find_defense(int m, int n, int *i, int *j); @@ -351,8 +351,8 @@ void who_wins(int color, FILE *outfile); /* high-level routine to generate the best move for the given color */ -int genmove(int *i, int *j, int color); -int genmove_conservative(int *i, int *j, int color); +int genmove(int color, float *value, int *resign); +int genmove_conservative(int color, float *value); /* Play through the aftermath. */ float aftermath_compute_score(int color, float komi, SGFTree *tree); @@ -378,7 +378,7 @@ void report_pattern_profiling(void); /* sgffile.c */ -void sgffile_add_debuginfo(SGFNode *node, int value); +void sgffile_add_debuginfo(SGFNode *node, float value); void sgffile_output(SGFTree *tree); void sgffile_printsgf(int color_to_play, const char *filename); Index: engine/handicap.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/handicap.c,v retrieving revision 1.7 diff -u -r1.7 handicap.c --- engine/handicap.c 24 Jan 2004 04:04:56 -0000 1.7 +++ engine/handicap.c 4 Nov 2004 15:33:33 -0000 @@ -254,8 +254,9 @@ /* Call genmove_conservative() in order to prepare the engine for * an aftermath_genmove() call. We discard the genmove result. */ - genmove_conservative(NULL, NULL, BLACK); - if (aftermath_genmove(&move, BLACK, NULL, 0) > 0) { + genmove_conservative(BLACK, NULL); + move = aftermath_genmove(BLACK, 0, NULL); + if (move != PASS_MOVE) { add_stone(move, BLACK); remaining_handicap_stones--; } Index: engine/interface.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/interface.c,v retrieving revision 1.49 diff -u -r1.49 interface.c --- engine/interface.c 21 Aug 2004 08:21:20 -0000 1.49 +++ engine/interface.c 4 Nov 2004 15:33:33 -0000 @@ -286,10 +286,17 @@ /* Interface to genmove() */ -int -gnugo_genmove(int *i, int *j, int color) +float +gnugo_genmove(int *i, int *j, int color, int *resign) { - return genmove(i, j, color); + float value; + int move = genmove(color, &value, resign); + if (i && j) { + *i = I(move); + *j = J(move); + } + + return value; } /* Interface to attack() */ Index: engine/liberty.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v retrieving revision 1.228 diff -u -r1.228 liberty.h --- engine/liberty.h 11 Oct 2004 21:03:28 -0000 1.228 +++ engine/liberty.h 4 Nov 2004 15:33:33 -0000 @@ -483,14 +483,13 @@ int atari_atari_blunder_size(int color, int tpos, char defense_moves[BOARDMAX], const char safe_stones[BOARDMAX]); -int review_move_reasons(int *move, float *val, int color, +int review_move_reasons(int *move, float *value, int color, float pure_threat_value, float our_score, int allowed_moves[BOARDMAX]); void prepare_move_influence_debugging(int pos, int color); int fill_liberty(int *move, int color); -int aftermath_genmove(int *aftermath_move, int color, - int under_control[BOARDMAX], - int do_capture_dead_stones); +int aftermath_genmove(int color, int do_capture_dead_stones, + int allowed_moves[BOARDMAX]); enum dragon_status aftermath_final_status(int color, int pos); int owl_attack(int target, int *attack_point, int *certain, int *kworm); @@ -520,10 +519,10 @@ void oracle_loadsgf(char *infilename, char *untilstring); int oracle_threatens(int move, int target); int within_search_area(int pos); -int metamachine_genmove(int *i, int *j, int color); +int metamachine_genmove(int color, float *value); void draw_search_area(void); -int genmove_restricted(int *i, int *j, int color, int allowed_moves[BOARDMAX]); +int genmove_restricted(int color, int allowed_moves[BOARDMAX]); void change_attack(int str, int move, int acode); void change_defense(int str, int move, int dcode); Index: engine/oracle.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/oracle.c,v retrieving revision 1.14 diff -u -r1.14 oracle.c --- engine/oracle.c 12 Apr 2004 15:22:30 -0000 1.14 +++ engine/oracle.c 4 Nov 2004 15:33:33 -0000 @@ -338,13 +338,13 @@ #define FIRST_LEVEL_MOVES 3 #define SECOND_LEVEL_MOVES 2 -static float -do_metamachine_genmove(int *i, int *j, int color, int width); +static int +do_metamachine_genmove(int color, int width, float *value); int -metamachine_genmove(int *i, int *j, int color) +metamachine_genmove(int color, float *value) { - float value; + int move; int pos; if (limit_search) { @@ -360,34 +360,34 @@ } } count_variations = 1; - value = do_metamachine_genmove(i, j, color, search_width()); + move = do_metamachine_genmove(color, search_width(), value); sgffile_enddump(outfilename); count_variations = 0; - return value; + return move; } -static float -do_metamachine_genmove(int *i, int *j, int color, int width) +static int +do_metamachine_genmove(int color, int width, float *value) { int k, moves_considered; float move_value[10]; float best_score = 0.; int best_move = -1; char *token; - int move_i[10], move_j[10]; + int moves[10]; float score[10]; char delimiters[] = " \t\r\n"; char buf[100]; + int i, j; - if (color == BLACK) + if (color == BLACK) TELL_ORACLE("top_moves_black\n"); else TELL_ORACLE("top_moves_white\n"); ask_oracle(); token = strtok(gnugo_line, delimiters); for (k = 0; k < 10; k++) { - move_i[k] = -1; - move_j[k] = -1; + moves[k] = PASS_MOVE; move_value[k] = 0.0; } moves_considered = width; @@ -397,39 +397,36 @@ token = strtok(NULL, delimiters); if (!token) break; - string_to_location(board_size, token, move_i+k, move_j+k); + string_to_location(board_size, token, &i, &j); + moves[k] = POS(i, j); token = strtok(NULL, delimiters); if (!token) break; - sscanf(token, "%f", move_value+k); - TRACE("move %d: %m valued %f\n", k, - move_i[k], move_j[k], move_value[k]); + sscanf(token, "%f", move_value + k); + TRACE("move %d: %1m valued %f\n", k, moves[k], move_value[k]); } /* if we left the loop early, k is the number of valid moves */ moves_considered = k; if (moves_considered == 0) { - *i = -1; - *j = -1; - return 0; + *value = 0.0; + return PASS_MOVE; } if (moves_considered == 1) { - *i = move_i[0]; - *j = move_j[0]; - return 1; + *value = 1.0; + return moves[k]; } for (k = 0; k < moves_considered; k++) { - if (oracle_trymove(POS(move_i[k], move_j[k]), color, "", 0, 0, NO_MOVE)) { + if (oracle_trymove(moves[k], color, "", 0, 0, NO_MOVE)) { int new_width = search_width(); if (new_width == 0) { TELL_ORACLE("experimental_score %s\n", color == BLACK ? "black" : "white"); ask_oracle(); - sscanf(gnugo_line, "= %f", score+k); + sscanf(gnugo_line, "= %f", score + k); } else { - score[k] = - do_metamachine_genmove(i, j, OTHER_COLOR(color), new_width); + do_metamachine_genmove(OTHER_COLOR(color), new_width, &score[k]); } if (verbose) dump_stack(); @@ -446,10 +443,9 @@ best_score = score[k]; } } - TRACE("best: %f at %2m\n", best_score, move_i[best_move], move_j[best_move]); - *i = move_i[best_move]; - *j = move_j[best_move]; - return score[best_move]; + TRACE("best: %f at %1m\n", best_score, moves[best_move]); + *value = score[best_move]; + return moves[best_move]; } /* decide how wide to search */ Index: engine/sgffile.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/sgffile.c,v retrieving revision 1.31 diff -u -r1.31 sgffile.c --- engine/sgffile.c 29 Apr 2004 23:56:01 -0000 1.31 +++ engine/sgffile.c 4 Nov 2004 15:33:33 -0000 @@ -47,7 +47,7 @@ */ void -sgffile_add_debuginfo(SGFNode *node, int value) +sgffile_add_debuginfo(SGFNode *node, float value) { int m, n; char comment[24]; @@ -79,7 +79,7 @@ } if (value > 0 && (output_flags & OUTPUT_MOVEVALUES)) { - sprintf(comment, "Value of move: %d", value); + sprintf(comment, "Value of move: %.2f", value); sgfAddComment(node, comment); } } Index: engine/value_moves.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/value_moves.c,v retrieving revision 1.133 diff -u -r1.133 value_moves.c --- engine/value_moves.c 26 Oct 2004 22:08:22 -0000 1.133 +++ engine/value_moves.c 4 Nov 2004 15:33:33 -0000 @@ -3527,33 +3527,33 @@ * for the best move. */ static int -find_best_move(int *the_move, float *val, int color, +find_best_move(int *the_move, float *value, int color, int allowed_moves[BOARDMAX]) { int good_move_found = 0; int ko_values_have_been_added = 0; char blunder_tested[BOARDMAX]; - float bestval = 0.0; + float best_value = 0.0; int best_move = NO_MOVE; int pos; memset(blunder_tested, 0, sizeof(blunder_tested)); while (!good_move_found) { - bestval = 0.0; + best_value = 0.0; best_move = NO_MOVE; /* Search through all board positions for the highest valued move. */ for (pos = BOARDMIN; pos < BOARDMAX; pos++) { - float tval = move[pos].final_value; + float this_value = move[pos].final_value; if (allowed_moves && !allowed_moves[pos]) continue; if (!ON_BOARD(pos) || move[pos].final_value == 0.0) continue; - if (tval > bestval) { + if (this_value > best_value) { if (is_legal(pos, color) || is_illegal_ko_capture(pos, color)) { - bestval = tval; + best_value = this_value; best_move = pos; } else { @@ -3568,9 +3568,9 @@ /* If the best move is an illegal ko capture, reevaluate ko * threats and search again. */ - if (bestval > 0.0 && is_illegal_ko_capture(best_move, color)) { + if (best_value > 0.0 && is_illegal_ko_capture(best_move, color)) { TRACE("Move at %1m would be an illegal ko capture.\n", best_move); - reevaluate_ko_threats(best_move, color, bestval); + reevaluate_ko_threats(best_move, color, best_value); redistribute_points(); time_report(2, " reevaluate_ko_threats", NO_MOVE, 1.0); ko_values_have_been_added = 1; @@ -3584,7 +3584,7 @@ * blunder. Otherwise devalue this move and scan through all move * values once more. */ - else if (bestval > 0.0) { + else if (best_value > 0.0) { if (!blunder_tested[best_move]) { float blunder_size = value_moves_get_blunder_size(best_move, color); if (blunder_size > 0.0) { @@ -3609,10 +3609,10 @@ good_move_found = 1; /* It's best to pass. */ } - if (bestval > 0.0 + if (best_value > 0.0 && best_move != NO_MOVE) { *the_move = best_move; - *val = bestval; + *value = best_value; return 1; } @@ -3632,7 +3632,7 @@ * NULL any move is allowed. */ int -review_move_reasons(int *the_move, float *val, int color, +review_move_reasons(int *the_move, float *value, int color, float pure_threat_value, float our_score, int allowed_moves[BOARDMAX]) { @@ -3684,7 +3684,7 @@ print_top_moves(); /* Select the highest valued move and return it. */ - return find_best_move(the_move, val, color, allowed_moves); + return find_best_move(the_move, value, color, allowed_moves); } Index: interface/play_ascii.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v retrieving revision 1.48 diff -u -r1.48 play_ascii.c --- interface/play_ascii.c 25 May 2004 03:13:47 -0000 1.48 +++ interface/play_ascii.c 4 Nov 2004 15:33:33 -0000 @@ -444,15 +444,16 @@ computer_move(Gameinfo *gameinfo, int *passes) { int i, j; - int move_val; + float move_value; + int resign; int resignation_declined = 0; float upper_bound, lower_bound; init_sgf(gameinfo); /* Generate computer move. */ - move_val = gnugo_genmove(&i, &j, gameinfo->to_move); - if (resignation_allowed && move_val < 0.0 && ON_BOARD2(i, j)) { + move_value = gnugo_genmove(&i, &j, gameinfo->to_move, &resign); + if (resignation_allowed && resign) { int state = ascii_endgame(gameinfo, 2); if (state != -1) return state; @@ -460,7 +461,6 @@ /* The opponent declined resignation. Remember not to resign again. */ resignation_allowed = 0; resignation_declined = 1; - move_val = -move_val; } if (showscore) { @@ -479,7 +479,7 @@ *passes = 0; gnugo_play_move(i, j, gameinfo->to_move); - sgffile_add_debuginfo(sgftree.lastnode, move_val); + sgffile_add_debuginfo(sgftree.lastnode, move_value); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); if (resignation_declined) sgftreeAddComment(&sgftree, "GNU Go resignation was declined"); @@ -513,7 +513,7 @@ TRACE("\nyour move: %m\n\n", i, j); init_sgf(gameinfo); gnugo_play_move(i, j, gameinfo->to_move); - sgffile_add_debuginfo(sgftree.lastnode, 0); + sgffile_add_debuginfo(sgftree.lastnode, 0.0); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); sgffile_output(&sgftree); @@ -547,7 +547,7 @@ (*passes)++; init_sgf(gameinfo); gnugo_play_move(-1, -1, gameinfo->to_move); - sgffile_add_debuginfo(sgftree.lastnode, 0); + sgffile_add_debuginfo(sgftree.lastnode, 0.0); sgftreeAddPlay(&sgftree, gameinfo->to_move, -1, -1); sgffile_output(&sgftree); Index: interface/play_gmp.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_gmp.c,v retrieving revision 1.27 diff -u -r1.27 play_gmp.c --- interface/play_gmp.c 24 Jan 2004 04:04:56 -0000 1.27 +++ interface/play_gmp.c 4 Nov 2004 15:33:33 -0000 @@ -45,7 +45,6 @@ const char *error; int i, j; - int moveval; int passes = 0; /* two passes and its over */ int to_move; /* who's turn is next ? */ @@ -142,7 +141,6 @@ while (passes < 2) { if (to_move == yourcolor) { - moveval = 0; /* Get opponent's move from gmp client. */ message = gmp_check(ge, 1, &j, &i, &error); @@ -188,11 +186,11 @@ } else { /* Generate my next move. */ - moveval = gnugo_genmove(&i, &j, mycolor); + float move_value = gnugo_genmove(&i, &j, mycolor, NULL); gnugo_play_move(i, j, mycolor); - sgffile_add_debuginfo(sgftree.lastnode, moveval); + sgffile_add_debuginfo(sgftree.lastnode, move_value); - if (moveval < 0) { + if (gnugo_is_pass(i, j)) { /* pass */ sgftreeAddPlay(&sgftree, to_move, -1, -1); gmp_sendPass(ge); @@ -205,7 +203,7 @@ passes = 0; TRACE("\nmy move: %m\n\n", i, j); } - sgffile_add_debuginfo(sgftree.lastnode, 0); + sgffile_add_debuginfo(sgftree.lastnode, 0.0); sgffile_output(&sgftree); } Index: interface/play_gtp.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v retrieving revision 1.154 diff -u -r1.154 play_gtp.c --- interface/play_gtp.c 11 Oct 2004 21:03:29 -0000 1.154 +++ interface/play_gtp.c 4 Nov 2004 15:33:33 -0000 @@ -2318,7 +2318,7 @@ sscanf(s + n, "%d", &minsize); - genmove(NULL, NULL, color); + genmove(color, NULL, NULL); get_saved_dragons(POS(i, j), saved_dragons); get_saved_worms(POS(i, j), saved_worms); @@ -2349,23 +2349,22 @@ static int gtp_genmove_black(char *s) { - int i, j; - float val; + int move; + int resign; UNUSED(s); if (stackp > 0) return gtp_failure("genmove cannot be called when stackp > 0"); - val = genmove(&i, &j, BLACK); + move = genmove(BLACK, NULL, &resign); - if (resign_allowed && val < 0.0 && ON_BOARD(POS(i, j))) { + if (resign) return gtp_success("resign"); - } - play_move(POS(i, j), BLACK); + play_move(move, BLACK); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2379,23 +2378,22 @@ static int gtp_genmove_white(char *s) { - int i, j; - float val; + int move; + int resign; UNUSED(s); if (stackp > 0) return gtp_failure("genmove cannot be called when stackp > 0"); - val = genmove(&i, &j, WHITE); + move = genmove(WHITE, NULL, &resign); - if (resign_allowed && val < 0.0 && ON_BOARD(POS(i, j))) { + if (resign) return gtp_success("resign"); - } - play_move(POS(i, j), WHITE); + play_move(move, WHITE); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2409,10 +2407,10 @@ static int gtp_genmove(char *s) { - int i, j; + int move; + int resign; int color; int n; - float val; n = gtp_decode_color(s, &color); if (!n) @@ -2423,17 +2421,16 @@ adjust_level_offset(color); level += level_offset; - val = genmove(&i, &j, color); + move = genmove(color, NULL, &resign); level -= level_offset; - if (resign_allowed && val < 0.0 && ON_BOARD(POS(i, j))) { + if (resign) return gtp_success("resign"); - } - play_move(POS(i, j), color); + play_move(move, color); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2448,7 +2445,7 @@ static int gtp_reg_genmove(char *s) { - int i, j; + int move; int color; int n; unsigned int saved_random_seed = get_random_seed(); @@ -2467,11 +2464,11 @@ */ set_random_seed(0); - genmove_conservative(&i, &j, color); + move = genmove_conservative(color, NULL); set_random_seed(saved_random_seed); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2485,7 +2482,7 @@ static int gtp_gg_genmove(char *s) { - int i, j; + int move; int color; int n; unsigned int saved_random_seed = get_random_seed(); @@ -2508,10 +2505,10 @@ sscanf(s+n, "%u", &seed); set_random_seed(seed); - genmove_conservative(&i, &j, color); + move = genmove_conservative(color, NULL); set_random_seed(saved_random_seed); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2525,6 +2522,7 @@ static int gtp_restricted_genmove(char *s) { + int move; int i, j; int color; int n; @@ -2564,10 +2562,10 @@ */ set_random_seed(0); - genmove_restricted(&i, &j, color, allowed_moves); + move = genmove_restricted(color, allowed_moves); set_random_seed(saved_random_seed); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2586,10 +2584,9 @@ static int gtp_kgs_genmove_cleanup(char *s) { - int i, j; + int move; int color; int n; - float val; int save_capture_all_dead = capture_all_dead; n = gtp_decode_color(s, &color); @@ -2606,15 +2603,15 @@ adjust_level_offset(color); level += level_offset; - val = genmove(&i, &j, color); + move = genmove(color, NULL, NULL); level -= level_offset; capture_all_dead = save_capture_all_dead; - play_move(POS(i, j), color); + play_move(move, color); gtp_start_response(GTP_SUCCESS); - gtp_print_vertex(i, j); + gtp_print_vertex(I(move), J(move)); return gtp_finish_response(); } @@ -2695,9 +2692,9 @@ static int gtp_top_moves_white(char *s) { - int i, j, k; + int k; UNUSED(s); - genmove(&i, &j, WHITE); + genmove(WHITE, NULL, NULL); gtp_start_response(GTP_SUCCESS); for (k = 0; k < 10; k++) if (best_move_values[k] > 0.0) { @@ -2716,9 +2713,9 @@ static int gtp_top_moves_black(char *s) { - int i, j, k; + int k; UNUSED(s); - genmove(&i, &j, BLACK); + genmove(BLACK, NULL, NULL); gtp_start_response(GTP_SUCCESS); for (k = 0; k < 10; k++) if (best_move_values[k] > 0.0) { @@ -3001,7 +2998,7 @@ static void finish_and_score_game(int seed) { - int move_val; + int move; int i, j; int next; int pass = 0; @@ -3042,9 +3039,9 @@ next = OTHER_COLOR(get_last_player()); do { - move_val = genmove_conservative(&i, &j, next); - play_move(POS(i, j), next); - if (move_val >= 0) { + move = genmove_conservative(next, NULL); + play_move(move, next); + if (move != PASS_MOVE) { pass = 0; moves++; } @@ -3318,7 +3315,7 @@ || (color != BLACK && color != WHITE)) return gtp_failure("invalid color"); - genmove_conservative(NULL, NULL, color); + genmove_conservative(color, NULL); estimate_score(&upper_bound, &lower_bound); if (debug & DEBUG_SCORING) Index: interface/play_solo.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_solo.c,v retrieving revision 1.33 diff -u -r1.33 play_solo.c --- interface/play_solo.c 27 May 2004 00:08:47 -0000 1.33 +++ interface/play_solo.c 4 Nov 2004 15:33:33 -0000 @@ -40,7 +40,7 @@ { SGFTree sgftree; int passes = 0; /* num. consecutive passes */ - int move_val; + float move_value; double t1, t2; int save_moves = moves; int boardsize = gnugo_get_boardsize(); @@ -83,15 +83,15 @@ memset(&totalstats, '\0', sizeof(totalstats)); while (passes < 2 && --moves >= 0) { reset_owl_node_counter(); - move_val = gnugo_genmove(&i, &j, gameinfo->to_move); + move_value = gnugo_genmove(&i, &j, gameinfo->to_move, NULL); gnugo_play_move(i, j, gameinfo->to_move); - sgffile_add_debuginfo(sgftree.lastnode, move_val); + sgffile_add_debuginfo(sgftree.lastnode, move_value); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); sgffile_output(&sgftree); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); - if (move_val < 0) { + if (POS(i, j) == PASS_MOVE) { ++passes; printf("%s(%d): Pass\n", gameinfo->to_move == BLACK ? "Black" : "White", movenum); @@ -145,7 +145,7 @@ SGFTree sgftree; int i, j; int next; - int move_val; + float move_value; next = gameinfo->to_move; sgftree = gameinfo->game_record; @@ -153,7 +153,7 @@ if (metamachine) sgffile_begindump(&sgftree); - move_val = gnugo_genmove(&i, &j, next); + move_value = gnugo_genmove(&i, &j, next, NULL); if (is_pass(POS(i, j))) gprintf("%s move: PASS!\n", next == WHITE ? "white (O)" : "black (X)"); @@ -166,7 +166,7 @@ gnugo_play_move(i, j, next); sgftreeAddPlay(&sgftree, next, i, j); sgftreeAddComment(&sgftree, "load and analyze mode"); - sgffile_add_debuginfo(sgftree.lastnode, move_val); + sgffile_add_debuginfo(sgftree.lastnode, move_value); sgffile_output(&sgftree); } } @@ -189,7 +189,8 @@ load_and_score_sgf_file(SGFTree *tree, Gameinfo *gameinfo, const char *scoringmode) { - int i, j, move_val; + int move; + float move_value; char *tempc = NULL; char text[250]; char winner; @@ -235,20 +236,20 @@ if (method != ESTIMATE) { doing_scoring = 1; while (pass < 2) { - move_val = genmove_conservative(&i, &j, next); - if (move_val >= 0) { + move = genmove_conservative(next, &move_value); + if (move != PASS_MOVE) { pass = 0; - gprintf("%d %s move %m\n", movenum, - next == WHITE ? "white (O)" : "black (X)", i, j); + gprintf("%d %s move %1m\n", movenum, + next == WHITE ? "white (O)" : "black (X)", move); } else { pass++; gprintf("%d %s move : PASS!\n", movenum, next == WHITE ? "white (O)" : "black (X)"); } - play_move(POS(i, j), next); - sgffile_add_debuginfo(score_tree->lastnode, move_val); - sgftreeAddPlay(score_tree, next, i, j); + play_move(move, next); + sgffile_add_debuginfo(score_tree->lastnode, move_value); + sgftreeAddPlay(score_tree, next, I(move), J(move)); sgffile_output(score_tree); next = OTHER_COLOR(next); } Index: interface/play_test.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_test.c,v retrieving revision 1.16 diff -u -r1.16 play_test.c --- interface/play_test.c 24 Jan 2004 04:04:56 -0000 1.16 +++ interface/play_test.c 4 Nov 2004 15:33:33 -0000 @@ -163,12 +163,13 @@ if (color == color_to_replay || color_to_replay == GRAY) { /* Get a move from the engine for color. */ - float move_val = gnugo_genmove(&i, &j, color); + int resign; + gnugo_genmove(&i, &j, color, &resign); /* Now report on how well the computer generated the move. */ if (i != m || j != n || !quiet) { mprintf("Move %d (%C): ", movenum + 1, color); - if (move_val < 0.0 && !gnugo_is_pass(i, j)) + if (resign) printf("GNU Go resigns "); else { mprintf("GNU Go plays %m ", i, j); @@ -186,7 +187,7 @@ } } if (i != m || j != n) { - if (move_val < 0.0 && !gnugo_is_pass(i, j)) + if (resign) gg_snprintf(buf, 127, "GNU Go resigns - Game move %s (%.2f)", location_to_string(POS(m, n)), gnugo_is_pass(m, n) @@ -208,7 +209,7 @@ location_to_string(POS(i, j)), gnugo_is_pass(i, j) ? 0 : potential_moves[i][j]); sgfAddComment(node, buf); - sgffile_add_debuginfo(node, 0); + sgffile_add_debuginfo(node, 0.0); } /* Finally, do play the move from the file. */