handle CS games on download

This commit is contained in:
Maximilian Keßler 2024-01-09 02:21:01 +01:00
parent 5b6e877a51
commit 486e459c68
Signed by: max
GPG key ID: BCC5A619923C0BA5
5 changed files with 44 additions and 24 deletions

View file

@ -98,6 +98,7 @@ namespace Hanabi
std::vector<Hanabi::Action> actions; std::vector<Hanabi::Action> actions;
Hanabi::suit_t num_suits; Hanabi::suit_t num_suits;
Hanabi::player_t num_players; Hanabi::player_t num_players;
clue_t num_clues_gained_per_discard_or_stack_finished;
}; };
struct Game : private GameInfo struct Game : private GameInfo

View file

@ -14,6 +14,7 @@ namespace Hanabi
* @param deck A list of cards with at most as many suits as num_suits * @param deck A list of cards with at most as many suits as num_suits
* @param score_goal What is considered as an optimal score for this game state. * @param score_goal What is considered as an optimal score for this game state.
* If null, the maximum score is inserted * If null, the maximum score is inserted
* @param num_clues_gained_on_discard_or_stack_finished The number of clues gained for discarding or playing a 5
* @return Pointer to created game state, wrapped into abstract interface * @return Pointer to created game state, wrapped into abstract interface
* *
* @note Since the implementation of the actual game state (the concrete class derived from HanabiStateIF), * @note Since the implementation of the actual game state (the concrete class derived from HanabiStateIF),
@ -25,6 +26,7 @@ namespace Hanabi
std::size_t num_suits, std::size_t num_suits,
Hanabi::player_t num_players, Hanabi::player_t num_players,
std::vector<Hanabi::Card> const &deck, std::vector<Hanabi::Card> const &deck,
clue_t num_clues_gained_on_discard_or_stack_finished = clue_t(1),
std::optional<uint8_t> score_goal = std::nullopt std::optional<uint8_t> score_goal = std::nullopt
); );
} }

View file

@ -41,7 +41,8 @@ namespace Download
} }
Hanabi::GameInfo game_info = Parsing::parse_game(game_json.value()); Hanabi::GameInfo game_info = Parsing::parse_game(game_json.value());
return {make_game_state(game_info.num_suits, game_info.num_players, game_info.deck, score_goal), game_info};
return {make_game_state(game_info.num_suits, game_info.num_players, game_info.deck, game_info.num_clues_gained_per_discard_or_stack_finished, score_goal), game_info};
} }
Hanabi::Game get_game(std::string const & filename, std::optional<uint8_t> score_goal) Hanabi::Game get_game(std::string const & filename, std::optional<uint8_t> score_goal)
@ -53,6 +54,6 @@ namespace Download
} }
Hanabi::GameInfo game_info = Parsing::parse_game(game_json.value()); Hanabi::GameInfo game_info = Parsing::parse_game(game_json.value());
return {make_game_state(game_info.num_suits, game_info.num_players, game_info.deck, score_goal), game_info}; return {make_game_state(game_info.num_suits, game_info.num_players, game_info.deck, game_info.num_clues_gained_per_discard_or_stack_finished, score_goal), game_info};
} }
} // namespace Download } // namespace Download

View file

@ -4,7 +4,8 @@
namespace Hanabi namespace Hanabi
{ {
std::unique_ptr<Hanabi::HanabiStateIF> make_game_state( std::unique_ptr<Hanabi::HanabiStateIF> make_game_state(
std::size_t num_suits, Hanabi::player_t num_players, std::vector<Hanabi::Card> const & deck, std::optional< std::size_t num_suits, Hanabi::player_t num_players, std::vector<Hanabi::Card> const & deck,
clue_t num_clues_gained_on_discard_or_stack_finished, std::optional<
uint8_t> score_goal uint8_t> score_goal
) )
{ {
@ -15,13 +16,13 @@ namespace Hanabi
switch (num_suits) switch (num_suits)
{ {
case 3: case 3:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 2, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 2, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 4: case 4:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 2, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 2, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 5: case 5:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 2, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 2, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 6: case 6:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 2, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 2, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
default: default:
throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits)); throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits));
} }
@ -29,13 +30,13 @@ namespace Hanabi
switch (num_suits) switch (num_suits)
{ {
case 3: case 3:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 3, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 3, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 4: case 4:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 3, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 3, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 5: case 5:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 3, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 3, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 6: case 6:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 3, 5>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 3, 5>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
default: default:
throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits)); throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits));
} }
@ -43,13 +44,13 @@ namespace Hanabi
switch (num_suits) switch (num_suits)
{ {
case 3: case 3:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 4, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 4, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 4: case 4:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 4, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 4, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 5: case 5:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 4, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 4, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 6: case 6:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 4, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 4, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
default: default:
throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits)); throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits));
} }
@ -57,13 +58,13 @@ namespace Hanabi
switch (num_suits) switch (num_suits)
{ {
case 3: case 3:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 5, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 5, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 4: case 4:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 5, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 5, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 5: case 5:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 5, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 5, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 6: case 6:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 5, 4>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 5, 4>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
default: default:
throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits)); throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits));
} }
@ -71,13 +72,13 @@ namespace Hanabi
switch (num_suits) switch (num_suits)
{ {
case 3: case 3:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 6, 3>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<3, 6, 3>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 4: case 4:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 6, 3>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<4, 6, 3>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 5: case 5:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 6, 3>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<5, 6, 3>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
case 6: case 6:
return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 6, 3>(deck, actual_score_goal)); return std::unique_ptr<Hanabi::HanabiStateIF>(new Hanabi::HanabiState<6, 6, 3>(deck, actual_score_goal, num_clues_gained_on_discard_or_stack_finished));
default: default:
throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits)); throw std::runtime_error("Invalid number of suits: " + std::to_string(num_suits));
} }

View file

@ -1,6 +1,7 @@
#include "parse_game.h" #include "parse_game.h"
#include "myassert.h" #include "myassert.h"
#include <iostream>
namespace Parsing namespace Parsing
{ {
@ -112,7 +113,21 @@ namespace Parsing
Hanabi::player_t num_players = game_json.at("players").as_array().size(); Hanabi::player_t num_players = game_json.at("players").as_array().size();
std::vector<Hanabi::Action> actions = convert_actions(hanab_live_actions, deck); std::vector<Hanabi::Action> actions = convert_actions(hanab_live_actions, deck);
return {deck, actions, num_suits, num_players}; boost::json::value const * options = game_json.if_contains("options");
Hanabi::clue_t num_clues_gained_on_discard = Hanabi::clue_t(1);
if (options != nullptr) {
std::cout << "found options";
boost::json::value const * variant = options->as_object().if_contains("variant");
if (variant != nullptr) {
std::cout << "found variant: " << variant->as_string();
if (variant->as_string().find("Clue Starved") != std::string::npos) {
num_clues_gained_on_discard = Hanabi::clue_t (1) / Hanabi::clue_t (2);
std::cout << "found cs game";
}
}
}
std::cout << num_clues_gained_on_discard;
return {deck, actions, num_suits, num_players, num_clues_gained_on_discard };
} }