Module: Scoring
- Included in:
- ScoreSheet
- Defined in:
- lib/scoring.rb
Overview
methods for calculating score
Constant Summary collapse
- UpperScores =
The fields on the top section of the score sheet
:ones, :twos, :threes, :fours, :fives, :sixes
- LowerScores =
The fields on the bottom section of the score sheet
:three_of_a_kind, :four_of_a_kind, :full_house, :small_straight, :large_straight, :chance, :yahtzee
Instance Method Summary collapse
-
#chance(dice) ⇒ Fixnum
The sum of all the dice.
- #fives(d) ⇒ Object
-
#four_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 4 of the same dice.
- #fours(d) ⇒ Object
-
#full_house(dice) ⇒ Fixnum
Checks to see if you have 3 of one kind of dice and 2 of another.
- #large_straight(dice) ⇒ Fixnum (also: #LS)
-
#ones(d) ⇒ Fixnum
The score.
- #sixes(d) ⇒ Object
- #small_straight(dice) ⇒ Fixnum (also: #SS)
-
#three_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 3 of the same dice.
- #threes(d) ⇒ Object
- #twos(d) ⇒ Object
Instance Method Details
#chance(dice) ⇒ Fixnum
Returns the sum of all the dice.
73 74 75 |
# File 'lib/scoring.rb', line 73 def chance(dice) dice.reduce :+ end |
#fives(d) ⇒ Object
51 52 53 |
# File 'lib/scoring.rb', line 51 def fives(d) # @see (#ones) single_face d, 5 end |
#four_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 4 of the same dice
27 28 29 |
# File 'lib/scoring.rb', line 27 def four_of_a_kind(dice) of_a_kind dice, 4 end |
#fours(d) ⇒ Object
47 48 49 |
# File 'lib/scoring.rb', line 47 def fours(d) # @see (#ones) single_face d, 4 end |
#full_house(dice) ⇒ Fixnum
Checks to see if you have 3 of one kind of dice and 2 of another
14 15 16 17 18 19 |
# File 'lib/scoring.rb', line 14 def full_house(dice) f_table = freq dice if (f_table.length == 2 && f_table.has_value?(3)) || f_table.length == 1 then return 25 else; return 0 end end |
#large_straight(dice) ⇒ Fixnum Also known as: LS
94 95 96 |
# File 'lib/scoring.rb', line 94 def large_straight(dice) straight dice, 5, 40 end |
#ones(d) ⇒ Fixnum
Returns the score.
35 36 37 |
# File 'lib/scoring.rb', line 35 def ones(d) single_face d, 1 end |
#sixes(d) ⇒ Object
55 56 57 |
# File 'lib/scoring.rb', line 55 def sixes(d) # @see (#ones) single_face d, 6 end |
#small_straight(dice) ⇒ Fixnum Also known as: SS
83 84 85 |
# File 'lib/scoring.rb', line 83 def small_straight(dice) straight dice, 4, 30 end |
#three_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 3 of the same dice
65 66 67 |
# File 'lib/scoring.rb', line 65 def three_of_a_kind(dice) of_a_kind dice, 3 end |
#threes(d) ⇒ Object
43 44 45 |
# File 'lib/scoring.rb', line 43 def threes(d) # @see (#ones) single_face d, 3 end |
#twos(d) ⇒ Object
39 40 41 |
# File 'lib/scoring.rb', line 39 def twos(d) # @see (#ones) single_face d, 2 end |