Created
August 31, 2013 00:23
-
-
Save jdwyah/6395465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ruby-debug' | |
NUM_SQUARES = 40 | |
JAIL = 10 | |
GOTO_JAIL = 30 | |
DOUBLE_MAX = 3 | |
MONTE = 4 | |
TOTAL_MOVES = 1 | |
GUESTS = 30 | |
USE_RULES = false | |
HUMAN = false | |
SQUARES = [] | |
MONTE.times do | |
SQUARES << [0] * NUM_SQUARES | |
end | |
def move(curMonte, space, moves, doubles) | |
dieOne = rand(6) + 1 | |
dieTwo = rand(6) + 1 | |
doubles += 1 if dieOne == dieTwo | |
if(doubles == DOUBLE_MAX && USE_RULES) | |
doubles = 0 | |
nextSpace = JAIL | |
else | |
nextSpace = (space + dieOne + dieTwo) % NUM_SQUARES | |
end | |
nextSpace = JAIL if nextSpace == GOTO_JAIL && USE_RULES | |
SQUARES[curMonte][nextSpace] += 1 | |
if moves > 1 | |
move(curMonte, nextSpace, moves - 1, doubles) | |
end | |
end | |
MONTE.times do |m| | |
GUESTS.times do |i| | |
move(m, 0, TOTAL_MOVES, 0) | |
end | |
end | |
names = ["Go", | |
"Mediterranean Avenue (Purple)", | |
"Community Chest", | |
"Baltic Avenue (Purple)", | |
"Income Tax", | |
"Reading Railroad (Railroad)", | |
"Oriental Avenue (Light Blue)", | |
"Chance", | |
"Vermont Avenue (Light Blue)", | |
"Connecticut Avenue (Light Blue)", | |
"Jail", | |
"Saint Charles Place (Pink)", | |
"Electric Company (Utility)", | |
"States Avenue (Pink)", | |
"Virginia Avenue (Pink)", | |
"Pennsylvania Railroad (Railroad)", | |
"Saint James Place (Orange)", | |
"Community Chest", | |
"Tennessee Avenue (Orange)", | |
"New York Avenue (Orange)", | |
"Free Parking", | |
"Kentucky Avenue (Red)", | |
"Chance", | |
"Indiana Avenue (Red)", | |
"Illinois Avenue (Red)", | |
"B & O Railroad (Railroad)", | |
"Atlantic Avenue (Yellow)", | |
"Ventnor Avenue (Yellow)", | |
"Water Works (Utility)", | |
"Marvin Gardens (Yellow)", | |
"Goto Jail", | |
"Pacific Avenue (Green)", | |
"North Carolina Avenue (Green)", | |
"Community Chest", | |
"Pennsylvania Avenue (Green)", | |
"Short Line (Railroad)", | |
"Chance", | |
"Park Place (Dark Blue)", | |
"Luxury Tax", | |
"Boardwalk (Dark Blue)"] | |
puts "#{MONTE} simulations of #{GUESTS} guests making #{TOTAL_MOVES} moves." | |
if USE_RULES | |
puts "Going to Jail after #{DOUBLE_MAX} doubles or Goto Jail." | |
end | |
zipped = SQUARES.shift | |
zipped = zipped.zip(*SQUARES) | |
names.each_with_index do |name, i| | |
z = zipped[i].sort | |
avg = z.inject{ |sum, el| sum + el }.to_f / z.size | |
index = (MONTE * 0.95).to_i | |
if(HUMAN) | |
puts "Avg servings #{avg} 95th pct #{z[index]} max #{z[-1]} #{name}" | |
else | |
puts "\"#{name}\", #{avg}, #{z[index]}, #{z[-1]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment