simplify play card logic: always consider bombs

This commit is contained in:
Maximilian Keßler 2023-08-11 12:12:09 +02:00
parent 3be7378903
commit a116ec45e3
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 10 additions and 9 deletions

View file

@ -143,12 +143,6 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size> template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
void HanabiState<num_suits, num_players, hand_size>::play(Hanabi::hand_index_t index) { void HanabiState<num_suits, num_players, hand_size>::play(Hanabi::hand_index_t index) {
const Card card = _hands[_turn][index];
if (!is_playable(card)) {
draw<false>(index);
incr_turn();
return;
}
play_and_potentially_update<false>(index); play_and_potentially_update<false>(index);
} }
@ -157,6 +151,11 @@ namespace Hanabi {
unsigned long HanabiState<num_suits, num_players, hand_size>::play_and_potentially_update(hand_index_t index) { unsigned long HanabiState<num_suits, num_players, hand_size>::play_and_potentially_update(hand_index_t index) {
ASSERT(index < _hands[_turn].size()); ASSERT(index < _hands[_turn].size());
const Card played_card = _hands[_turn][index]; const Card played_card = _hands[_turn][index];
if (!is_playable(played_card)) {
const unsigned long multiplicity = draw<false>(index);
incr_turn();
return multiplicity;
}
ASSERT(is_playable(played_card)); ASSERT(is_playable(played_card));
_actions_log.emplace(ActionType::play, played_card, index, _num_clues == 8); _actions_log.emplace(ActionType::play, played_card, index, _num_clues == 8);
@ -169,7 +168,7 @@ namespace Hanabi {
_num_clues++; _num_clues++;
} }
unsigned long multiplicity = draw<update_card_positions>(index); const unsigned long multiplicity = draw<update_card_positions>(index);
incr_turn(); incr_turn();
return multiplicity; return multiplicity;
@ -403,7 +402,9 @@ namespace Hanabi {
_num_clues--; _num_clues--;
} }
revert_draw(last_action.index, last_action.discarded); revert_draw(last_action.index, last_action.discarded);
if(_stacks[last_action.discarded.suit] == last_action.discarded.rank) {
_stacks[last_action.discarded.suit]++; _stacks[last_action.discarded.suit]++;
}
_score--; _score--;
} }