improve return codes
This commit is contained in:
parent
b30024d5a3
commit
d6474bb19d
3 changed files with 15 additions and 5 deletions
|
@ -82,6 +82,7 @@ namespace Hanabi
|
||||||
|
|
||||||
constexpr int download_failed = 1;
|
constexpr int download_failed = 1;
|
||||||
constexpr int state_unreachable = 2;
|
constexpr int state_unreachable = 2;
|
||||||
|
constexpr int out_of_memory = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse parameters from command-line arguments.
|
* Parse parameters from command-line arguments.
|
||||||
|
|
|
@ -776,13 +776,19 @@ namespace Hanabi
|
||||||
|
|
||||||
const std::array<Card, hand_size> & hand = _hands[_turn];
|
const std::array<Card, hand_size> & hand = _hands[_turn];
|
||||||
// First, check for playable cards
|
// First, check for playable cards
|
||||||
|
bool played_trash = false;
|
||||||
for (std::uint8_t index = 0; index < hand_size; index++)
|
for (std::uint8_t index = 0; index < hand_size; index++)
|
||||||
{
|
{
|
||||||
Card const & card = hand[index];
|
Card card = hand[index];
|
||||||
bool const consider_playing = is_playable(hand[index]) or (not is_critical(card) and not reasonable);
|
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)
|
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;
|
bool known = true;
|
||||||
probability_t sum_of_probabilities = 0;
|
probability_t sum_of_probabilities = 0;
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
|
|
||||||
#include "command_line_interface.h"
|
#include "command_line_interface.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::optional<Hanabi::CLIParms> parms = Hanabi::parse_parms(argc, argv);
|
std::optional<Hanabi::CLIParms> parms = Hanabi::parse_parms(argc, argv);
|
||||||
if (parms.has_value())
|
if (parms.has_value())
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return Hanabi::run_cli(parms.value());
|
return Hanabi::run_cli(parms.value());
|
||||||
|
} catch (std::bad_alloc& ex) {
|
||||||
|
return Hanabi::out_of_memory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue