improve return codes

This commit is contained in:
Maximilian Keßler 2024-01-13 14:36:36 +01:00
parent b30024d5a3
commit d6474bb19d
Signed by: max
GPG Key ID: BCC5A619923C0BA5
3 changed files with 15 additions and 5 deletions

View File

@ -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.

View File

@ -776,13 +776,19 @@ namespace Hanabi
const std::array<Card, hand_size> & 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;

View File

@ -2,13 +2,16 @@
#include "command_line_interface.h"
int main(int argc, char *argv[])
{
std::optional<Hanabi::CLIParms> 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;
}