-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonoprobability.py
More file actions
176 lines (147 loc) · 4.68 KB
/
Copy pathmonoprobability.py
File metadata and controls
176 lines (147 loc) · 4.68 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import random
Board = {
0: "GO",
1: "Mediterranean Avenue",
2: "CC 1",
3: "Baltic Avenue",
4: "Income Tax",
5: "Reading Railroad",
6: "Oriental Avenue",
7: "Chance 1",
8: "Vermont Avenue",
9: "Connecticut Avenue",
10: "Jail",
11: "St. Charles Place",
12: "Electric Company",
13: "States Avenue",
14: "Virginia Avenue",
15: "Pennsylvania Railroad",
16: "St. James Place",
17: "CC 2",
18: "Tennessee Avenue",
19: "New York Avenue",
20: "Free Parking",
21: "Kentucky Avenue",
22: "Chance 2",
23: "Indiana Avenue",
24: "Illinois Avenue",
25: "B&O Railroad",
26: "Atlantic Avenue",
27: "Ventnor Avenue",
28: "Water Works",
29: "Marvin Gardens",
30: "Go To Jail",
31: "Pacific Avenue",
32: "North Carolina Avenue",
33: "CC 3",
34: "Pennsylvania Avenue",
35: "Short Line",
36: "Chance 3",
37: "Park Place",
38: "Luxury Tax",
39: "Boardwalk"
}
class Game:
def __init__(self, game_limit: int):
self._board = Board
self._player_space = 0
self._turn_count = 0
self._double_count = 0
self._total_double = 0
self._game_count = 0
self._game_limit = game_limit
self._total_turn = 0
self._double_jail = 0
self._stats = []
for value in self._board.values():
self._stats.append([value, 0])
def play(self) -> None:
if self._turn_count == 40:
self._player_space = 0
self._game_count += 1
self._turn_count = 0
roll = dice_roll()
self._player_space = (self._player_space + roll[0] + roll[1]) % 40
if "Chance" in self._board[self._player_space]:
self._chance()
if "CC" in self._board[self._player_space]:
self._cc()
if self._player_space == 30:
self._player_space = 10
self._total_turn += 1
# double
if roll[0] == roll[1]:
self._double_count += 1
self._total_double += 1
# triple double jail
if self._double_count == 3:
self._player_space = 10
self._double_jail += 1
else:
self._double_count = 0
self._turn_count += 1
amount = self._stats[self._player_space][1] + 1
self._stats[self._player_space][1] = amount
print(f"Game {self._game_count}, Turn {self._turn_count} done.")
def game_over(self) -> bool:
if self._game_count >= self._game_limit:
return True
def print_results(self) -> None:
for stats in self._stats:
print(f"{stats[0]}\t"
f"{round(((stats[1] / self._total_turn) * 100), 4)}%\t"
f"{stats[1]}")
print(f"Total Turns: {self._total_turn}")
print(f"Amount of Doubles: {self._total_double}")
print(f"Amount of Triple Doubles; {self._double_jail}")
def _chance(self) -> None:
chance = random.randint(1, 16)
# Advance to Go
if chance == 1:
self._player_space = 0
# Advance to Illinois
elif chance == 2:
self._player_space = 24
# Advance to St. Charles
elif chance == 3:
self._player_space = 11
# Advance to nearest utility
elif chance == 4:
while self._player_space not in (12, 28):
self._player_space = (self._player_space + 1) % 40
# Advance to nearest railroad
elif chance == 5:
while self._player_space not in (5, 15, 25, 35):
self._player_space = (self._player_space + 1) % 40
# Go back three spaces
elif chance == 8:
self._player_space -= 3
# Go to Jail
elif chance == 9:
self._player_space = 10
# Trip to Reading Railroad
elif chance == 12:
self._player_space = 5
# Trip to Boardwalk
elif chance == 13:
self._player_space = 39
def _cc(self) -> None:
cc = random.randint(1, 16)
# Advance to Go
if cc == 1:
self._player_space = 0
# Go to Jail
elif cc == 6:
self._player_space = 10
def dice_roll() -> (int, int):
first = random.randint(1, 6)
second = random.randint(1, 6)
numbers = (first, second)
return numbers
def main():
game = Game(1000000)
while not game.game_over():
game.play()
game.print_results()
if __name__ == "__main__":
main()