NAME

Game::Durak::Error - what the rules refuse, as a code

VERSION

Version 0.01

SYNOPSIS

my $out = $game->apply(1, { kind => 'attack', card => 14 });
if (ref $out eq 'Game::Durak::Error') {
    $out->code;       # 'rank_not_in_bout'
    $out->message;    # 'nothing on the table has that rank'
}

DESCRIPTION

An error is returned and never thrown. A move a player is not allowed to make is an ordinary answer, not an exception: the consumer turns the code into whatever it says to a person, and a code it has never heard of degrades to a refusal rather than to a crash.

A state that cannot happen is the other thing entirely, and it dies. A card id that is not a card, a suit that is not a suit, a bout opened against an empty hand: those are bugs in the caller and they are not codes.

The codes, and why they are not the obvious names

The consumer these are written for is peer2peergames, whose own refusal table already holds a hundred and sixty codes, so two of the obvious names are taken and would have landed this game's refusals on another game's sentence. no_swap is the Hex swap rule ("the swap is only offered on the second player's first turn"), so the exchange refuses with not_the_six and talon_shut. stock_empty says stock and belongs to a shedding game, so the talon says talon_shut.

must_attack is the reachable half of what an earlier draft called bout_open. A card that is unbeaten in a bout nobody has taken is the defending stage, so a done sent then is refused for the stage and never for the unbeaten card; the one way to say you are finished when you are not is to say it before attacking at all.

METHODS

code

The short string a consumer switches on.

message

One sentence in English, for a terminal or a log. A consumer with a translation table of its own should use the code and ignore this.

new_code

Game::Durak::Error->new_code('bout_full');

An error from a code. An unknown code gets itself as its message rather than undef, so a missing entry shows up in the output instead of disappearing.

codes

Every code this engine can return, sorted. A consumer's mapping table can be tested against it, which is how a new code is noticed before a player finds it.

SEE ALSO

Game::Durak.

AUTHOR

LNATION, <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under the Artistic License 2.0.