forked from stinkystanotter/playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
score_helpers.rb
205 lines (163 loc) · 4.54 KB
/
score_helpers.rb
1
2
3
4
5
6
7
8
9
10
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#playing with some scoring methods
def calc_ba(h,ab)
ba = (h.to_f/ab.to_f)
# sprintf("%.3f",ba)[-4,4]
end
def calc_era(er, ip)
era = 9 * er.to_f / ip.to_f
end
def calc_whip(h,bb,ip)
whip = (h.to_f + bb.to_f)/ ip.to_f
end
def assign_cat_pts(*cat_scores)
#validate
#####WILL NEED TO VALIDATE FIRST ARGUMENT IS EITHER 2 OR 3
#
#pts_available = *(1..num_players).inject(0){|sum,item| sum + item}
if cat_scores.size == 2
pts_available = 3
else
pts_available = 6
end
#score
puts "POINTS TO GET:"
puts pts_available
puts "\n"
#cat_scores.each { |s| puts s}
#array.each_with_index.max = [maximum value, index of that value]
# dumb way 1
#original Jake method
#biggest_ind = 0
#biggest = cat_scores[biggest_ind]
#smallest_ind = 0
#smallest = cat_scores[smallest_ind]
#cat_scores.each_with_index do |v,k|
#puts k.inspect
#puts v.inspect
# if v > biggest
# biggest_ind = k
# biggest = v
# end
# if v < smallest
# smallest_ind = k
# smallest = v
# end
#end
#let's try it with min, max
biggest = cat_scores.max
smallest = cat_scores.min
biggest_ind = cat_scores.index(cat_scores.max)
smallest_ind = cat_scores.index(cat_scores.min)
returner = []
if cat_scores.size == 2
returner[smallest_ind] = 1
returner[biggest_ind] = 2
if biggest == smallest
returner = [1.5, 1.5]
end
else
### THREE (3) categories to compare
if cat_scores.uniq.length == 1
returner = [2,2,2]
end
if cat_scores.uniq.length == 3
returner[smallest_ind] = 1
returner[biggest_ind] = 3
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 2
end
if cat_scores.uniq.length == 2
if cat_scores.count(biggest) == 2
returner[smallest_ind] = 1
returner[biggest_ind] = 2.5
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 2.5
#### 2 SMALLESTS
else
returner[smallest_ind] = 1.5
returner[biggest_ind] = 3
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 1.5
end
end
end
puts "Method will return: " + returner.inspect
puts "\n"
puts "\nnumber of scores: "+cat_scores.size.inspect
puts "\nbiggest: "+biggest.to_s
puts "\n"+biggest_ind.to_s
puts "\nsmallest: "+smallest.to_s
puts "\n"+smallest_ind.to_s
returner
end
def assign_cat_pts_low(*cat_scores)
#validate
#####WILL NEED TO VALIDATE EITHER 2 OR 3
#
if cat_scores.size == 2
pts_available = 3
else
pts_available = 6
end
#score
puts "POINTS TO GET:"
puts pts_available
puts "\n"
#array.each_with_index.max = [maximum value, index of that value]
#let's try it with min, max
biggest = cat_scores.max
smallest = cat_scores.min
biggest_ind = cat_scores.index(cat_scores.max)
smallest_ind = cat_scores.index(cat_scores.min)
#two players
returner = []
if cat_scores.size == 2
returner[smallest_ind] = 2
returner[biggest_ind] = 1
#two players tie
if biggest == smallest
returner = [1.5, 1.5]
end
else
# three players 3-way tie
if cat_scores.uniq.length == 1
returner = [2,2,2]
end
# three players
if cat_scores.uniq.length == 3
returner[smallest_ind] = 3
returner[biggest_ind] = 1
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 2
end
# three players high-value tie
if cat_scores.uniq.length == 2
if cat_scores.count(biggest) == 2
returner[smallest_ind] = 3
returner[biggest_ind] = 1.5
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 1.5
# three players low-value tie
else
returner[smallest_ind] = 2.5
returner[biggest_ind] = 1
all = [0,1,2]
have = [smallest_ind,biggest_ind]
returner[(all - have)[0].to_i] = 2.5
end
end
end
puts "Method will return: " + returner.inspect
puts "\n"
puts "\nnumber of scores: "+cat_scores.size.inspect
puts "\nbiggest: "+biggest.to_s
puts "\n"+biggest_ind.to_s
puts "\nsmallest: "+smallest.to_s
puts "\n"+smallest_ind.to_s
returner
end