rename function, rework backtrackaction
This commit is contained in:
parent
44db744ae3
commit
3be7378903
3 changed files with 26 additions and 24 deletions
41
game_state.h
41
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<unsigned long, probability_t> visited_states() const = 0;
|
||||
[[nodiscard]] virtual const std::unordered_map<unsigned long, probability_t>& 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<unsigned long, probability_t> visited_states() const final;
|
||||
[[nodiscard]] const std::unordered_map<unsigned long, probability_t>& 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<bool update_card_positions> unsigned long play_and_potentially_update(hand_index_t index);
|
||||
template<bool update_card_positions> unsigned long discard_and_potentially_update(hand_index_t index);
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ namespace Hanabi {
|
|||
return _array[card.suit][card.rank];
|
||||
};
|
||||
|
||||
BacktrackAction::BacktrackAction(
|
||||
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||
HanabiState<num_suits, num_players, hand_size>::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<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||
std::unordered_map<unsigned long, probability_t> HanabiState<num_suits, num_players, hand_size>::visited_states() const {
|
||||
const std::unordered_map<unsigned long, probability_t>& HanabiState<num_suits, num_players, hand_size>::position_tablebase() const {
|
||||
return _position_tablebase;
|
||||
}
|
||||
|
||||
|
|
4
main.cpp
4
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;
|
||||
|
|
Loading…
Reference in a new issue