Ruby_Dice 1.0.0.pre.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0b41e4272ad3e63b64929479bca5d394678b8d8
4
- data.tar.gz: bd450c716e3859116be0fa928c521ca299382ff9
3
+ metadata.gz: ef8117351f5cfdb375f63cbda1f3da98d3da62aa
4
+ data.tar.gz: f108f818986f325633806d14022096b585f17c9a
5
5
  SHA512:
6
- metadata.gz: e1be61f9c2979458163467c3d16c8c9ee546779ee19859539651bdbb2bb0326a1cdccd482559be94fd3575722efe9ffef59f4b35f26351635d0dcd96ed9b281d
7
- data.tar.gz: 0311fda4468da9264582b638bc8ef9c910f4ca1fa13404f7b0c507549ae1d16c4f2179a0f66b1a9c94831a820ba781cf7d6289484333fdabb07a1f48460219a7
6
+ metadata.gz: 04d5812de399b4e905d9f6ac7a28e6d465683b69b1b421e21c5df7bb04ec1aba8edcca237fb07ac348e53a64050396332e7614e12676a567e17340832d214bee
7
+ data.tar.gz: 84fcd63edbfbf2bef34de656b78e72619f111eb3982c1ec5c439b837a1f33c1e6320936488f3b339cf0b501e090fed851c0f8698b6d5b2fd1fda0a63d471bef6
data/bin/Ruby_Dice CHANGED
@@ -1,27 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
2
  BEGIN { # Checks for options
3
- if ARGV.include? "-h"
4
- puts <<HELP
3
+ if ARGV.include? "-h"
4
+ puts <<HELP
5
5
  Usage: $ Ruby_Dice [--help]
6
6
  \u00B7 --help -> Displays this help message
7
7
  Gameplay:
8
- Abbreviations:
9
- \u00B7 1 -> Ones
10
- \u00B7 2 -> Twos
11
- \u00B7 3 -> Threes
12
- \u00B7 4 -> Fours
13
- \u00B7 5 -> Fives
14
- \u00B7 6 -> Sixes
15
- \u00B7 ss -> Small Straight
16
- \u00B7 ls -> Large Straight
17
- \u00B7 tok -> Three Of A Kind
18
- \u00B7 fok -> Four Of A Kind
19
- \u00B7 fh -> Full House
20
- \u00B7 y -> Yahtzee
21
- \u00B7 ? -> Chance
8
+ \u00B7 Rolling:
9
+ \u00B7 You must not put any scoring abbreviations in your input (See Scoring Abbreviations)
10
+ \u00B7 You can only roll twice before you must score
11
+ \u00B7 Select the characters of the dice you want to roll again
12
+ \u00B7 The characters must consist of at least one of these: ZXCVB
13
+ \u00B7 They can be touching
14
+ \u00B7 They can be in any order
15
+ \u00B7 Scoring:
16
+ \u00B7 You must not roll
17
+ \u00B7 You must use an abbreviation specified in Scoring Abbreviations
18
+ \u00B7 It must be available (with the exeception of Yahztee, which can be used multiple times)
19
+ \u00B7 Scoring Abbreviations:
20
+ \u00B7 1 -> Ones
21
+ \u00B7 2 -> Twos
22
+ \u00B7 3 -> Threes
23
+ \u00B7 4 -> Fours
24
+ \u00B7 5 -> Fives
25
+ \u00B7 6 -> Sixes
26
+ \u00B7 ss -> Small Straight
27
+ \u00B7 ls -> Large Straight
28
+ \u00B7 tok -> Three Of A Kind
29
+ \u00B7 fok -> Four Of A Kind
30
+ \u00B7 fh -> Full House
31
+ \u00B7 y -> Yahtzee
32
+ \u00B7 ? -> Chance
22
33
  HELP
23
- exit
24
- end
34
+ exit
35
+ end
25
36
  }
26
37
 
27
38
  require "Ruby_Dice"
data/lib/dice.rb CHANGED
@@ -7,8 +7,6 @@ class Dice # Class for working with the 5 dice at the same time
7
7
  @values = values
8
8
  end
9
9
 
10
- # @!group Roll Methods
11
-
12
10
  =begin
13
11
  @raise [ArgumentError] if i element > 4
14
12
  @return [void]
@@ -30,7 +28,6 @@ class Dice # Class for working with the 5 dice at the same time
30
28
  initialize
31
29
  end
32
30
 
33
- # @!endgroup
34
31
 
35
32
  def to_s # @return [String] instance variable dice
36
33
  print @values
data/lib/scoresheet.rb CHANGED
@@ -56,8 +56,6 @@ class ScoreSheet # Keeps score throughout the game
56
56
  lower_score_total + upper_score_total
57
57
  end
58
58
 
59
-
60
-
61
59
  =begin
62
60
  Checks if upper score bonus can be awarded
63
61
  @return [Fixnum] 0 if raw_upper < 63
@@ -70,7 +68,7 @@ Checks if upper score bonus can be awarded
70
68
  end
71
69
  end
72
70
  =begin
73
- @return [Fixnum]
71
+ @return [Integer]
74
72
  Checks to see if you have all the of the same dice
75
73
  =end
76
74
  def yahtzee
@@ -127,7 +125,7 @@ Checks to see if you have all the of the same dice
127
125
  Replace underscores with spaces
128
126
  =end
129
127
  def format_score(score_region, index)
130
- score_label = "#{score_region[index]}".tr(?_, " ")
128
+ score_label = score_region[index].to_s.tr(?_, " ")
131
129
  cap_label score_label
132
130
  score_field = @sheet[score_region[index]]
133
131
  return justify_score(score_label, "#{score_field[1]? score_field[0]:?-}")
@@ -140,11 +138,11 @@ Replace underscores with spaces
140
138
  =begin
141
139
  @param score_label [String]
142
140
  @return [String]
143
- Capitalize each letter of each word only if the score label has two words
141
+ Capitalize each letter of each word only if the score label has two or more words
144
142
  Else only capitalize the first letter of the score label
145
143
  =end
146
144
  def cap_label(score_label)
147
- if score_label.split.length == 2
145
+ if score_label.split.length >= 2
148
146
  score_label = score_label.split.map(&:capitalize)*' '
149
147
  else
150
148
  score_label.capitalize!
data/lib/scoring.rb CHANGED
@@ -7,9 +7,10 @@ module Scoring # methods for calculating score
7
7
  LowerScores = :three_of_a_kind, :four_of_a_kind, :full_house, :small_straight, :large_straight, :chance, :yahtzee # The fields on the bottom section of the score sheet
8
8
 
9
9
  =begin
10
- Checks to see if you have 3 of one kind of dice and 2 of another
11
- @return [Fixnum] 25 if @dice.dice contains 3 of one Fixnum and 2 of another
12
- @return [Fixnum] 0 if @dice.dice does not contain 3 of one Fixnum and 2 of another
10
+ @param dice [Array<Fixnum>] The dice to be tested
11
+ Checks to see if dice has 3 of one kind of dice and 2 of another
12
+ @return [Fixnum] 25 if dice contains 3 of one Fixnum and 2 of another
13
+ @return [Fixnum] 0 if dice does not contain 3 of one Fixnum and 2 of another
13
14
  =end
14
15
  def full_house(dice)
15
16
  f_table = freq dice
@@ -19,10 +20,11 @@ Checks to see if you have 3 of one kind of dice and 2 of another
19
20
  end
20
21
 
21
22
  =begin
23
+ @param dice [Array<Fixnum>] The dice to be tested
22
24
  Checks to see if you have 4 of the same dice
23
25
  @return [Fixnum] 0 if <= 4 indices have the same value
24
26
  @return [Fixnum] dice.reduce(:+) if >= 4 indices have the same value
25
- @see (#three_of_a_kind)
27
+ @see (three_of_a_kind)
26
28
  =end
27
29
  def four_of_a_kind(dice)
28
30
  of_a_kind dice, 4
@@ -30,28 +32,48 @@ Checks to see if you have 4 of the same dice
30
32
 
31
33
  =begin
32
34
  @param d [Array<Fixnum>] the dice to be tested
33
- @return [Fixnum] the score
35
+ @return [Fixnum] the total of all the ones
34
36
  =end
35
37
  def ones(d)
36
38
  single_face d, 1
37
39
  end
38
40
 
39
- def twos(d) # @see (#ones)
41
+ =begin
42
+ @param d [Array<Fixnum>] the dice to be tested
43
+ @return [Fixnum] the total of all the twos
44
+ =end
45
+ def twos(d)
40
46
  single_face d, 2
41
47
  end
42
48
 
43
- def threes(d) # @see (#ones)
49
+ =begin
50
+ @param d [Array<Fixnum>] the dice to be tested
51
+ @return [Fixnum] the score
52
+ =end
53
+ def threes(d)
44
54
  single_face d, 3
45
55
  end
46
56
 
47
- def fours(d) # @see (#ones)
57
+ =begin
58
+ @param d [Array<Fixnum>] the dice to be tested
59
+ @return [Fixnum] the score
60
+ =end
61
+ def fours(d)
48
62
  single_face d, 4
49
63
  end
50
-
51
- def fives(d) # @see (#ones)
64
+
65
+ =begin
66
+ @param d [Array<Fixnum>] the dice to be tested
67
+ @return [Fixnum] the score
68
+ =end
69
+ def fives(d)
52
70
  single_face d, 5
53
71
  end
54
72
 
73
+ =begin
74
+ @param d [Array<Fixnum>] the dice to be tested
75
+ @return [Fixnum] the score
76
+ =end
55
77
  def sixes(d) # @see (#ones)
56
78
  single_face d, 6
57
79
  end
@@ -78,7 +100,7 @@ Checks to see if you have 3 of the same dice
78
100
  @param dice [Array<Fixnum>] the dice to be tested
79
101
  @return [Fixnum] 30 if there are 3 consecutive Fixnums in dice
80
102
  @return [Fixnum] 0 if there are not three conscecutive Fixnums in dice
81
- @see (#large_straight)
103
+ @see (large_straight)
82
104
  =end
83
105
  def small_straight(dice)
84
106
  straight dice, 4, 30
@@ -89,7 +111,7 @@ Checks to see if you have 3 of the same dice
89
111
  @param dice [Array<Fixnum>] the dice to be tested
90
112
  @return [Fixnum] 40 if there are 4 consecutive Fixnums in dice
91
113
  @return [Fixnum] 0 if there are not three conscecutive Fixnums in dice
92
- @see (#small_straight)
114
+ @see (small_straight)
93
115
  =end
94
116
  def large_straight(dice)
95
117
  straight dice, 5, 40
@@ -98,32 +120,32 @@ Checks to see if you have 3 of the same dice
98
120
 
99
121
  private # Helper methods for score calculation
100
122
 
101
- def single_face(dice, value)
102
- v = dice.select{|number| number == value}.reduce :+
103
- unless v.nil?
104
- return v
105
- else
106
- return 0
107
- end
123
+ def single_face(dice, value)
124
+ v = dice.select{|number| number == value}.reduce :+
125
+ unless v.nil?
126
+ return v
127
+ else
128
+ return 0
108
129
  end
130
+ end
109
131
 
110
- def freq(dice)
111
- dice.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
112
- end
132
+ def freq(dice)
133
+ dice.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
134
+ end
113
135
 
114
- def modal_frequency(dice)
115
- freq(dice).max_by{|k,v| v}[1]
116
- end
136
+ def modal_frequency(dice)
137
+ freq(dice).max_by{|k,v| v}[1]
138
+ end
117
139
 
118
- def of_a_kind(dice, limit)
119
- if modal_frequency(dice) >= limit
120
- dice.reduce :+
121
- else
122
- 0
123
- end
140
+ def of_a_kind(dice, limit)
141
+ if modal_frequency(dice) >= limit
142
+ dice.reduce :+
143
+ else
144
+ 0
124
145
  end
146
+ end
125
147
 
126
- =begin
148
+ =begin
127
149
  @param dice [Fixnum] the dice to be tested
128
150
  @param limit [Fixnum] = 4 for small straight
129
151
  @param limit [Fixnum] = 5 for large straight
@@ -132,14 +154,11 @@ common code for both small straight (SS) and large straight (LS)
132
154
  @return [Fixnum] score
133
155
  =end
134
156
  def straight(dice, limit, score)
135
- #each_cons is generating every possible value for a straight of length limit
136
- (1..6).each_cons(limit).each do |i|
137
- # Asking if i is a subset of dice
138
- if (i - dice).empty?
157
+ (1..6).each_cons(limit).each do |i| #each_cons is generating every possible value for a straight of length limit
158
+ if (i - dice).empty? # Asking if i is a subset of dice
139
159
  return score if (i - dice)
140
160
  end
141
161
  end
142
162
  return 0
143
163
  end
144
-
145
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Ruby_Dice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-27 00:00:00.000000000 Z
12
+ date: 2014-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -76,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: 1.9.2
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 1.3.1
81
+ version: '0'
82
82
  requirements:
83
83
  - Terminal
84
84
  rubyforge_project: