mirror of
https://github.com/samsonjs/mystery7-simulator.git
synced 2026-04-27 15:07:42 +00:00
mystery16 support
This commit is contained in:
parent
cf8a859d97
commit
1704fc05ce
2 changed files with 56 additions and 30 deletions
72
roulette.rb
72
roulette.rb
|
|
@ -5,43 +5,59 @@ require 'sqlite3'
|
||||||
class Roulette
|
class Roulette
|
||||||
|
|
||||||
Sets = {
|
Sets = {
|
||||||
:j => [1, 2, 3, 13, 15, 26, 27],
|
:mystery7 => {
|
||||||
:k => [4, 5, 6, 16, 17, 28, 30],
|
:j => [1, 2, 3, 13, 15, 26, 27],
|
||||||
:m => [7, 8, 19, 20, 21, 31, 32],
|
:k => [4, 5, 6, 16, 17, 28, 30],
|
||||||
:c => [11, 12, 22, 24, 34, 35, 36],
|
:m => [7, 8, 19, 20, 21, 31, 32],
|
||||||
:n => [9, 10, 14, 18, 23, 25, 29],
|
:c => [11, 12, 22, 24, 34, 35, 36],
|
||||||
:z => [0, 2, 16, 19, 33, 36]
|
:n => [9, 10, 14, 18, 23, 25, 29],
|
||||||
|
:z => [0, 2, 16, 19, 33, 36]
|
||||||
|
},
|
||||||
|
:mystery16 => {
|
||||||
|
:j => [0, 1, 2, 3, 13, 15, 26, 27, 11, 12, 22, 24, 33, 34, 35, 36]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# original
|
BettingSequences = {
|
||||||
# BettingSequence = [1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 8, 10, 12, 15]
|
# original
|
||||||
|
# :mystery7 => [1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 8, 10, 12, 15],
|
||||||
|
|
||||||
# better
|
# better
|
||||||
# BettingSequence = [1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 10, 12, 15, 18]
|
# :mystery7 => [1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 10, 12, 15, 18],
|
||||||
|
|
||||||
# best
|
# best
|
||||||
BettingSequence = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 8, 10, 12, 15, 18]
|
:mystery7 => [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 8, 10, 12, 15, 18],
|
||||||
|
|
||||||
|
:mystery16 => [1, 2, 4, 8, 16, 25, 50, 100]
|
||||||
|
}
|
||||||
|
|
||||||
attr_accessor :results, :counts, :set_status, :wins, :closing
|
attr_accessor :results, :counts, :set_status, :wins, :closing
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = options
|
@options = options
|
||||||
@sets = {}
|
@sets = {}
|
||||||
Sets.keys.each do |key|
|
sets = Sets[@options[:set]]
|
||||||
@sets[key] = Sets[key].dup
|
sets.keys.each do |key|
|
||||||
|
@sets[key] = sets[key].dup
|
||||||
end
|
end
|
||||||
if @options[:american]
|
|
||||||
@sets[:z] << 37
|
if @options[:mystery7]
|
||||||
else
|
if @options[:american]
|
||||||
@sets[:z].insert(2, 5)
|
@sets[:z] << 37
|
||||||
|
else
|
||||||
|
@sets[:z].insert(2, 5)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# generated numbers are from 0 to max
|
# generated numbers are from 0 to max
|
||||||
@max = @options[:american] ? 38 : 37
|
@max = @options[:american] ? 38 : 37
|
||||||
|
|
||||||
@net_profits = net_profits_for_sequence(BettingSequence)
|
@multiplier = @options[:mystery16] ? 16 : 7
|
||||||
|
@betting_sequence = BettingSequences[@options[:set]]
|
||||||
|
|
||||||
|
@net_profits = net_profits_for_sequence(@betting_sequence)
|
||||||
puts "Profit sequence: #{@net_profits.join(', ')}"
|
puts "Profit sequence: #{@net_profits.join(', ')}"
|
||||||
@snake_penalty = snake_penalty_for_sequence(BettingSequence)
|
@snake_penalty = snake_penalty_for_sequence(@betting_sequence)
|
||||||
puts "Snake penalty: #{@snake_penalty}"
|
puts "Snake penalty: #{@snake_penalty}"
|
||||||
|
|
||||||
@cumulative_net = 0
|
@cumulative_net = 0
|
||||||
|
|
@ -49,7 +65,7 @@ class Roulette
|
||||||
|
|
||||||
def simulate
|
def simulate
|
||||||
@set_status = {}
|
@set_status = {}
|
||||||
Sets.keys.each do |letter|
|
@sets.keys.each do |letter|
|
||||||
@set_status[letter] = {
|
@set_status[letter] = {
|
||||||
:net => 0,
|
:net => 0,
|
||||||
:sequence => 0,
|
:sequence => 0,
|
||||||
|
|
@ -68,7 +84,7 @@ class Roulette
|
||||||
@rng = @options[:seed] ? Random.new(@options[:seed]) : Random.new
|
@rng = @options[:seed] ? Random.new(@options[:seed]) : Random.new
|
||||||
|
|
||||||
@options[:spins].times do |i|
|
@options[:spins].times do |i|
|
||||||
break if @options[:spins] - i < 10 && @cumulative_net > 100
|
break if @options[:mystery7] && @options[:spins] - i < 10 && @cumulative_net > 100
|
||||||
result = spin
|
result = spin
|
||||||
record(result) if @options[:record]
|
record(result) if @options[:record]
|
||||||
if @results.length % 100_000 == 0
|
if @results.length % 100_000 == 0
|
||||||
|
|
@ -77,7 +93,7 @@ class Roulette
|
||||||
print '.'
|
print '.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @cumulative_net < 100
|
if @options[:mystery7] && @cumulative_net < 100
|
||||||
@closing = true
|
@closing = true
|
||||||
spin until closed?
|
spin until closed?
|
||||||
end
|
end
|
||||||
|
|
@ -121,10 +137,10 @@ class Roulette
|
||||||
status[:ghost_sequence] += 1
|
status[:ghost_sequence] += 1
|
||||||
end
|
end
|
||||||
# snake
|
# snake
|
||||||
if status[:sequence] >= BettingSequence.length
|
if status[:sequence] >= @betting_sequence.length
|
||||||
puts "#{letter}: SNAKE!" if @options[:verbose]
|
puts "#{letter}: SNAKE!" if @options[:verbose]
|
||||||
status[:sequence] = 0
|
status[:sequence] = 0
|
||||||
status[:sleeping] = true
|
status[:sleeping] = true if @options[:sleep]
|
||||||
if closing
|
if closing
|
||||||
status[:closed] = true
|
status[:closed] = true
|
||||||
puts "[snake] closed set #{letter} on spin #{@results.length + 1}" if @options[:verbose]
|
puts "[snake] closed set #{letter} on spin #{@results.length + 1}" if @options[:verbose]
|
||||||
|
|
@ -133,7 +149,7 @@ class Roulette
|
||||||
status[:net] -= @snake_penalty
|
status[:net] -= @snake_penalty
|
||||||
net -= @snake_penalty
|
net -= @snake_penalty
|
||||||
end
|
end
|
||||||
if status[:sequence] > 0 && status[:sequence] % @options[:misses] == 0
|
if @options[:sleep] && status[:sequence] > 0 && status[:sequence] % @options[:misses] == 0
|
||||||
status[:sleeping] = true
|
status[:sleeping] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -168,12 +184,12 @@ class Roulette
|
||||||
total_per_number = 0
|
total_per_number = 0
|
||||||
sequence.map do |n|
|
sequence.map do |n|
|
||||||
total_per_number += n
|
total_per_number += n
|
||||||
36 * n - 7 * total_per_number
|
36 * n - @multiplier * total_per_number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def snake_penalty_for_sequence(sequence)
|
def snake_penalty_for_sequence(sequence)
|
||||||
7 * sequence.inject(0) { |sum, n| sum + n }
|
@multiplier * sequence.inject(0) { |sum, n| sum + n }
|
||||||
end
|
end
|
||||||
|
|
||||||
def db
|
def db
|
||||||
|
|
|
||||||
14
simulate.rb
14
simulate.rb
|
|
@ -13,15 +13,25 @@ def main
|
||||||
opt :'dump-wins', "Dump wins to wins.csv in Dropbox"
|
opt :'dump-wins', "Dump wins to wins.csv in Dropbox"
|
||||||
opt :european, "European style, without 00", :short => 'e', :default => false
|
opt :european, "European style, without 00", :short => 'e', :default => false
|
||||||
opt :misses, "Number of misses before sleeping", :short => 'm', :default => 4
|
opt :misses, "Number of misses before sleeping", :short => 'm', :default => 4
|
||||||
|
opt :mystery7, "Use Mystery7 sets", :default => true
|
||||||
|
opt :mystery16, "Use Mystery16 set"
|
||||||
opt :record, "Record results", :short => 'r'
|
opt :record, "Record results", :short => 'r'
|
||||||
opt :seed, "Seed for the RNG", :type => :int
|
opt :seed, "Seed for the RNG", :type => :int
|
||||||
opt :sessions, "Number of sessions to simulate", :short => 's', :type => :int, :default => 1000
|
opt :sessions, "Number of sessions to simulate", :short => 's', :type => :int, :default => 1000
|
||||||
|
opt :sleep, "Sleep after N misses", :default => true
|
||||||
opt :spins, "Number of spins", :short => 'n', :type => :int, :default => 45
|
opt :spins, "Number of spins", :short => 'n', :type => :int, :default => 45
|
||||||
opt :verbose, "Print stats after each spin", :short => 'v'
|
opt :verbose, "Print stats after each spin", :short => 'v'
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:style] = options[:european] ? 'European' : 'American'
|
options[:style] = options[:european] ? 'European' : 'American'
|
||||||
puts ">>> Simulating #{options[:sessions]} #{options[:style]} style sessions of #{options[:spins]} spins, sleeping after #{options[:misses]} miss#{options[:misses] > 0 ? 'es' : ''}..."
|
options[:set] = options[:mystery16] ? :mystery16 : :mystery7
|
||||||
|
if options[:mystery16]
|
||||||
|
options[:mystery7] = false
|
||||||
|
options[:sleep] = false
|
||||||
|
end
|
||||||
|
print ">>> Simulating #{options[:sessions]} #{options[:style]} style sessions of #{options[:spins]} spins"
|
||||||
|
print ", sleeping after #{options[:misses]} miss#{options[:misses] > 0 ? 'es' : ''}" if options[:sleep]
|
||||||
|
puts "..."
|
||||||
|
|
||||||
roulette = Roulette.new(options.dup)
|
roulette = Roulette.new(options.dup)
|
||||||
|
|
||||||
|
|
@ -46,7 +56,7 @@ def main
|
||||||
:wins => 0
|
:wins => 0
|
||||||
}
|
}
|
||||||
|
|
||||||
Roulette::Sets.each do |letter, set|
|
Roulette::Sets[options[:set]].each do |letter, set|
|
||||||
puts "# of #{letter.to_s.upcase}s: #{roulette.counts[letter]}" if options[:verbose]
|
puts "# of #{letter.to_s.upcase}s: #{roulette.counts[letter]}" if options[:verbose]
|
||||||
set_status = roulette.set_status[letter]
|
set_status = roulette.set_status[letter]
|
||||||
puts "status: #{set_status.inspect}" if options[:verbose]
|
puts "status: #{set_status.inspect}" if options[:verbose]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue