bugfix: have switch for card cycling in play/discard methods as well

This commit is contained in:
Maximilian Keßler 2023-11-11 13:07:15 +01:00
parent a3972fe637
commit b9b73406f2
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 16 additions and 11 deletions

View file

@ -366,10 +366,10 @@ private:
bool initialized { false };
};
unsigned long discard_and_potentially_update(hand_index_t index);
unsigned long play_and_potentially_update(hand_index_t index);
unsigned long discard_and_potentially_update(hand_index_t index, bool cycle = false);
unsigned long play_and_potentially_update(hand_index_t index, bool cycle = false);
unsigned draw(hand_index_t index);
unsigned draw(hand_index_t index, bool cycle = false);
void revert_draw(hand_index_t index, Card discarded_card, bool cycle = false);
void revert_clue();

View file

@ -206,13 +206,13 @@ namespace Hanabi {
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
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, bool cycle) {
check_draw_pile_integrity();
auto copy = _draw_pile;
ASSERT(index < _hands[_turn].size());
const Card played_card = _hands[_turn][index];
if (!is_playable(played_card)) {
const unsigned long multiplicity = draw(index);
const unsigned long multiplicity = draw(index, cycle);
incr_turn();
return multiplicity;
}
@ -228,7 +228,7 @@ namespace Hanabi {
_num_clues++;
}
const unsigned long multiplicity = draw(index);
const unsigned long multiplicity = draw(index, cycle);
incr_turn();
check_draw_pile_integrity();
@ -241,7 +241,7 @@ namespace Hanabi {
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
unsigned long HanabiState<num_suits, num_players, hand_size>::discard_and_potentially_update(hand_index_t index) {
unsigned long HanabiState<num_suits, num_players, hand_size>::discard_and_potentially_update(hand_index_t index, bool cycle) {
check_draw_pile_integrity();
auto copy = _draw_pile;
ASSERT(index < _hands[_turn].size());
@ -251,7 +251,7 @@ namespace Hanabi {
_num_clues++;
_pace--;
unsigned long multiplicity = draw(index);
unsigned long multiplicity = draw(index, cycle);
_actions_log.emplace(ActionType::discard, discarded_card, index, false, copy);
incr_turn();
@ -309,7 +309,7 @@ namespace Hanabi {
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
unsigned HanabiState<num_suits, num_players, hand_size>::draw(uint8_t index) {
unsigned HanabiState<num_suits, num_players, hand_size>::draw(uint8_t index, bool cycle) {
ASSERT(index < _hands[_turn].size());
// update card position of the card we are about to discard
@ -337,8 +337,13 @@ namespace Hanabi {
ASSERT(draw.multiplicity > 0);
if (draw.multiplicity > 1) {
if (cycle) {
_draw_pile.push_back(draw);
_draw_pile.back().multiplicity--;
} else {
_draw_pile.push_front(draw);
_draw_pile.front().multiplicity--;
}
}
if (_relative_representation.initialized) {
@ -824,9 +829,9 @@ namespace Hanabi {
auto copy = _draw_pile;
auto do_action = [this, index, play](){
if (play) {
return play_and_potentially_update(index);
return play_and_potentially_update(index, true);
} else {
return discard_and_potentially_update(index);
return discard_and_potentially_update(index, true);
}
};