Games::Tournament::Card - A record of the results of a match
=cut
=head1 SYNOPSIS
$game = Games::Tournament:Card->new(round => 1, contestants => {Black => $knicks, White => $deepblue}, result => { Black => 'Win', White => 'Loss' });
=head1 DESCRIPTION
In a tournament, matches take place in rounds between contestants, who are maybe floated, and who have roles, and there is a result for these matches, which can be written on a card.
=head1 METHODS
=head2 new
$game = Games::Tournament:Card->new(
round => 1,
contestants => {Black => $knicks, White => $deepblue},
result => { Black => 'Win', White => 'Loss' },
floats => { Black => 'Up', White => 'Down' }, or
floats => { Black => 'Not', White => 'Not' }
);
$bye = Games::Tournament:Card->new(
round => 1,
contestants => {Bye => $player},
result => "Bye"
floats => 'Down' );
'contestants' is a hash ref of player objects, keyed on Black and White, or Home and Away, or some other role distinction that needs to be balanced over the tournament. The players are probably instances of the Games::Tournament::Contestant::Swiss class. 'result' is a hash reference, keyed on the same keys as contestants, containing the results of the match. 'floats' is a hash of which role was floated up and which down. The default is neither contestant was floated, and 'Down' for a Bye. A4. What are the fields in Forfeits and byes? Forfeit and Tardy have no special form, other than { White => 'Forfeit', Black => 'Tardy' }. Bye is { Bye => $player }. TODO Perhaps the fields should be Winner and Loser, and Down and Up?
=cut
subnew {
my$self= shift;
my%args= @_;
returnbless\%args, $self;
}
=head2 canonize
$game->canonize
Fleshes out a partial statement of the result. From an abbreviated match result (eg, { Black => 'Win' }), works out a canonical representation (eg, { Black => 'Win', White => 'Loss' }). A bye result is represented as { Bye => 'Bye' }.
A predicate to perform a test to see if a player is a contestant in $game. Because different objects may refer to the same player when copied by value, use id to decide.
=cut
subhasPlayer {
my$self= shift;
my$player= shift;
my@contestants= $self->myPlayers;
any { $player->id eq $_->id } @contestants;
}
=head2 myOpponent
$game->myOpponent($player)
Returns the opponent of $player from $game. If $player has a Bye, return a Games::Tournament::Contestant::Swiss object with name 'Bye', and id 'Bye'.
Gets/sets whether the player was floated 'Up', 'Down', or 'Not' floated. $player->floats is not changed. This takes place in $tourney->collectCards. TODO what if $player is 'Bye'?