diff --git a/include/game_state.h b/include/game_state.h index 3e5a5ff..28cafb4 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -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(); diff --git a/include/game_state.hpp b/include/game_state.hpp index e5c781d..293858b 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -206,13 +206,13 @@ namespace Hanabi { } template - unsigned long HanabiState::play_and_potentially_update(hand_index_t index) { + unsigned long HanabiState::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 - unsigned long HanabiState::discard_and_potentially_update(hand_index_t index) { + unsigned long HanabiState::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 - unsigned HanabiState::draw(uint8_t index) { + unsigned HanabiState::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); } };