mirror of
https://github.com/samsonjs/mystery7-simulator.git
synced 2026-06-30 05:49:36 +00:00
add options to dump results and wins
This commit is contained in:
parent
4ea9183426
commit
68b8a4d1ef
2 changed files with 27 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ class Roulette
|
|||
# best
|
||||
BettingSequence = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 8, 10, 12, 15, 18]
|
||||
|
||||
attr_accessor :results, :counts, :set_status
|
||||
attr_accessor :results, :counts, :set_status, :wins
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
|
|
@ -64,13 +64,14 @@ class Roulette
|
|||
end
|
||||
|
||||
@results = []
|
||||
@wins = []
|
||||
@counts = Hash.new { 0 }
|
||||
|
||||
@options[:spins].times do
|
||||
result = spin
|
||||
record(result) if @options[:record]
|
||||
if @results.length % 100_000 == 0
|
||||
print @results.length / 100000
|
||||
print @results.length / 100_000
|
||||
elsif @results.length % 10_000 == 0
|
||||
print '.'
|
||||
end
|
||||
|
|
@ -89,6 +90,7 @@ class Roulette
|
|||
status[:sleeping] = false
|
||||
else
|
||||
net = @net_profits[status[:sequence]]
|
||||
@wins << { :set => letter, :sequence => 1 + status[:sequence] }
|
||||
status[:net] += net
|
||||
status[:sequence] = 0
|
||||
status[:wins] += 1
|
||||
|
|
|
|||
31
simulate.rb
31
simulate.rb
|
|
@ -9,6 +9,8 @@ def main
|
|||
options = Trollop::options do
|
||||
opt :american, "American style, with 00", :short => 'a', :default => true
|
||||
opt :database, "Filename for results database", :type => String, :default => File.expand_path("~/Projects/Mystery7/results.sqlite")
|
||||
opt :'dump-results', "Dump results to results.csv in Dropbox"
|
||||
opt :'dump-wins', "Dump wins to wins.csv in Dropbox"
|
||||
opt :european, "European style, without 00", :short => 'e', :default => false
|
||||
opt :misses, "Number of misses before sleeping", :short => 'm', :default => 4
|
||||
opt :record, "Record results", :short => 'r'
|
||||
|
|
@ -31,7 +33,8 @@ def main
|
|||
:wins => 0
|
||||
}
|
||||
|
||||
# all_results = []
|
||||
all_results = []
|
||||
all_wins = []
|
||||
|
||||
options[:sessions].times do
|
||||
|
||||
|
|
@ -62,7 +65,8 @@ def main
|
|||
puts "Snakes: #{status[:snakes]}"
|
||||
end
|
||||
|
||||
# all_results += roulette.results
|
||||
all_results += roulette.results if options[:'dump-results']
|
||||
all_wins += roulette.wins if options[:'dump-wins']
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -70,12 +74,23 @@ def main
|
|||
puts "Wins: #{overall_status[:wins]}"
|
||||
puts "Snakes: #{overall_status[:snakes]}"
|
||||
|
||||
# File.open(File.expand_path('~/Dropbox/Mystery7/results.csv'), 'w') do |f|
|
||||
# f.puts('Roll, Net, Cumulative Net')
|
||||
# all_results.each do |result|
|
||||
# f.puts("#{result[:roll]}, #{result[:net]}, #{result[:cumulative_net]}")
|
||||
# end
|
||||
# end
|
||||
if options[:'dump-results']
|
||||
File.open(File.expand_path('~/Dropbox/Mystery7/results.csv'), 'w') do |f|
|
||||
f.puts('Roll, Net, Cumulative Net')
|
||||
all_results.each do |result|
|
||||
f.puts("#{result[:roll]}, #{result[:net]}, #{result[:cumulative_net]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if options[:'dump-wins']
|
||||
File.open(File.expand_path('~/Dropbox/Mystery7/wins.csv'), 'w') do |f|
|
||||
f.puts('Set, Sequence')
|
||||
all_wins.each do |win|
|
||||
f.puts("#{win[:set]}, #{win[:sequence]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts ">>> Results are in #{options[:database]}." if options[:record]
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue