Class: Bcalc::Calculator
- Inherits:
-
Object
- Object
- Bcalc::Calculator
- Defined in:
- lib/bcalc/calculator.rb
Constant Summary collapse
- SUITS =
{ "C" => Bcalc::Lib::BCALC_SUIT_CLUBS, "D" => Bcalc::Lib::BCALC_SUIT_DIAMONDS, "H" => Bcalc::Lib::BCALC_SUIT_HEARTS, "S" => Bcalc::Lib::BCALC_SUIT_SPADES, "NT" => Bcalc::Lib::BCALC_NT }
- PLAYERS =
{ "N" => Bcalc::Lib::BCALC_PLAYER_NORTH, "E" => Bcalc::Lib::BCALC_PLAYER_EAST, "S" => Bcalc::Lib::BCALC_PLAYER_SOUTH, "W" => Bcalc::Lib::BCALC_PLAYER_WEST, }
Instance Attribute Summary collapse
-
#deal ⇒ Object
readonly
Returns the value of attribute deal.
-
#declarer ⇒ Object
readonly
Returns the value of attribute declarer.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Instance Method Summary collapse
-
#initialize(deal:, declarer:, suit:) ⇒ Calculator
constructor
A new instance of Calculator.
-
#tricks ⇒ Object
Returns number of tricks that declarer can take.
Constructor Details
#initialize(deal:, declarer:, suit:) ⇒ Calculator
Returns a new instance of Calculator.
21 22 23 24 25 26 27 28 |
# File 'lib/bcalc/calculator.rb', line 21 def initialize(deal:, declarer:, suit:) PLAYERS.keys.include?(declarer) || raise(ArgumentError, "Wrong declarer value: #{declarer}") SUITS.keys.include?(suit) || raise(ArgumentError, "Wrong suit value: #{suit}") @deal = deal @declarer = declarer @suit = suit end |
Instance Attribute Details
#deal ⇒ Object (readonly)
Returns the value of attribute deal.
19 20 21 |
# File 'lib/bcalc/calculator.rb', line 19 def deal @deal end |
#declarer ⇒ Object (readonly)
Returns the value of attribute declarer.
19 20 21 |
# File 'lib/bcalc/calculator.rb', line 19 def declarer @declarer end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
19 20 21 |
# File 'lib/bcalc/calculator.rb', line 19 def suit @suit end |
Instance Method Details
#tricks ⇒ Object
Returns number of tricks that declarer can take
31 32 33 34 35 36 37 38 |
# File 'lib/bcalc/calculator.rb', line 31 def tricks solver = Bcalc::Lib.bcalcDDS_new("PBN", deal, SUITS[suit], leader) raise_on_error(solver) result = Bcalc::Lib.bcalcDDS_getTricksToTake(solver) MAX_TRICKS - result ensure Bcalc::Lib.bcalcDDS_delete(solver) end |