All of the interesting technological, artistic or just plain fun subjects I'd investigate if I had an infinite number of lifetimes. In other words, a dumping ground...
Tuesday, 18 August 2009
Roulette Ruby
Assumptions:
- we get double our bet back when we win
- we reset the bet to 1 when we win
- we leave the bet at the maximum bet of $50 when we hit it
- we double our bet each time we lose (this is the theoretical lynch pin in that you can win back your previous losses eg. you lose with bets of 1,2,4,8. Then you win with a bet of 16. So total profit is 16 - 8 - 4 -2 -1 = 1. So you never really lose. Until you hit the table betting limit.)
- we keep betting until we run out of money or we make 1.05 * initial bank
This is the highest win ratio but the wins are so small that one loss wipes them out.
tohare@pts-tohare-laptop:~/projects/ruby$ ruby roulette.rb
count: 368, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 190, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 233, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 1361, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 192, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 425, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 702, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 219, bank 2101, bank - INITIAL_BANK 101, bet 1
count: 15496, bank 44, bank - INITIAL_BANK -1956, bet 50
count: 1078, bank 2101, bank - INITIAL_BANK 101, bet 1
Times Won: 9
Times Lost: 1
Average win amount: -105
tot amount: -1047
class RouletteTable
BLACk=[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35]
RED=[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36]
def self.spin
srand()
result = rand(37)
#puts "Result: #{result}"
return :green if result == 0
return :black if BLACk.include?(result)
return :red if RED.include?(result)
end
end
INITIAL_BANK=2000
BETTING_LIMIT=50
winnings=[]
10.times do
bank = INITIAL_BANK
bet = 1
count =0
while 1
break if ((bank - bet) < 0)
break if (bank > (1.05 * INITIAL_BANK))
bank -= bet
count += 1
if RouletteTable.spin == :black
bank += bet*2
bet = 1
next
end
bet = (bet*2).to_i
if bet > BETTING_LIMIT
bet = BETTING_LIMIT
end
end
winnings << bank - INITIAL_BANK
win = bank - INITIAL_BANK
#puts "count: #{count}, bank #{bank}, bank - INITIAL_BANK #{win}, bet #{bet}, winnings #{winnings}"
puts "count: #{count}, bank #{bank}, bank - INITIAL_BANK #{win}, bet #{bet}"
end
profit = winnings.select{|i| i > 0}.length
loss = winnings.select{|i| i < 0}.length
tot = winnings.inject{|acc,i| acc + i}
avg = winnings.inject{|acc,i| acc + i} / winnings.length
puts "Times Won: #{profit}"
puts "Times Lost: #{loss}"
puts "Average win amount: #{avg}"
puts "tot amount: #{tot}"
Subscribe to:
Post Comments (Atom)
tim's shared items
Blog Archive
-
▼
2009
(64)
-
▼
August
(16)
- Pyjamas examples
- Skype trojan source code
- Webhooks & PubSubHubbub
- Pyjamas - Google Web Toolkit in Python
- electronic music
- Qt Designer and subclassing QGraphicsView
- Message Queue links
- Electronic music and Sound Cloud
- Roulette Ruby
- Ruby Roulette
- Real time physics simulators
- Git
- static checking tools
- HTML 5 resources
- Open Source Windows Applictions
- Compiler errors
-
▼
August
(16)
No comments:
Post a Comment