Skip to content

Instantly share code, notes, and snippets.

@adamkewley
Last active December 31, 2016 11:20
Show Gist options
  • Save adamkewley/1ba54a7f78b8f811f7749dd5922c0d15 to your computer and use it in GitHub Desktop.
Save adamkewley/1ba54a7f78b8f811f7749dd5922c0d15 to your computer and use it in GitHub Desktop.
Calculting monty hall effect for starcraft zergling scouting (Sam)
class Array
def select_random
return self.sample
end
def select_random_that_isnt(*excluded_vals)
selected_value = self.select_random
if excluded_vals.include? selected_value
return self.select_random_that_isnt(*excluded_vals)
else return selected_value end
end
end
num_simulation_attempts = 1000000
num_spawn_locations = 3
overlord_always_finds_an_empty_slot = true
spawn_locations = (1..num_spawn_locations).to_a
wins = 0
num_simulation_attempts.times do
enemy_base_location = spawn_locations.select_random
zergling_choice = spawn_locations.select_random
overlord_choice =
if overlord_always_finds_an_empty_slot
spawn_locations.select_random_that_isnt(zergling_choice, enemy_base_location)
else
spawn_locations.select_random_that_isnt(zergling_choice)
end
swapped_zergling_choice =
spawn_locations.select_random_that_isnt(zergling_choice, overlord_choice)
if swapped_zergling_choice == enemy_base_location
wins = wins + 1
end
end
puts wins.to_f / num_simulation_attempts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment