diff options
| author | realtradam <[email protected]> | 2023-01-09 02:12:40 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-01-09 02:12:40 -0500 |
| commit | 06d1c06bb37cd0fdd5fc68e4c235f0c56e08e998 (patch) | |
| tree | e78ff13024f99079c4bd37ea9a8da1de07546343 /odds_testing | |
| parent | 431003c20269652c7169beecdb3654e12713687f (diff) | |
| download | Plore-Tabletop-Game-06d1c06bb37cd0fdd5fc68e4c235f0c56e08e998.tar.gz Plore-Tabletop-Game-06d1c06bb37cd0fdd5fc68e4c235f0c56e08e998.zip | |
new resolution mechanic + other things
Diffstat (limited to 'odds_testing')
| -rw-r--r-- | odds_testing/.vimrc | 2 | ||||
| -rw-r--r-- | odds_testing/cards.rb | 87 | ||||
| -rw-r--r-- | odds_testing/temp.txt | 144 |
3 files changed, 233 insertions, 0 deletions
diff --git a/odds_testing/.vimrc b/odds_testing/.vimrc new file mode 100644 index 0000000..064e560 --- /dev/null +++ b/odds_testing/.vimrc @@ -0,0 +1,2 @@ +" press F5 to compile and execute the project code +map <f5> :AsyncRun -save=1 ruby '%:p' <CR> diff --git a/odds_testing/cards.rb b/odds_testing/cards.rb new file mode 100644 index 0000000..03c8d3f --- /dev/null +++ b/odds_testing/cards.rb @@ -0,0 +1,87 @@ +class Array + def deep_copy + Marshal.load(Marshal.dump(self)) + end + def mean + return 0 if self.length.zero? + self.sum.to_f / self.length.to_f + end + def median + return 0 if self.length.zero? + sorted = self.sort + mid = (sorted.length - 1).to_f / 2.0 + (sorted[mid.floor] + sorted[mid.ceil]).to_f / 2.0 + end + def mode + return 0 if self.length.zero? + self.group_by(&:itself).values.max_by(&:size).first.to_f + end +end + +suits = [:s,:c,:h,:d] +ten = (1..10).to_a +courts = [:k, :q, :r, :j] +@cards = suits.map do |suit| + ten.map do |num| + [suit, num.to_s] + end + courts.map do |court| + [suit, court] + end +end + +def test_multi(iterations, *block_params, &block) + results = [] + iterations.times do + results.push block.call(*block_params) + end + "Mean: " + results.mean.to_s + + "\nMedian: " + results.median.to_s + + "\nMode: " + results.mode.to_s + + "\nDistribution:\n" + + results.group_by(&:itself).map do |key, value| + [key, value.size.to_f / results.size] + end.to_h.sort_by do |key, value| + [-value, key] + end.to_h.to_s +end + +basic_match = ->(player_hand_size = 3, dm_hand_size = 3) do + dm_deck = @cards.shuffle + player_deck = @cards.shuffle + + dm_hand = dm_deck[0...dm_hand_size] + player_hand = player_deck[0...player_hand_size] + dup_dm_hand = dm_hand.clone + dup_player_hand = player_hand.clone + matches = 0 + + dm_hand.reverse_each do |dm_card| + card_paired = false + player_hand.reverse_each do |player_card| + if player_card == dm_card + dm_hand.delete dm_card + player_hand.delete player_card + card_paired = true + matches += 1 + next + end + next if card_paired + end + end + + matches +end +#test_multi(20_000, 3, 3, &basic_match) +result = "" +3.times do |play| + 6.times do |dm| + play_mod = (play + 2) + dm_mod = (dm + 1) + result += "player: #{play_mod}\n" + result += "dm : #{dm_mod}\n" + result += test_multi(200_000, dm_mod, play_mod, &basic_match) + "\n\n" + end +end + +File.write('temp.txt', result) diff --git a/odds_testing/temp.txt b/odds_testing/temp.txt new file mode 100644 index 0000000..f12df15 --- /dev/null +++ b/odds_testing/temp.txt @@ -0,0 +1,144 @@ +player: 2 +dm : 1 +Mean: 0.15256 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.84744, 1=>0.15256} + +player: 2 +dm : 2 +Mean: 0.292 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.719435, 1=>0.26913, 2=>0.011435} + +player: 2 +dm : 3 +Mean: 0.41299 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.616645, 1=>0.35372, 2=>0.029635} + +player: 2 +dm : 4 +Mean: 0.529445 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.52538, 1=>0.419795, 2=>0.054825} + +player: 2 +dm : 5 +Mean: 0.63111 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.46442, 0=>0.452235, 2=>0.083345} + +player: 2 +dm : 6 +Mean: 0.726155 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.497885, 0=>0.38798, 2=>0.114135} + +player: 3 +dm : 1 +Mean: 0.2203 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.7797, 1=>0.2203} + +player: 3 +dm : 2 +Mean: 0.41693 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.61351, 1=>0.35605, 2=>0.03044} + +player: 3 +dm : 3 +Mean: 0.59677 +Median: 1.0 +Mode: 0.0 +Distribution: +{0=>0.48433, 1=>0.436645, 2=>0.07695, 3=>0.002075} + +player: 3 +dm : 4 +Mean: 0.75684 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.478115, 0=>0.385945, 2=>0.129095, 3=>0.006845} + +player: 3 +dm : 5 +Mean: 0.90343 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.49448, 0=>0.3083, 2=>0.18271, 3=>0.01451} + +player: 3 +dm : 6 +Mean: 1.03908 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.494765, 0=>0.245995, 2=>0.233405, 3=>0.025835} + +player: 4 +dm : 1 +Mean: 0.277745 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.722255, 1=>0.277745} + +player: 4 +dm : 2 +Mean: 0.530095 +Median: 0.0 +Mode: 0.0 +Distribution: +{0=>0.525, 1=>0.419905, 2=>0.055095} + +player: 4 +dm : 3 +Mean: 0.75736 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.476565, 0=>0.386465, 2=>0.130115, 3=>0.006855} + +player: 4 +dm : 4 +Mean: 0.961645 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.48815, 0=>0.286295, 2=>0.203485, 3=>0.021755, 4=>0.000315} + +player: 4 +dm : 5 +Mean: 1.15414 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.472675, 2=>0.27089, 0=>0.210455, 3=>0.044235, 4=>0.001745} + +player: 4 +dm : 6 +Mean: 1.322185 +Median: 1.0 +Mode: 1.0 +Distribution: +{1=>0.44169, 2=>0.323865, 0=>0.158145, 3=>0.072435, 4=>0.003865} + |
