support striking of cards

This commit is contained in:
Maximilian Keßler 2023-08-07 00:06:50 +02:00
parent bd400bb58c
commit 228eac7af1
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 19 additions and 5 deletions

View file

@ -113,6 +113,8 @@ namespace Download {
const std::vector<Action>& actions, const std::vector<Action>& actions,
size_t num_turns_to_replicate size_t num_turns_to_replicate
) { ) {
std::cout << "Initialising game with " << +num_players << " players, " << +num_suits << " suits and hand size " << +hand_size << std::endl;
auto game = std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<num_suits, num_players, hand_size>(deck)); auto game = std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<num_suits, num_players, hand_size>(deck));
std::uint8_t index; std::uint8_t index;
for (size_t i = 0; i < num_turns_to_replicate; i++) { for (size_t i = 0; i < num_turns_to_replicate; i++) {

View file

@ -177,6 +177,8 @@ protected:
void print(std::ostream& os) const final; void print(std::ostream& os) const final;
private: private:
BacktrackAction play_no_strike(hand_index_t index);
hand_index_t draw(hand_index_t index); hand_index_t draw(hand_index_t index);
void revert_draw(hand_index_t index, Card discarded_card); void revert_draw(hand_index_t index, Card discarded_card);

View file

@ -119,11 +119,21 @@ 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>
BacktrackAction HanabiState<num_suits, num_players, hand_size>::play( BacktrackAction HanabiState<num_suits, num_players, hand_size>::play(Hanabi::hand_index_t index) {
std::uint8_t index) { const Card card = _hands[_turn][index];
if (!is_playable(card)) {
BacktrackAction ret{card, index, draw(index)};
incr_turn();
return ret;
}
return play_no_strike(index);
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
BacktrackAction HanabiState<num_suits, num_players, hand_size>::play_no_strike(Hanabi::hand_index_t index) {
ASSERT(index < _hands[_turn].size()); ASSERT(index < _hands[_turn].size());
const Card card = _hands[_turn][index]; const Card card = _hands[_turn][index];
ASSERT(card.rank == _stacks[card.suit] - 1); ASSERT(is_playable(card));
--_stacks[card.suit]; --_stacks[card.suit];
_score++; _score++;
@ -323,7 +333,7 @@ namespace Hanabi {
if(is_playable(hand[index])) { if(is_playable(hand[index])) {
if (_draw_pile.empty()) { if (_draw_pile.empty()) {
bool on_8_clues = _num_clues == 8; bool on_8_clues = _num_clues == 8;
BacktrackAction action = play(index); BacktrackAction action = play_no_strike(index);
const double probability_for_this_play = backtrack(depth + 1); const double probability_for_this_play = backtrack(depth + 1);
revert_play(action, on_8_clues); revert_play(action, on_8_clues);
UPDATE_PROBABILITY(probability_for_this_play); UPDATE_PROBABILITY(probability_for_this_play);
@ -332,7 +342,7 @@ namespace Hanabi {
uint8_t sum_of_mults = 0; uint8_t sum_of_mults = 0;
for (size_t i = 0; i < _draw_pile.size(); i++) { for (size_t i = 0; i < _draw_pile.size(); i++) {
bool on_8_clues = _num_clues == 8; bool on_8_clues = _num_clues == 8;
BacktrackAction action = play(index); BacktrackAction action = play_no_strike(index);
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity; sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
sum_of_mults += action.multiplicity; sum_of_mults += action.multiplicity;
revert_play(action, on_8_clues); revert_play(action, on_8_clues);