From 0f3f30d41168209bfd94d51f8aa6c5a13d523476 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 21 Dec 2017 11:44:21 +0000 Subject: Initial Commit --- Readme.textile | 21 +++++ monopoly.bottom.dat | 40 ++++++++++ monopoly.bottom.plot | 10 +++ monopoly.bottom.svg | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++ monopoly.discard.dat | 40 ++++++++++ monopoly.discard.plot | 10 +++ monopoly.discard.svg | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++ monopoly.rb | 129 +++++++++++++++++++++++++++++++ 8 files changed, 666 insertions(+) create mode 100644 Readme.textile create mode 100644 monopoly.bottom.dat create mode 100755 monopoly.bottom.plot create mode 100644 monopoly.bottom.svg create mode 100644 monopoly.discard.dat create mode 100755 monopoly.discard.plot create mode 100644 monopoly.discard.svg create mode 100755 monopoly.rb diff --git a/Readme.textile b/Readme.textile new file mode 100644 index 0000000..4e1c33b --- /dev/null +++ b/Readme.textile @@ -0,0 +1,21 @@ +h1. Monopoly Landings + +This experimentally tests landing frequencies for squares on a monopoly board. + +h1. Requirements + +* Ruby +* Gnuplot + +h1. Deck strateies + +There are two deck strategies available: + +* Put card back on bottom of deck (@bottom@) +* Form a discard pile and shuffle it when the draw runs out (@discard@) + +h1. Running + +# ./monopoly > monopoly..dat +# ./monopoly..plot +# see monopoly..svg diff --git a/monopoly.bottom.dat b/monopoly.bottom.dat new file mode 100644 index 0000000..1ba0ebe --- /dev/null +++ b/monopoly.bottom.dat @@ -0,0 +1,40 @@ +0 2056672 +1 2035295 +2 2133768 +3 2220406 +4 2315543 +5 2423412 +6 2554524 +7 2693143 +8 2638163 +9 2569634 +10 2876766 +11 2420811 +12 2421525 +13 2413601 +14 2498800 +15 2651458 +16 2773959 +17 2896894 +18 2853827 +19 2830049 +20 2795982 +21 2760713 +22 2724420 +23 2689202 +24 2676457 +25 2670255 +26 2646872 +27 2603607 +28 2547940 +29 2488636 +30 2516624 +31 2531628 +32 2488149 +33 2427072 +34 2378673 +35 2317250 +36 2208126 +37 2093793 +38 2087411 +39 2068940 diff --git a/monopoly.bottom.plot b/monopoly.bottom.plot new file mode 100755 index 0000000..bb1bc60 --- /dev/null +++ b/monopoly.bottom.plot @@ -0,0 +1,10 @@ +#!/usr/bin/gnuplot + +reset + +set terminal svg size 350,262 fname 'Verdana, Helvetica, Arial, sans-serif' fsize '10' +set output 'monopoly.bottom.svg' + +unset key + +plot 'monopoly.bottom.dat' with linespoints ls 1 diff --git a/monopoly.bottom.svg b/monopoly.bottom.svg new file mode 100644 index 0000000..bc1ac69 --- /dev/null +++ b/monopoly.bottom.svg @@ -0,0 +1,208 @@ + + + + +Gnuplot +Produced by GNUPLOT 5.0 patchlevel 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2x106 + + + + + 2.1x106 + + + + + 2.2x106 + + + + + 2.3x106 + + + + + 2.4x106 + + + + + 2.5x106 + + + + + 2.6x106 + + + + + 2.7x106 + + + + + 2.8x106 + + + + + 2.9x106 + + + + + 0 + + + + + 5 + + + + + 10 + + + + + 15 + + + + + 20 + + + + + 25 + + + + + 30 + + + + + 35 + + + + + 40 + + + + + + + + + 'monopoly.bottom.dat' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/monopoly.discard.dat b/monopoly.discard.dat new file mode 100644 index 0000000..fa2af6a --- /dev/null +++ b/monopoly.discard.dat @@ -0,0 +1,40 @@ +0 2054907 +1 2035470 +2 2131962 +3 2223948 +4 2315474 +5 2422870 +6 2553760 +7 2698018 +8 2642567 +9 2571248 +10 2877528 +11 2424713 +12 2419076 +13 2417959 +14 2500926 +15 2651781 +16 2767257 +17 2895492 +18 2851747 +19 2826312 +20 2797420 +21 2758991 +22 2721143 +23 2690382 +24 2675196 +25 2669472 +26 2646083 +27 2603111 +28 2543992 +29 2491120 +30 2514633 +31 2536961 +32 2484118 +33 2431014 +34 2378539 +35 2315314 +36 2209503 +37 2093443 +38 2087070 +39 2069480 diff --git a/monopoly.discard.plot b/monopoly.discard.plot new file mode 100755 index 0000000..ea85f99 --- /dev/null +++ b/monopoly.discard.plot @@ -0,0 +1,10 @@ +#!/usr/bin/gnuplot + +reset + +set terminal svg size 350,262 fname 'Verdana, Helvetica, Arial, sans-serif' fsize '10' +set output 'monopoly.discard.svg' + +unset key + +plot 'monopoly.discard.dat' with linespoints ls 1 diff --git a/monopoly.discard.svg b/monopoly.discard.svg new file mode 100644 index 0000000..f1ba2f1 --- /dev/null +++ b/monopoly.discard.svg @@ -0,0 +1,208 @@ + + + + +Gnuplot +Produced by GNUPLOT 5.0 patchlevel 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2x106 + + + + + 2.1x106 + + + + + 2.2x106 + + + + + 2.3x106 + + + + + 2.4x106 + + + + + 2.5x106 + + + + + 2.6x106 + + + + + 2.7x106 + + + + + 2.8x106 + + + + + 2.9x106 + + + + + 0 + + + + + 5 + + + + + 10 + + + + + 15 + + + + + 20 + + + + + 25 + + + + + 30 + + + + + 35 + + + + + 40 + + + + + + + + + 'monopoly.discard.dat' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/monopoly.rb b/monopoly.rb new file mode 100755 index 0000000..db8f01b --- /dev/null +++ b/monopoly.rb @@ -0,0 +1,129 @@ +#!/usr/bin/env ruby + +require 'pp' + +class Roll + attr_reader :d1, :d2 + + def initialize + @d1 = rand(6) + 1 + @d2 = rand(6) + 1 + end + + def sum + return @d1 + @d2 + end + + def double? + return @d1 == @d2 + end +end + +class Deck + def initialize(cards, strategy) + @draw = cards.shuffle + @size = cards.length + @strategy = strategy + @discard = [] if strategy == :discard + end + + def take + this = @draw.shift + + case @strategy + when :bottom + @draw << this + when :discard + @discard << this + if @draw.empty? then + @draw = @discard.shuffle + @discard = [] + end + end + + return this + end +end + +class Chance < Deck + def initialize(strategy) + super([0, 24, 11, [12,28], [5,15,25,35], nil, nil, -3, 10, nil, nil, 5, 39, nil, nil, nil], strategy) + end +end + +class CommunityChest < Deck + def initialize(strategy) + super([0, nil, nil, nil, nil, 10, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], strategy) + end +end + +space = 0 +doubles = 0 +stats = (0..39).map{|i|[i, 0]}.to_h + +strat = (ARGV.shift || 'bottom').chomp.intern + +chance = Chance.new(strat) +chest = CommunityChest.new(strat) + +(ARGV.shift || "10000000").chomp.to_i.times do + r = Roll.new + + if r.double? then + doubles += 1 + else + doubles = 0 + end + + if doubles == 3 then + space = 10 + else + space = (space + r.sum) % 40 + end + + stats[space] += 1 + + if space == 30 then + space = 10 + end + + if [7,22,36].include?(space) then + c = chance.take + if c.is_a?(Integer) then + if c >= 0 then + space = 0 + else + space = (space + c) % 40 + end + elsif c.is_a?(Array) then + try = c.drop_while{|x|x <= space}[0] + if try.nil? then + space = 0 + else + space = try + end + end + end + + if [2,17,33].include?(space) then + c = chest.take + if c.is_a?(Integer) then + if c >= 0 then + space = 0 + else + space = (space + c) % 40 + end + elsif c.is_a?(Array) then + try = c.drop_while{|x|x <= space}[0] + if try.nil? then + space = 0 + else + space = try + end + end + end +end + +stats.each do |k, v| + puts "#{k}\t#{v}" +end -- cgit v1.2.1