game state: fix taking actions: rotate draw correctly

This commit is contained in:
Maximilian Keßler 2023-11-10 21:42:09 +01:00
parent 9af6ef3368
commit 6dd2b07c09
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 5 additions and 4 deletions

View file

@ -262,6 +262,7 @@ struct Game {
std::unique_ptr<HanabiStateIF> state;
std::vector<Action> actions;
std::vector<Card> deck;
unsigned next_action;
};

View file

@ -651,8 +651,8 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
void HanabiState<num_suits, num_players, hand_size>::rotate_next_draw(const Card& card) {
auto card_it = std::find_if(_draw_pile.begin(), _draw_pile.end(), [&card](const CardMultiplicity& card_multiplicity){
return card_multiplicity.card.rank == card.rank and card_multiplicity.card.suit == card.suit;
auto card_it = std::find_if(_draw_pile.begin(), _draw_pile.end(), [&card, this](const CardMultiplicity& card_multiplicity){
return (is_trash(card) and is_trash(card_multiplicity.card)) or (card_multiplicity.card.rank == card.rank and card_multiplicity.card.suit == card.suit);
});
ASSERT(card_it != _draw_pile.end());
std::swap(*card_it, _draw_pile.front());

View file

@ -182,7 +182,7 @@ namespace Download {
}();
if (!game_json_opt.has_value() or game_json_opt.value().empty()) {
return {nullptr, {}, 0};
return {nullptr, {}, {}, 0};
}
const boost::json::object& game_json = game_json_opt.value();
@ -202,7 +202,7 @@ namespace Download {
}
);
return {get_base_state(num_suits, num_players, deck, score_goal), actions, 0};
return {get_base_state(num_suits, num_players, deck, score_goal), actions, deck, 0};
}
} // namespace Download