diff --git a/game_state.h b/game_state.h index 1186547..2c0f366 100644 --- a/game_state.h +++ b/game_state.h @@ -173,7 +173,7 @@ struct BacktrackAction { class HanabiStateIF { public: - virtual probability_t backtrack(size_t depth) = 0; + virtual probability_t evaluate_state() = 0; virtual void clue() = 0; virtual void discard(hand_index_t index) = 0; @@ -203,7 +203,7 @@ public: HanabiState() = default; explicit HanabiState(const std::vector& deck); - probability_t backtrack(size_t depth) final; + probability_t evaluate_state() final; void clue() final; void play(hand_index_t index) final; diff --git a/game_state.hpp b/game_state.hpp index eec2c92..58a1baa 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -437,7 +437,7 @@ namespace Hanabi { template - probability_t HanabiState::backtrack(size_t depth) { + probability_t HanabiState::evaluate_state() { _enumerated_states++; const unsigned long id_of_state = unique_id(); @@ -462,7 +462,7 @@ namespace Hanabi { probability_t sum_of_probabilities = 0; do_for_each_potential_draw(index, [this, &sum_of_probabilities](const unsigned long multiplicity){ - sum_of_probabilities += backtrack(0) * multiplicity; + sum_of_probabilities += evaluate_state() * multiplicity; }); const unsigned long total_weight = std::max(static_cast(_weighted_draw_pile_size), 1ul); @@ -483,7 +483,7 @@ namespace Hanabi { probability_t sum_of_probabilities = 0; do_for_each_potential_draw(index, [this, &sum_of_probabilities](const unsigned long multiplicity){ - sum_of_probabilities += backtrack(0) * multiplicity; + sum_of_probabilities += evaluate_state() * multiplicity; }); const unsigned long total_weight = std::max(static_cast(_weighted_draw_pile_size), 1ul); @@ -505,7 +505,7 @@ namespace Hanabi { // Last option is to stall if(_num_clues > 0) { clue(); - const probability_t probability_stall = backtrack(depth + 1); + const probability_t probability_stall = evaluate_state(); revert_clue(); best_probability = std::max(best_probability, probability_stall); if (best_probability == 1) { diff --git a/main.cpp b/main.cpp index f17545f..8b8c316 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ namespace Hanabi { void download(std::variant game_id, int turn) { auto game = Download::get_game(game_id, turn); std::cout << "Analysing state: " << std::endl << *game << std::endl; - auto res = game->backtrack(1); + auto res = game->evaluate_state(); std::cout.precision(10); std::cout << std::endl; std::cout << "Probability with optimal play: " << res << std::endl; @@ -52,7 +52,7 @@ namespace Hanabi { void test() { { auto game = Download::get_game("in/1005195", 43); - auto res = game->backtrack(1); + auto res = game->evaluate_state(); CHECK("1005195", res == Hanabi::probability_t (7,8)); } } @@ -68,7 +68,7 @@ void check_games(unsigned num_players, unsigned max_draw_pile_size, unsigned fir for(size_t game_id = first_game; game_id <= last_game; game_id++) { const std::string input_fname = "json/" + std::to_string(num_players) + "p/" + std::to_string(game_id) + ".json"; auto game = Download::get_game(input_fname.c_str(), 50, draw_pile_size); - const Hanabi::probability_t chance = game->backtrack(0); + const Hanabi::probability_t chance = game->evaluate_state(); winning_percentages[game_id].push_back(chance); if(chance != 1) { file << "Game " << game_id << ": " << chance << std::endl;