Class: Bridge::Contract
- Inherits:
-
Object
- Object
- Bridge::Contract
- Defined in:
- lib/bridge/contract.rb
Overview
Represents the result of an auction. Swiped from: pybridge.svn.sourceforge.net/svnroot/pybridge/trunk/pybridge/pybridge/games/bridge/auction.py
Instance Attribute Summary collapse
-
#bid ⇒ Object
Returns the value of attribute bid.
-
#declarer ⇒ Object
Returns the value of attribute declarer.
-
#double_by ⇒ Object
Returns the value of attribute double_by.
-
#redouble_by ⇒ Object
Returns the value of attribute redouble_by.
Instance Method Summary collapse
-
#initialize(auction) ⇒ Contract
constructor
A new instance of Contract.
- #to_hash ⇒ Object
Constructor Details
#initialize(auction) ⇒ Contract
Returns a new instance of Contract.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bridge/contract.rb', line 11 def initialize auction raise InvalidAuctionError unless auction.complete? and !auction.passed_out? # The contract is the last (and highest) bid. self.bid = auction.current_bid # The declarer is the first partner to bid the contract denomination. caller = auction.who_called?(self.bid) partnership = [caller, Direction[(caller + 2) % 4]] # Determine which partner is declarer. auction.calls.each do |call| if call.is_a?(Bid) and call.strain == self.bid.strain bidder = auction.who_called?(call) if partnership.include?(bidder) self.declarer = bidder break end end end self.double_by, self.redouble_by = [nil, nil] if auction.current_double # The opponent who doubled the contract bid. self.double_by = auction.who_called?(auction.current_double) if auction.current_redouble # The partner who redoubled an opponent's double. self.redouble_by = auction.who_called?(auction.current_redouble) end end end |
Instance Attribute Details
#bid ⇒ Object
Returns the value of attribute bid.
7 8 9 |
# File 'lib/bridge/contract.rb', line 7 def bid @bid end |
#declarer ⇒ Object
Returns the value of attribute declarer.
7 8 9 |
# File 'lib/bridge/contract.rb', line 7 def declarer @declarer end |
#double_by ⇒ Object
Returns the value of attribute double_by.
7 8 9 |
# File 'lib/bridge/contract.rb', line 7 def double_by @double_by end |
#redouble_by ⇒ Object
Returns the value of attribute redouble_by.
7 8 9 |
# File 'lib/bridge/contract.rb', line 7 def redouble_by @redouble_by end |
Instance Method Details
#to_hash ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/bridge/contract.rb', line 42 def to_hash { :bid => bid, :declarer => declarer, :double_by => double_by, :redouble_by => redouble_by } end |