The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Games::Cards::Bridge::Contract - Bridge (card game) contract and scoring class

VERSION

Version 0.01

SYNOPSIS

This module provides a class for creating Bridge contract objects, including the results and both duplicate and rubber scoring.

This is example is for the contract of 4S by North, not vulnerable, redoubled, and taking 11 tricks.

  my $contract = Games::Cards::Bridge::Contract->new( declarer=>'N', trump=>'S', bid=>4, made=>5, vul=>0, penalty=>2);
  my $pts = $contract->duplicate_score;
  my ( $declarer_above_line, $declarer_below_line, $defense_above_line ) = $contract->rubber_score;

METHODS

new

Requires named parameters trump, declarer, bid, made, down (only one of made or down can be set). Optional named parameters of vul, penalty. See each of the ATTRIBUTES for the allowed values/defaults. Croaks if validation fails.

minor

Boolean -- true iff the contract is Clubs or Diamonds

major

Boolean -- true iff the contract is Hearts or Spades

notrump

Boolean -- true iff the contract is No Trump

passout

Boolean -- true iff the contract was a passout

slam

Boolean -- true iff contract was at the slam (small or grand) level

small_slam

Boolean -- true iff contract was a small slam (bid 6)

grand_slam

Boolean -- true iff contract was a grand slam (bid 7)

overtricks

If contract made, this is the number of overtrcks (made-bid). undef if contract was defeated.

game

Boolean -- true iff the given number of tricks (defaults to number bid) would constitute the game level (or higher).

rubber_score

Returns an array of ( declarer_above, declarer_below, defense_above ) for the current contract/result.

Note that honors, game bonus, and rubber bonus need to be handled externally. (See Games::Cards::Bridge::Rubber)

duplicate_score

Returns the declarer's score for this contract/result. Postive if declarer made it, negative if he went down.

__calc_score

Internal-use method that does the actual score calculation. Returns a hashref w/the following keys:

  • undertricks

  • tricks

  • overtricks

  • partscore

  • game

  • slam

  • insult

each representing part of the total score. For scoring references/details, see

ATTRIBUTES

These all have accessors provided by Class::Accessor.

declarer

Must be one of: N E S W for North, East, South, West.

trump

Must be one of: C D H S N P for Clubs, Diamonds, Hearts, Spades, Notrump, Passout.

vul

Boolean (gets casted into 1 or 0)

penalty

Must be 1 if the contract is doubled, 2 if it is redoubled, and 0 otherwise.

bid

The level of the contract. Must be between 1 and 7, inclusive.

made

If the contract made, this should be the level that was made, which must be between bid and 7, inclusive. e.g. If bid 4 and took 12 tricks, then made is 6. Must be undef/unspecified if the contract went down.

down

If the contract was defeated, then this is number of tricks it went down, which must be between 1 and bid, inclusive. e.g. If bid 4 and took 8 tricks, then down is 2. Must be undef/unspecified if the contract made.

PREREQUISITES

AUTHOR

David Westbrook, <dwestbrook at gmail.com>

SEE ALSO

TODO

BUGS

Please report any bugs or feature requests to bug-games-cards-bridge at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Cards-Bridge-Contract. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

I'm also available by email or via '/msg davidrw' on http://perlmonks.org.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Games::Cards::Bridge::Contract

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2006 David Westbrook, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.