backtracking: consider striking at 8 clues

This commit is contained in:
Maximilian Keßler 2024-02-01 22:26:08 +01:00
parent 863baf3acd
commit 47d59464cd
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -215,6 +215,7 @@ namespace Hanabi
}
} else {
_num_strikes++;
assert(_num_strikes <= max_num_strikes);
_num_copies_left[played_card]--;
}
@ -646,6 +647,7 @@ namespace Hanabi
// If we misplayed, then we lost the card and have to regain it now
_num_copies_left[last_action.discarded]++;
_num_strikes--;
assert(_num_strikes >= 0);
}
CHECK_DRAW_PILE_INTEGRITY;
}
@ -1033,8 +1035,9 @@ namespace Hanabi
}
// Check for discards now
if (_pace > 0 and _num_clues < max_num_clues)
if (_pace > 0 and (_num_clues < max_num_clues or _num_strikes < max_num_strikes))
{
bool const play_card_instead_of_discarding = _num_clues == max_num_clues;
// This will hold the index of trash to discard
std::uint8_t const invalid_index = std::numeric_limits<std::uint8_t>::max();
std::uint8_t discard_index = invalid_index;
@ -1068,7 +1071,7 @@ namespace Hanabi
// Discard if we found trash now
if (discard_index != invalid_index) {
probability_t const probability_discard = check_play_or_discard(discard_index, false);
probability_t const probability_discard = check_play_or_discard(discard_index, play_card_instead_of_discarding);
best_probability = std::max(best_probability, probability_discard);
if (best_probability == 1)
@ -1081,7 +1084,7 @@ namespace Hanabi
// sacrifice cards in hand
for(hand_index_t index = 0; index < hand_size; ++index) {
if(!is_critical(hand[index])) {
probability_t const probability_sacrifice = check_play_or_discard(index, false);
probability_t const probability_sacrifice = check_play_or_discard(index, play_card_instead_of_discarding);
best_probability = std::max(best_probability, probability_sacrifice);
if (best_probability == 1)
@ -1176,7 +1179,8 @@ namespace Hanabi
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
std::uint64_t HanabiState<num_suits, num_players, hand_size>::unique_id() const
{
unsigned long id = 0;
// Encode strikes first, since they will often be zero.
unsigned long id = _num_strikes;
// encode all positions of cards that started in draw pile
ASSERT(_relative_representation.card_positions_draw.size() == _relative_representation.good_cards_draw.size());
@ -1259,6 +1263,9 @@ namespace Hanabi
std::vector<std::uint64_t> ret;
std::vector<Card> cards;
// encode strikes first
ret.push_back(_num_strikes);
// encode all positions of cards that started in draw pile
ASSERT(_relative_representation.card_positions_draw.size() == _relative_representation.good_cards_draw.size());
for (size_t i = 0; i < _relative_representation.card_positions_draw.size(); i++)