introduce function to select which states to save to map

This commit is contained in:
Maximilian Keßler 2024-02-08 11:10:00 +01:00
parent f0a496a8f0
commit 27922de8e8
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 18 additions and 1 deletions

View file

@ -226,6 +226,12 @@ namespace Hanabi
probability_t check_play_or_discard(hand_index_t index, bool play);
// For the current state, returns whether we will save it in the lookup table.
// By default, this is just constant true, but we might want to trade memory for speed, i.e.
// store less states, which will reduce memory consumption at the cost of re-computing some of the values
// when re-visiting the states.
bool save_state_to_map();
static constexpr uint8_t no_endgame = std::numeric_limits<uint8_t>::max();
// Usual game state
@ -260,6 +266,7 @@ namespace Hanabi
map_type<unsigned long, probability_t> _position_tablebase;
std::uint64_t _enumerated_states{};
};
template<std::size_t num_suits, player_t num_players, std::size_t hand_size>

View file

@ -982,6 +982,13 @@ namespace Hanabi
return _actions_log.top().action_type;
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
bool HanabiState<num_suits, num_players, hand_size>::save_state_to_map()
{
return true;
return _draw_pile.size() != 2;
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
probability_t HanabiState<num_suits, num_players, hand_size>::evaluate_state()
{
@ -1381,7 +1388,10 @@ namespace Hanabi
{
ASSERT(_position_tablebase[id] == probability);
}
_position_tablebase[id] = probability;
if (save_state_to_map())
{
_position_tablebase[id] = probability;
}
}
} // namespace Hanabi