diff --git a/game_state.h b/game_state.h index 2c0f366..8f74732 100644 --- a/game_state.h +++ b/game_state.h @@ -145,24 +145,6 @@ enum class ActionType { vote_terminate = 10, }; -struct BacktrackAction { - explicit BacktrackAction( - ActionType action_type, - Card discarded_or_played = unknown_card, - hand_index_t index = 0, - bool was_on_8_clues = false - ); - - ActionType action_type{}; - // The card that was discarded or played - Card discarded{}; - // Index of card in hand that was discarded or played - hand_index_t index{}; - - // Indicates whether before the action was taken, we had 8 clues. - // This is important so that we know if we go back to 7 or 8 clues when we revert playing a 5 - bool was_on_8_clues {false}; -}; /** Would like to have 2 versions: * All: @@ -185,7 +167,7 @@ public: [[nodiscard]] virtual size_t draw_pile_size() const = 0; [[nodiscard]] virtual std::uint64_t enumerated_states() const = 0; - [[nodiscard]] virtual std::unordered_map visited_states() const = 0; + [[nodiscard]] virtual const std::unordered_map& position_tablebase() const = 0; virtual void normalize_draw_and_positions() = 0; @@ -219,7 +201,7 @@ public: [[nodiscard]] size_t draw_pile_size() const final; [[nodiscard]] std::uint64_t enumerated_states() const final; - [[nodiscard]] std::unordered_map visited_states() const final; + [[nodiscard]] const std::unordered_map& position_tablebase() const final; void normalize_draw_and_positions() final; @@ -229,6 +211,25 @@ protected: void print(std::ostream& os) const final; private: + struct BacktrackAction { + explicit BacktrackAction( + ActionType action_type, + Card discarded_or_played = unknown_card, + hand_index_t index = 0, + bool was_on_8_clues = false + ); + + ActionType action_type{}; + // The card that was discarded or played + Card discarded{}; + // Index of card in hand that was discarded or played + hand_index_t index{}; + + // Indicates whether before the action was taken, we had 8 clues. + // This is important so that we know if we go back to 7 or 8 clues when we revert playing a 5 + bool was_on_8_clues {false}; + }; + template unsigned long play_and_potentially_update(hand_index_t index); template unsigned long discard_and_potentially_update(hand_index_t index); diff --git a/game_state.hpp b/game_state.hpp index 58a1baa..2900649 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -61,7 +61,8 @@ namespace Hanabi { return _array[card.suit][card.rank]; }; - BacktrackAction::BacktrackAction( + template + HanabiState::BacktrackAction::BacktrackAction( Hanabi::ActionType action_type, Hanabi::Card discarded_or_played, Hanabi::hand_index_t index, bool was_on_8_clues ): @@ -606,7 +607,7 @@ namespace Hanabi { } template - std::unordered_map HanabiState::visited_states() const { + const std::unordered_map& HanabiState::position_tablebase() const { return _position_tablebase; } diff --git a/main.cpp b/main.cpp index 8b8c316..d7de691 100644 --- a/main.cpp +++ b/main.cpp @@ -22,9 +22,9 @@ namespace Hanabi { std::cout << std::endl; std::cout << "Probability with optimal play: " << res << std::endl; std::cout << "Enumerated " << game->enumerated_states() << " states" << std::endl; - std::cout << "Visited " << game->visited_states().size() << " unique game states. " << std::endl; + std::cout << "Visited " << game->position_tablebase().size() << " unique game states. " << std::endl; unsigned long biggest_key = 0; - for(const auto& [key, prob] : game->visited_states()) { + for(const auto& [key, prob] : game->position_tablebase()) { biggest_key = std::max(biggest_key, key); } std::cout << "Biggest key generated is " << biggest_key << std::endl;