From 6dd2b07c09eb688ec122b900820166ad7c8855a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 10 Nov 2023 21:42:09 +0100 Subject: [PATCH] game state: fix taking actions: rotate draw correctly --- include/game_state.h | 1 + include/game_state.hpp | 4 ++-- src/download.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/game_state.h b/include/game_state.h index 850f154..c1c5564 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -262,6 +262,7 @@ struct Game { std::unique_ptr state; std::vector actions; + std::vector deck; unsigned next_action; }; diff --git a/include/game_state.hpp b/include/game_state.hpp index e8ac360..0ebb8cd 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -651,8 +651,8 @@ namespace Hanabi { template void HanabiState::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()); diff --git a/src/download.cpp b/src/download.cpp index 8240872..7a6b568 100644 --- a/src/download.cpp +++ b/src/download.cpp @@ -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