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) ⇒ Fixnum
The score.
-
#four_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 4 of the same dice.
-
#fours(d) ⇒ Fixnum
The score.
-
#full_house(dice) ⇒ Fixnum
Checks to see if dice has 3 of one kind of dice and 2 of another.
- #large_straight(dice) ⇒ Fixnum (also: #LS)
-
#ones(d) ⇒ Fixnum
The total of all the ones.
-
#sixes(d) ⇒ Fixnum
The score.
- #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) ⇒ Fixnum
The score.
-
#twos(d) ⇒ Fixnum
The total of all the twos.
Instance Method Details
#chance(dice) ⇒ Fixnum
Returns the sum of all the dice.
95 96 97 |
# File 'lib/scoring.rb', line 95 def chance(dice) dice.reduce :+ end |
#fives(d) ⇒ Fixnum
Returns the score.
69 70 71 |
# File 'lib/scoring.rb', line 69 def fives(d) single_face d, 5 end |
#four_of_a_kind(dice) ⇒ Fixnum
Checks to see if you have 4 of the same dice
29 30 31 |
# File 'lib/scoring.rb', line 29 def four_of_a_kind(dice) of_a_kind dice, 4 end |
#fours(d) ⇒ Fixnum
Returns the score.
61 62 63 |
# File 'lib/scoring.rb', line 61 def fours(d) single_face d, 4 end |
#full_house(dice) ⇒ Fixnum
Checks to see if dice has 3 of one kind of dice and 2 of another
15 16 17 18 19 20 |
# File 'lib/scoring.rb', line 15 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
116 117 118 |
# File 'lib/scoring.rb', line 116 def large_straight(dice) straight dice, 5, 40 end |
#ones(d) ⇒ Fixnum
Returns the total of all the ones.
37 38 39 |
# File 'lib/scoring.rb', line 37 def ones(d) single_face d, 1 end |
#sixes(d) ⇒ Fixnum
Returns the score.
77 78 79 |
# File 'lib/scoring.rb', line 77 def sixes(d) # @see (#ones) single_face d, 6 end |
#small_straight(dice) ⇒ Fixnum Also known as: SS
105 106 107 |
# File 'lib/scoring.rb', line 105 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
87 88 89 |
# File 'lib/scoring.rb', line 87 def three_of_a_kind(dice) of_a_kind dice, 3 end |
#threes(d) ⇒ Fixnum
Returns the score.
53 54 55 |
# File 'lib/scoring.rb', line 53 def threes(d) single_face d, 3 end |
#twos(d) ⇒ Fixnum
Returns the total of all the twos.
45 46 47 |
# File 'lib/scoring.rb', line 45 def twos(d) single_face d, 2 end |