void sgf_trace(const char *func, int str, int move, int result, const char *message) { char buf[100]; sprintf(buf, "%s %c%d: ", func, J(str) + 'A' + (J(str) >= 8), board_size - I(str)); if (result == 0) sprintf(buf + strlen(buf), "0"); else if (ON_BOARD(move)) sprintf(buf + strlen(buf), "%s %c%d", result_to_string(result), J(move) + 'A' + (J(move) >= 8), board_size - I(move)); else if (is_pass(move)) sprintf(buf + strlen(buf), "%s PASS", result_to_string(result)); else sprintf(buf + strlen(buf), "%s [%d]", result_to_string(result), move); if (message) sprintf(buf + strlen(buf), " (%s)", message); sgftreeAddComment(sgf_dumptree, buf); }
/* Prints out all relevant information for a cache entry, and prints * a board showing the active area. */ static void print_persistent_cache_entry(struct persistent_cache_entry *entry) { int r; gprintf("%omovenum = %d\n", entry->movenum); gprintf("%oscore = %d\n", entry->score); gprintf("%ocost = %d\n", entry->cost); gprintf("%oroutine = %s\n", routine_id_to_string(entry->routine)); gprintf("%oapos = %1m\n", entry->apos); if (entry->bpos != NO_MOVE) gprintf("%obpos = %1m\n", entry->bpos); if (entry->cpos != NO_MOVE) gprintf("%ocpos = %1m\n", entry->cpos); gprintf("%oresult = %s\n", result_to_string(entry->result)); if (entry->result_certain != -1) gprintf("%oresult_certain = %d\n", entry->result_certain); if (entry->node_limit != -1) gprintf("%onode_limit = %d\n", entry->node_limit); if (entry->move != NO_MOVE) gprintf("%omove = %1m\n", entry->move); if (entry->move2 != NO_MOVE) gprintf("%omove2 = %1m\n", entry->move2); for (r = 0; r < MAX_CACHE_DEPTH; r++) { if (entry->stack[r] == 0) break; gprintf("%ostack[%d] = %C %1m\n", r, entry->move_color[r], entry->stack[r]); } draw_active_area(entry->board, entry->apos); }
int search_persistent_owl_cache(int routine, int apos, int bpos, int cpos, int *result, int *move, int *move2, int *certain) { int k; gg_assert(stackp == 0 || stackp == 1); for (k = 0; k < persistent_owl_cache_size; k++) { if (persistent_owl_cache[k].routine == routine && persistent_owl_cache[k].apos == apos && persistent_owl_cache[k].bpos == bpos && persistent_owl_cache[k].cpos == cpos && verify_stored_board(persistent_owl_cache[k].board)) { *result = persistent_owl_cache[k].result; if (move) *move = persistent_owl_cache[k].move; if (move2) *move2 = persistent_owl_cache[k].move2; if (certain) *certain = persistent_owl_cache[k].result_certain; TRACE_OWL_PERSISTENT_CACHE( "persistent owl cache hit: routine %s at %1m result %d\n", routine_to_string(routine), apos, bpos, cpos, result_to_string(persistent_owl_cache[k].result)); return 1; } } return 0; }
void decide_semeai(int apos, int bpos) { SGFTree tree; int resulta, resultb, move, result_certain; int color = board[apos]; if (color == EMPTY || board[bpos] != OTHER_COLOR(color)) { gprintf("gnugo: --decide-semeai called on invalid data\n"); return; } /* Prepare pattern matcher and reading code. */ reset_engine(); silent_examine_position(EXAMINE_DRAGONS_WITHOUT_OWL); gprintf("finished examine_position\n"); count_variations = 1; if (*outfilename) sgffile_begindump(&tree); gprintf("Analyzing semeai between %1m and %1m, %C moves first\n", apos, bpos, board[apos]); owl_analyze_semeai(apos, bpos, &resulta, &resultb, &move, &result_certain); gprintf("Semeai defense of %1m: result %s %1m\n", apos, result_to_string(resulta), move); gprintf("Semeai attack of %1m: result %s %1m\n", bpos, result_to_string(resultb), move); gprintf("%d nodes%s\n\n", count_variations, result_certain ? "" : ", uncertain result"); gprintf("Analyzing semeai between %1m and %1m, %C moves first\n", bpos, apos, board[bpos]); owl_analyze_semeai(bpos, apos, &resultb, &resulta, &move, &result_certain); gprintf("Semeai defense of %1m: result %s %1m\n", bpos, result_to_string(resultb), move); gprintf("Semeai attack of %1m: result %s %1m\n", apos, result_to_string(resulta), move); gprintf("%d nodes%s\n", count_variations, result_certain ? "" : ", uncertain result"); sgffile_enddump(outfilename); count_variations = 0; }
int main(int argc, char ** argv) { if(argc != 2) { std::cout << argv[0] << " <path to D2 binaries with terminating slash/backslash>" << std::endl; return 1; } std::string directory(argv[1]); std::cout << "Running check_revision tests:" << std::endl << std::endl; for(std::size_t i = 0; i < nil::countof(mpq_strings); i++) { ulong sum = 0; check_revision_result_type result = check_revision(formulas[i], mpq_strings[i], directory, sum); std::cout << "Key " << (i + 1) << " result: " << result_to_string(result) << ", checksum: " << std::hex << sum << std::endl; } std::cout << std::endl << "Running hash_d2key tests:" << std::endl << std::endl; for(std::size_t i = 0; i < nil::countof(keys); i++) { std::string hash, public_value; bool result = hash_d2key(keys[i], client_token, server_token, hash, public_value); std::cout << "Key " << (i + 1); if(result) { std::cout << ":" << std::endl; std::cout << "Hash: "; print_data(hash); std::cout << "Public value: "; print_data(public_value); } else std::cout << " is invalid" << std::endl; } std::cout << std::endl << "Running double_hash tests:" << std::endl << std::endl; for(std::size_t i = 0; i < nil::countof(passwords); i++) { std::string hash = double_hash(client_token, server_token, passwords[i]); std::cout << "Password " << (i + 1) << ": "; print_data(hash); } #ifdef NIL_WINDOWS //haha std::cin.get(); #endif return 0; }
void print_outcome(int player, int move, int result) { printf(COM2, "Player %d played: %s, Result: %s\n", player, move_to_string(move), result_to_string(result)); }
void semeai() { int semeai_results_first[MAX_DRAGONS][MAX_DRAGONS]; int semeai_results_second[MAX_DRAGONS][MAX_DRAGONS]; int semeai_move[MAX_DRAGONS][MAX_DRAGONS]; char semeai_certain[MAX_DRAGONS][MAX_DRAGONS]; int d1, d2; int k; int num_dragons = number_of_dragons; if (num_dragons > MAX_DRAGONS) { TRACE("Too many dragons!!! Might disregard some semeais."); num_dragons = MAX_DRAGONS; } for (d1 = 0; d1 < num_dragons; d1++) for (d2 = 0; d2 < num_dragons; d2++) { semeai_results_first[d1][d2] = -1; semeai_results_second[d1][d2] = -1; } for (d1 = 0; d1 < num_dragons; d1++) for (k = 0; k < dragon2[d1].neighbors; k++) { int apos = DRAGON(d1).origin; int bpos = DRAGON(dragon2[d1].adjacent[k]).origin; int result_certain; d2 = dragon[bpos].id; /* Look for semeais */ if (dragon[apos].color == dragon[bpos].color || (dragon[apos].status != DEAD && dragon[apos].status != CRITICAL) || (dragon[bpos].status != DEAD && dragon[bpos].status != CRITICAL)) continue; /* Ignore inessential worms or dragons */ if (worm[apos].inessential || DRAGON2(apos).safety == INESSENTIAL || worm[bpos].inessential || DRAGON2(bpos).safety == INESSENTIAL) continue; /* Sometimes the dragons are considered neighbors but are too * distant to constitute a proper semeai, e.g. in nngs4:650, P2 * vs. R3. Then the result of semeai reading may be meaningless * and can confuse the analysis. In order to avoid this we check * that the dragons either are directly adjacent or at least * have one common liberty. */ if (!close_enough_for_proper_semeai(apos, bpos)) continue; /* The array semeai_results_first[d1][d2] will contain the status * of d1 after the d1 d2 semeai, giving d1 the first move. * The array semeai_results_second[d1][d2] will contain the status * of d1 after the d1 d2 semeai, giving d2 the first move. */ DEBUG(DEBUG_SEMEAI, "Considering semeai between %1m and %1m\n", apos, bpos); owl_analyze_semeai(apos, bpos, &(semeai_results_first[d1][d2]), &(semeai_results_second[d1][d2]), &(semeai_move[d1][d2]), 1, &result_certain); DEBUG(DEBUG_SEMEAI, "results if %s moves first: %s %s, %1m%s\n", board[apos] == BLACK ? "black" : "white", result_to_string(semeai_results_first[d1][d2]), result_to_string(semeai_results_second[d1][d2]), semeai_move[d1][d2], result_certain ? "" : " (uncertain)"); semeai_certain[d1][d2] = result_certain; } /* Look for dragons which lose all their semeais outright. The * winners in those semeais are considered safe and further semeais * they are involved in are disregarded. See semeai:81-86 and * nicklas5:1211 for examples of where this is useful. * * Note: To handle multiple simultaneous semeais properly we would * have to make simultaneous semeai reading. Lacking that we can * only get rough guesses of the correct status of the involved * dragons. This code is not guaranteed to be correct in all * situations but should usually be an improvement. */ for (d1 = 0; d1 < num_dragons; d1++) { int involved_in_semeai = 0; int all_lost = 1; for (d2 = 0; d2 < num_dragons; d2++) { if (semeai_results_first[d1][d2] != -1) { involved_in_semeai = 1; if (semeai_results_first[d1][d2] != 0) { all_lost = 0; break; } } } if (involved_in_semeai && all_lost) { /* Leave the status changes to the main loop below. Here we just * remove the presumably irrelevant semeai results. */ for (d2 = 0; d2 < num_dragons; d2++) { if (semeai_results_first[d1][d2] == 0) { int d3; for (d3 = 0; d3 < num_dragons; d3++) { if (semeai_results_second[d3][d2] > 0) { semeai_results_first[d3][d2] = -1; semeai_results_second[d3][d2] = -1; semeai_results_first[d2][d3] = -1; semeai_results_second[d2][d3] = -1; } } } } } } for (d1 = 0; d1 < num_dragons; d1++) { int semeais_found = 0; int best_defense = 0; int best_attack = 0; int defense_move = PASS_MOVE; int attack_move = PASS_MOVE; int defense_certain = 0; int attack_certain = 0; int semeai_attack_target = NO_MOVE; int semeai_defense_target = NO_MOVE; for (d2 = 0; d2 < num_dragons; d2++) { if (semeai_results_first[d1][d2] == -1) continue; gg_assert(semeai_results_second[d1][d2] != -1); semeais_found++; if (best_defense < semeai_results_first[d1][d2] || (best_defense == semeai_results_first[d1][d2] && defense_certain < semeai_certain[d1][d2])) { best_defense = semeai_results_first[d1][d2]; defense_move = semeai_move[d1][d2]; defense_certain = semeai_certain[d1][d2]; semeai_defense_target = dragon2[d2].origin; } if (best_attack < semeai_results_second[d2][d1] || (best_attack == semeai_results_second[d2][d1] && attack_certain < semeai_certain[d2][d1])) { best_attack = semeai_results_second[d2][d1]; attack_move = semeai_move[d2][d1]; attack_certain = semeai_certain[d2][d1]; semeai_attack_target = dragon2[d2].origin; } } if (semeais_found) { dragon2[d1].semeais = semeais_found; if (best_defense != 0 && best_attack != 0) update_status(DRAGON(d1).origin, CRITICAL, CRITICAL); else if (best_attack == 0 && attack_certain) update_status(DRAGON(d1).origin, ALIVE, ALIVE); dragon2[d1].semeai_defense_point = defense_move; dragon2[d1].semeai_defense_certain = defense_certain; dragon2[d1].semeai_defense_target = semeai_defense_target; dragon2[d1].semeai_attack_point = attack_move; dragon2[d1].semeai_attack_certain = attack_certain; dragon2[d1].semeai_attack_target = semeai_attack_target; } } find_moves_to_make_seki(); }