diff --git a/include/command_line_interface.h b/include/command_line_interface.h index 82f7d35..b5b2d71 100644 --- a/include/command_line_interface.h +++ b/include/command_line_interface.h @@ -82,6 +82,7 @@ namespace Hanabi constexpr int download_failed = 1; constexpr int state_unreachable = 2; + constexpr int out_of_memory = 3; /** * Parse parameters from command-line arguments. diff --git a/include/game_state.hpp b/include/game_state.hpp index 7d3e9a0..ffd2574 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -776,13 +776,19 @@ namespace Hanabi const std::array & hand = _hands[_turn]; // First, check for playable cards + bool played_trash = false; for (std::uint8_t index = 0; index < hand_size; index++) { - Card const & card = hand[index]; - bool const consider_playing = is_playable(hand[index]) or (not is_critical(card) and not reasonable); + Card card = hand[index]; + bool const consider_playing = is_playable(card) or (not is_critical(card) and not reasonable and (not is_trash(card) or not played_trash)); if (consider_playing) { - const Action action = {ActionType::play, hand[index]}; + if (is_trash(card)) + { + card = Cards::trash; + played_trash = true; + } + const Action action = {ActionType::play, card}; bool known = true; probability_t sum_of_probabilities = 0; diff --git a/src/main.cpp b/src/main.cpp index 3cc4d26..df2109b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,13 +2,16 @@ #include "command_line_interface.h" - int main(int argc, char *argv[]) { std::optional parms = Hanabi::parse_parms(argc, argv); if (parms.has_value()) { - return Hanabi::run_cli(parms.value()); + try { + return Hanabi::run_cli(parms.value()); + } catch (std::bad_alloc& ex) { + return Hanabi::out_of_memory; + } } return EXIT_SUCCESS; }