fix clue count when playing 5s on 8 clues

This commit is contained in:
Maximilian Keßler 2023-08-06 17:34:07 +02:00
parent 6e71a6a457
commit 87ff267f80
Signed by: max
GPG Key ID: BCC5A619923C0BA5
3 changed files with 11 additions and 9 deletions

View File

@ -162,7 +162,7 @@ public:
void normalize_draw_and_positions();
void revert_clue();
void revert_play(const BacktrackAction &action);
void revert_play(const BacktrackAction &action, bool was_on_8_clues);
void revert_discard(const BacktrackAction &action);
uint8_t draw(uint8_t index);

View File

@ -128,7 +128,7 @@ namespace Hanabi {
BacktrackAction ret{_hands[_turn][index], index, 0};
if (card.rank == 0) {
if (card.rank == 0 and _num_clues < max_num_clues) {
// update clues if we played the last card of a stack
_num_clues++;
}
@ -301,9 +301,10 @@ namespace Hanabi {
}
template<std::size_t num_suits, player_t num_players, std::size_t hand_size>
void HanabiState<num_suits, num_players, hand_size>::revert_play(const BacktrackAction& action) {
void HanabiState<num_suits, num_players, hand_size>::revert_play(const BacktrackAction& action, bool was_on_8_clues) {
ASSERT(!was_on_8_clues or _num_clues == 8);
decr_turn();
if (action.discarded.rank == 0) {
if (action.discarded.rank == 0 and not was_on_8_clues) {
_num_clues--;
}
revert_draw(action.index, action.discarded);
@ -353,19 +354,20 @@ namespace Hanabi {
for(std::uint8_t index = 0; index < hand_size; index++) {
if(is_playable(hand[index])) {
if (_draw_pile.empty()) {
auto copy = *this;
bool on_8_clues = _num_clues == 8;
BacktrackAction action = play(index);
const double probability_for_this_play = backtrack(depth + 1);
revert_play(action);
revert_play(action, on_8_clues);
UPDATE_PROBABILITY(probability_for_this_play);
} else {
double sum_of_probabilities = 0;
uint8_t sum_of_mults = 0;
for (size_t i = 0; i < _draw_pile.size(); i++) {
bool on_8_clues = _num_clues == 8;
BacktrackAction action = play(index);
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
sum_of_mults += action.multiplicity;
revert_play(action);
revert_play(action, on_8_clues);
ASSERT(sum_of_mults <= _weighted_draw_pile_size);
}
ASSERT(sum_of_mults == _weighted_draw_pile_size);
@ -376,7 +378,7 @@ namespace Hanabi {
}
// Check for discards now
if(_pace > 0) {
if(_pace > 0 and _num_clues < max_num_clues) {
for(std::uint8_t index = 0; index < hand_size; index++) {
if (is_trash(hand[index])) {
double sum_of_probabilities = 0;

View File

@ -30,7 +30,7 @@ void test_game() {
auto a = state.play(4);
std::cout << state;
state.revert_play(a);
state.revert_play(a, false);
std::cout << state << std::endl;
std::cout << state2 << std::endl;