bugfix: have switch for card cycling in play/discard methods as well
This commit is contained in:
parent
a3972fe637
commit
b9b73406f2
2 changed files with 16 additions and 11 deletions
|
@ -366,10 +366,10 @@ private:
|
||||||
bool initialized { false };
|
bool initialized { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned long discard_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);
|
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_draw(hand_index_t index, Card discarded_card, bool cycle = false);
|
||||||
void revert_clue();
|
void revert_clue();
|
||||||
|
|
|
@ -206,13 +206,13 @@ 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>
|
||||||
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();
|
check_draw_pile_integrity();
|
||||||
auto copy = _draw_pile;
|
auto copy = _draw_pile;
|
||||||
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)) {
|
if (!is_playable(played_card)) {
|
||||||
const unsigned long multiplicity = draw(index);
|
const unsigned long multiplicity = draw(index, cycle);
|
||||||
incr_turn();
|
incr_turn();
|
||||||
return multiplicity;
|
return multiplicity;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ namespace Hanabi {
|
||||||
_num_clues++;
|
_num_clues++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned long multiplicity = draw(index);
|
const unsigned long multiplicity = draw(index, cycle);
|
||||||
|
|
||||||
incr_turn();
|
incr_turn();
|
||||||
check_draw_pile_integrity();
|
check_draw_pile_integrity();
|
||||||
|
@ -241,7 +241,7 @@ 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>
|
||||||
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();
|
check_draw_pile_integrity();
|
||||||
auto copy = _draw_pile;
|
auto copy = _draw_pile;
|
||||||
ASSERT(index < _hands[_turn].size());
|
ASSERT(index < _hands[_turn].size());
|
||||||
|
@ -251,7 +251,7 @@ namespace Hanabi {
|
||||||
_num_clues++;
|
_num_clues++;
|
||||||
_pace--;
|
_pace--;
|
||||||
|
|
||||||
unsigned long multiplicity = draw(index);
|
unsigned long multiplicity = draw(index, cycle);
|
||||||
_actions_log.emplace(ActionType::discard, discarded_card, index, false, copy);
|
_actions_log.emplace(ActionType::discard, discarded_card, index, false, copy);
|
||||||
|
|
||||||
incr_turn();
|
incr_turn();
|
||||||
|
@ -309,7 +309,7 @@ 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>
|
||||||
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());
|
ASSERT(index < _hands[_turn].size());
|
||||||
|
|
||||||
// update card position of the card we are about to discard
|
// update card position of the card we are about to discard
|
||||||
|
@ -337,8 +337,13 @@ namespace Hanabi {
|
||||||
ASSERT(draw.multiplicity > 0);
|
ASSERT(draw.multiplicity > 0);
|
||||||
|
|
||||||
if (draw.multiplicity > 1) {
|
if (draw.multiplicity > 1) {
|
||||||
|
if (cycle) {
|
||||||
_draw_pile.push_back(draw);
|
_draw_pile.push_back(draw);
|
||||||
_draw_pile.back().multiplicity--;
|
_draw_pile.back().multiplicity--;
|
||||||
|
} else {
|
||||||
|
_draw_pile.push_front(draw);
|
||||||
|
_draw_pile.front().multiplicity--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_relative_representation.initialized) {
|
if (_relative_representation.initialized) {
|
||||||
|
@ -824,9 +829,9 @@ namespace Hanabi {
|
||||||
auto copy = _draw_pile;
|
auto copy = _draw_pile;
|
||||||
auto do_action = [this, index, play](){
|
auto do_action = [this, index, play](){
|
||||||
if (play) {
|
if (play) {
|
||||||
return play_and_potentially_update(index);
|
return play_and_potentially_update(index, true);
|
||||||
} else {
|
} else {
|
||||||
return discard_and_potentially_update(index);
|
return discard_and_potentially_update(index, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue