fix keeping track of card positions
This commit is contained in:
parent
704913b64c
commit
1484c9e428
1 changed files with 19 additions and 12 deletions
|
@ -214,6 +214,21 @@ namespace Hanabi {
|
||||||
std::uint8_t HanabiState<num_suits, num_players, hand_size>::draw(uint8_t index) {
|
std::uint8_t HanabiState<num_suits, num_players, hand_size>::draw(uint8_t index) {
|
||||||
ASSERT(index < _hands[_turn].size());
|
ASSERT(index < _hands[_turn].size());
|
||||||
|
|
||||||
|
// update card position of the card we are about to discard
|
||||||
|
if constexpr(update_card_positions) {
|
||||||
|
const Card discarded = _hands[_turn][index];
|
||||||
|
if (!discarded.initial_trash) {
|
||||||
|
if (discarded.was_in_initial_hand) {
|
||||||
|
ASSERT(_card_positions_hands[_turn][index] == true);
|
||||||
|
_card_positions_hands[_turn][index] = false;
|
||||||
|
} else {
|
||||||
|
auto replaced_card_it = std::ranges::find(_card_positions_draw[discarded], _turn);
|
||||||
|
ASSERT(replaced_card_it != _card_positions_draw[discarded].end());
|
||||||
|
*replaced_card_it = trash_or_play_stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// draw a new card if the draw pile is not empty
|
// draw a new card if the draw pile is not empty
|
||||||
if (!_draw_pile.empty()) {
|
if (!_draw_pile.empty()) {
|
||||||
--_weighted_draw_pile_size;
|
--_weighted_draw_pile_size;
|
||||||
|
@ -228,18 +243,7 @@ namespace Hanabi {
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr(update_card_positions) {
|
if constexpr(update_card_positions) {
|
||||||
const Card discarded = _hands[_turn][index];
|
// update card position of the drawn card
|
||||||
if (!discarded.initial_trash) {
|
|
||||||
if (discarded.was_in_initial_hand) {
|
|
||||||
ASSERT(_card_positions_hands[_turn][index] == true);
|
|
||||||
_card_positions_hands[_turn][index] = false;
|
|
||||||
} else {
|
|
||||||
auto replaced_card_it = std::ranges::find(_card_positions_draw[discarded], _turn);
|
|
||||||
ASSERT(replaced_card_it != _card_positions_draw[discarded].end());
|
|
||||||
*replaced_card_it = trash_or_play_stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!draw.card.initial_trash) {
|
if (!draw.card.initial_trash) {
|
||||||
auto new_card_it = std::ranges::find(_card_positions_draw[draw.card], draw_pile);
|
auto new_card_it = std::ranges::find(_card_positions_draw[draw.card], draw_pile);
|
||||||
ASSERT(new_card_it != _card_positions_draw[draw.card].end());
|
ASSERT(new_card_it != _card_positions_draw[draw.card].end());
|
||||||
|
@ -281,6 +285,8 @@ namespace Hanabi {
|
||||||
|
|
||||||
_weighted_draw_pile_size++;
|
_weighted_draw_pile_size++;
|
||||||
_endgame_turns_left = no_endgame;
|
_endgame_turns_left = no_endgame;
|
||||||
|
} else {
|
||||||
|
ASSERT(_hands[_turn][index] == discarded_card);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discarded_card.initial_trash) {
|
if (!discarded_card.initial_trash) {
|
||||||
|
@ -290,6 +296,7 @@ namespace Hanabi {
|
||||||
} else {
|
} else {
|
||||||
auto hand_card_it = std::ranges::find(_card_positions_draw[discarded_card], trash_or_play_stack);
|
auto hand_card_it = std::ranges::find(_card_positions_draw[discarded_card], trash_or_play_stack);
|
||||||
ASSERT(hand_card_it != _card_positions_draw[discarded_card].end());
|
ASSERT(hand_card_it != _card_positions_draw[discarded_card].end());
|
||||||
|
*hand_card_it = _turn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue