-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (26 loc) · 1.46 KB
/
main.py
File metadata and controls
36 lines (26 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import random
switch = True # whether player switches door after reveal
play_count = 100000
win_count = 0 # will update on every win
# randomness_test: list[int] = [0, 0, 0]
for i in range(play_count): # 0 to (n-1)
doors_choosable: set = {1, 2, 3} # choices offered to player
doors_revealable: set = {1, 2, 3} # doors that can be revealed by host
correct_door = random.sample(sorted(doors_revealable), 1)[0]
# randomness_test[correct_door-1] += 1
doors_revealable.remove(correct_door) # correct door can't be revealed
choice_1 = random.sample(sorted(doors_choosable), 1)[0] # player selects a door (33% chance it's correct)
doors_choosable.remove(choice_1)
doors_revealable.discard(choice_1) # chosen door can't be revealed
reveal = random.sample(sorted(doors_revealable), 1)[0] # one of the incorrect doors is revealed
doors_choosable.remove(reveal) # revealed door is incorrect, only 1 choice left (if switching)
assert len(doors_choosable) == 1, "Erorr, wrong assumption"
if (switch): # player decides whether to switch doors now
choice_1 = list(doors_choosable)[0] # otherwise stick to older choice_1
if(choice_1 == correct_door):
win_count += 1
# print(f"game {i} end")
# print(f"win count = {win_count}")
print(f"win percent = {win_count*100/play_count}")
# randomness_test = [count/play_count for count in randomness_test]
# print(f"RNG distribution: {randomness_test}")