bb-jouer 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/bin/jouer +20 -0
- data/lib/bb_jouer.rb +223 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
YWQzODMxYTMyYjkzOGNiNWZkODU2ZmEyZGM0NGY4MTQ0MDZhZjVlMQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
NDUxZGI4NGJiNDA0OTNhNzM4M2IwNGIyNTU3OWZiZWM2YTA1MmU5OQ==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
MjJjMmZmMGM0NDgzNTI2ZmZmNzMxNTRmY2MwOTU1OTVmNjc4YmRhZjA4ZTA5
|
|
10
|
+
YTI3OTU4ZWFkMWUzNTQ1ZTY0NWI0NjE5Njk5MDAwMjc1YjlhNDViNTA0NWFk
|
|
11
|
+
MTc1Mjk1Yjc3MmU1NjA2ODBjMjBmZGYyYmIzNzg4MzE5YzgwNWM=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
NjJjMTEwNDViN2I1OGY5NjRmYzI5OGM0ZmU2MGM5M2UzNDEzNzliYmJlODlm
|
|
14
|
+
MTZkMzg3ZDZjNTY4ZGNiMDgxNWNhODkyYzUwNjdiMDViZGFjZTYyMmZiNWMz
|
|
15
|
+
ZjVkNDY1YTM1M2I2NjE0MmI1NDU0YTIwYmU5NTcyYzZjZTg0OTE=
|
data/bin/jouer
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require './lib/bb_jouer.rb'
|
|
3
|
+
|
|
4
|
+
@p = BbJouer.new
|
|
5
|
+
puts "Play Ball!!!!"
|
|
6
|
+
puts "First Player is Robinson Cano of the Seattle Mariners - Hit Go to configure batting situation."
|
|
7
|
+
@p.build_stat_table
|
|
8
|
+
until @p.over?
|
|
9
|
+
puts "Playing at Home? (y or n)"
|
|
10
|
+
home = gets.chomp.capitalize
|
|
11
|
+
puts "Lefty on the Mound? (y or n)"
|
|
12
|
+
pitcher = gets.chomp.capitalize
|
|
13
|
+
puts "Runner on First? (y or n)"
|
|
14
|
+
first = gets.chomp.capitalize
|
|
15
|
+
puts "Runner on Second? (y or n)"
|
|
16
|
+
second = gets.chomp.capitalize
|
|
17
|
+
puts "Runner on Third? (y or n)"
|
|
18
|
+
third = gets.chomp.capitalize
|
|
19
|
+
puts @p.calculate_chances(home,pitcher,first,second,third)
|
|
20
|
+
end
|
data/lib/bb_jouer.rb
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
class BbJouer
|
|
2
|
+
attr_accessor :player
|
|
3
|
+
def initialize
|
|
4
|
+
@player = {:PA => 681, :H=> 190, :D=>41,:T=>0,:HR=>27,:BB=>65,:SO=>85,:HBP=>6,:SAC=>5,:BA=>314,:OBP=>383,:SLG=>516,
|
|
5
|
+
:OPS=>899,:OPSplus=>145,:BR=>398,:BRS=>81,:BRSpc=>20,:TB=>312,:AB=>605,
|
|
6
|
+
:PA3B=>49,:PA3BS =>28,:PA3BSpc=>57,:PA2B=>32,:PA2Badv=>18,:PA2Badvpc=>56}
|
|
7
|
+
end
|
|
8
|
+
#stat table
|
|
9
|
+
def build_stat_table
|
|
10
|
+
#test_stat_table = Array.new(1000)
|
|
11
|
+
#test_stat_table.length
|
|
12
|
+
@stat_table = Array.new(@player[:H]){|v| v="Base Hit"}
|
|
13
|
+
@stat_table = @stat_table + Array.new(@player[:D]){"Double"}
|
|
14
|
+
@stat_table = @stat_table + Array.new(@player[:T]){"Trible"}
|
|
15
|
+
@stat_table = @stat_table + Array.new(@player[:HR]){"Home Run"}
|
|
16
|
+
@stat_table = @stat_table + Array.new(@player[:BB]){"Ball Four!"}
|
|
17
|
+
@stat_table = @stat_table + Array.new(@player[:SO]){"Strike Three!"}
|
|
18
|
+
#@stat_table = stat_table + Array.new(@player[:BA]-stat_table.length){"Sacrafice"}
|
|
19
|
+
@stat_table = @stat_table + Array.new(@player[:HBP]){"Hit By Pitch"}
|
|
20
|
+
@stat_table = @stat_table + Array.new(@player[:SAC]){"Sacrafice"}
|
|
21
|
+
@stat_table = @stat_table + Array.new(1000-@stat_table.length){"Outta There!"}
|
|
22
|
+
@stat_table.length
|
|
23
|
+
end
|
|
24
|
+
#confirm obs
|
|
25
|
+
def confirm_ops
|
|
26
|
+
@player[:OBP] + @player[:SLG]
|
|
27
|
+
end
|
|
28
|
+
def confirm_slg
|
|
29
|
+
#(312.fdiv(605).round(3)*1000).to_i
|
|
30
|
+
(@player[:TB].fdiv(@player[:AB]).round(3)*1000).to_i
|
|
31
|
+
end
|
|
32
|
+
def slg
|
|
33
|
+
@player[:SLG]
|
|
34
|
+
end
|
|
35
|
+
def ops
|
|
36
|
+
@player[:OPS]
|
|
37
|
+
end
|
|
38
|
+
def obp
|
|
39
|
+
@player[:OBP]
|
|
40
|
+
end
|
|
41
|
+
def slg
|
|
42
|
+
@player[:SLG]
|
|
43
|
+
end
|
|
44
|
+
#batting average
|
|
45
|
+
def ba
|
|
46
|
+
@player[:BA]
|
|
47
|
+
end
|
|
48
|
+
#plate appearances
|
|
49
|
+
def pa
|
|
50
|
+
@player[:PA]
|
|
51
|
+
end
|
|
52
|
+
def calculate_chances home,pitcher,runner1, runner2,runner3
|
|
53
|
+
@runner_0 = false
|
|
54
|
+
@runner_1 = false
|
|
55
|
+
@runner_2 = false
|
|
56
|
+
@runner_3 = false
|
|
57
|
+
@runner_1_2 = false
|
|
58
|
+
@runner_1_3 = false
|
|
59
|
+
@runner_2_3 = false
|
|
60
|
+
@runner_1_2_3 = false
|
|
61
|
+
puts "\n"
|
|
62
|
+
puts "Situation:"
|
|
63
|
+
if home == 'Y'
|
|
64
|
+
puts " - Playing at Home"
|
|
65
|
+
else
|
|
66
|
+
puts " - On the Road"
|
|
67
|
+
end
|
|
68
|
+
if pitcher == 'Y'
|
|
69
|
+
puts " - Batting against a Lefty"
|
|
70
|
+
else
|
|
71
|
+
puts " - Batting against a Righty"
|
|
72
|
+
end
|
|
73
|
+
if runner1 == 'N' && runner2 == 'N' && runner3 == 'N'
|
|
74
|
+
@runner_0 = true
|
|
75
|
+
puts " - The Bases are Empty"
|
|
76
|
+
elsif runner1 == 'Y' && runner2 == 'Y' && runner3 == 'Y'
|
|
77
|
+
@runner_1_2_3 = true
|
|
78
|
+
puts " - The Bases are Loaded!"
|
|
79
|
+
elsif runner1 == 'Y' && runner2 == 'Y'
|
|
80
|
+
@runner_1_2 = true
|
|
81
|
+
puts " - Runners on First and Second"
|
|
82
|
+
elsif runner1 == 'Y' && runner3 == 'Y'
|
|
83
|
+
@runner_1_3 = true
|
|
84
|
+
puts " - Runners on First and Third"
|
|
85
|
+
elsif runner2 == 'Y' && runner3 == 'Y'
|
|
86
|
+
@runner_2_3 = true
|
|
87
|
+
puts " - Runners on Second and Third"
|
|
88
|
+
elsif runner1 == 'Y'
|
|
89
|
+
@runner_1 = true
|
|
90
|
+
puts " - Runner on First"
|
|
91
|
+
elsif runner2 == 'Y'
|
|
92
|
+
@runner_2 = true
|
|
93
|
+
puts " - Runner on Second"
|
|
94
|
+
elsif runner3 == 'Y'
|
|
95
|
+
@runner_3 = true
|
|
96
|
+
puts " - Runner on Third"
|
|
97
|
+
elsif runner2 == 'Y' && runner3 == 'Y'
|
|
98
|
+
@runner_2_3 = true
|
|
99
|
+
puts " - Runners on Second and Third"
|
|
100
|
+
end
|
|
101
|
+
determine_probability
|
|
102
|
+
end
|
|
103
|
+
def determine_probability
|
|
104
|
+
@stat = @stat_table.sample
|
|
105
|
+
put_result
|
|
106
|
+
end
|
|
107
|
+
def put_result
|
|
108
|
+
puts "The fans await the pitch...."
|
|
109
|
+
puts "\n"
|
|
110
|
+
sleep(3)
|
|
111
|
+
case @stat
|
|
112
|
+
when "Ball Four!" || "Hit By Pitch"
|
|
113
|
+
if @runner_1_2_3
|
|
114
|
+
puts "#{@stat} - 1 run scores - The Bases are still loaded"
|
|
115
|
+
elsif @runner_2_3
|
|
116
|
+
puts "#{@stat} - The Bases are now loaded"
|
|
117
|
+
elsif @runner_1_2
|
|
118
|
+
puts "#{@stat} - The Bases are now loaded"
|
|
119
|
+
elsif @runner_1_3
|
|
120
|
+
puts "#{@stat} - The Bases are now loaded"
|
|
121
|
+
elsif @runner_1
|
|
122
|
+
puts "#{@stat} - Runners are now on First and Second"
|
|
123
|
+
elsif @runner_2
|
|
124
|
+
puts "#{@stat} - Runners are now on First and Second"
|
|
125
|
+
elsif @runner_3
|
|
126
|
+
puts "#{@stat} - Runners are now on First and Third"
|
|
127
|
+
else
|
|
128
|
+
puts "#{@stat} - a Runner is now on first"
|
|
129
|
+
end
|
|
130
|
+
when "Strike Three!"
|
|
131
|
+
puts "#{@stat} - He Struck him out!"
|
|
132
|
+
when "Sacrafice"
|
|
133
|
+
if @runner_1_2_3
|
|
134
|
+
puts "#{@stat} - 1 run scores on a tag up - Runners advance and now on second and third"
|
|
135
|
+
elsif @runner_2_3
|
|
136
|
+
puts "#{@stat} - Runner tags - 1 run scores and runner advances to third"
|
|
137
|
+
elsif @runner_1_2
|
|
138
|
+
puts "#{@stat} - Runners tag and move up a base to second and third"
|
|
139
|
+
elsif @runner_1_3
|
|
140
|
+
puts "#{@stat} - Runner tags and 1 runn scores"
|
|
141
|
+
elsif @runner_1
|
|
142
|
+
puts "#{@stat} - Runners tages and now in scoring postion at second base!"
|
|
143
|
+
elsif @runner_2
|
|
144
|
+
puts "#{@stat} - Runner tags and moves over to third"
|
|
145
|
+
elsif @runner_3
|
|
146
|
+
puts "#{@stat} - Runner tags up and scores!"
|
|
147
|
+
else
|
|
148
|
+
puts "#{@stat} - Runner thrown out at first trying to bunt for a base hit."
|
|
149
|
+
end
|
|
150
|
+
when "Base Hit"
|
|
151
|
+
if @runner_1_2_3
|
|
152
|
+
puts "#{@stat} - 2 runs score - Runners now on first and third"
|
|
153
|
+
elsif @runner_2_3
|
|
154
|
+
puts "#{@stat} - 2 runs score - Runner now on first base"
|
|
155
|
+
elsif @runner_1_2
|
|
156
|
+
puts "#{@stat} - 1 run scores - Runners now on first and third"
|
|
157
|
+
elsif @runner_1_3
|
|
158
|
+
puts "#{@stat} - 1 run scores - runners now on first and second"
|
|
159
|
+
elsif @runner_1
|
|
160
|
+
puts "#{@stat} - Runners now on first and second!"
|
|
161
|
+
elsif @runner_2
|
|
162
|
+
puts "#{@stat} - 1 run scores - Runner now on first"
|
|
163
|
+
elsif @runner_3
|
|
164
|
+
puts "#{@stat} - 1 run scores - Runner now on first"
|
|
165
|
+
else
|
|
166
|
+
puts "#{@stat} - Runner now on First Base."
|
|
167
|
+
end
|
|
168
|
+
when "Double"
|
|
169
|
+
if @runner_1_2_3
|
|
170
|
+
puts "#{@stat} - 2 Runs Score - Runners now on second and third"
|
|
171
|
+
elsif @runner_2_3
|
|
172
|
+
puts "#{@stat} - 2 Run Scores - Runner now on second"
|
|
173
|
+
elsif @runner_1_2
|
|
174
|
+
puts "#{@stat} - 1 Run Scores - Runners now on second and third"
|
|
175
|
+
elsif @runner_1_3
|
|
176
|
+
puts "#{@stat} - 1 run scores - runners now on second and third"
|
|
177
|
+
elsif @runner_1
|
|
178
|
+
puts "#{@stat} - Runners now on second and third"
|
|
179
|
+
elsif @runner_2
|
|
180
|
+
puts "#{@stat} - 1 run scores - Runner in scoring position"
|
|
181
|
+
elsif @runner_3
|
|
182
|
+
puts "#{@stat} - 1 run scores - Runner in scoring position"
|
|
183
|
+
else
|
|
184
|
+
puts "#{@stat} - Runner now on Second Base."
|
|
185
|
+
end
|
|
186
|
+
when "Triple"
|
|
187
|
+
if @runner_1_2_3
|
|
188
|
+
puts "#{@stat} - 3 runs score!"
|
|
189
|
+
elsif @runner_1_2 || @runner_2_3
|
|
190
|
+
puts "#{@stat} - 2 runs score - Runner now on third"
|
|
191
|
+
elsif @runner_1 || @runner_2 || @runner_3
|
|
192
|
+
puts "#{@stat} - 1 run scores - Runner now on third"
|
|
193
|
+
else
|
|
194
|
+
puts "#{@stat} - Runner now on third base"
|
|
195
|
+
end
|
|
196
|
+
when "Home Run"
|
|
197
|
+
if @runner_1_2_3
|
|
198
|
+
puts "#{@stat} - Grand Slam - 4 runs score!"
|
|
199
|
+
elsif @runner_1_2 || @runner_2_3
|
|
200
|
+
puts "#{@stat} - 3 runs score!"
|
|
201
|
+
elsif @runner_1 || @runner_2 || @runner_3
|
|
202
|
+
puts "#{@stat} - 2 run scores!"
|
|
203
|
+
else
|
|
204
|
+
puts "#{@stat} - Add one more to the score board!"
|
|
205
|
+
end
|
|
206
|
+
else
|
|
207
|
+
puts "#{@stat}"
|
|
208
|
+
end
|
|
209
|
+
sleep(3)
|
|
210
|
+
puts "\n"
|
|
211
|
+
puts "Hit Enter to Continue with another scenario or exit to quit"
|
|
212
|
+
end
|
|
213
|
+
def over?
|
|
214
|
+
@input = gets.chomp
|
|
215
|
+
if @input == "exit" || @input == 'quit' || @input == 'q'
|
|
216
|
+
true
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def <=>(other)
|
|
221
|
+
@stat <=> other.stat
|
|
222
|
+
end
|
|
223
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bb-jouer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- David L Baynes
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Run 'jouer' in terminal after installing
|
|
14
|
+
email: dlbaynes@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- jouer
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/bb_jouer.rb
|
|
21
|
+
- bin/jouer
|
|
22
|
+
homepage: https://github.com/dbaynes/bb-jouer
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ! '>='
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ! '>='
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.1.8
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Elementary simulated results from a batter in certain limited situations
|
|
46
|
+
test_files: []
|