-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
133 lines (110 loc) · 2.77 KB
/
hello.py
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
from random import randint
squares = ["GO",
"Med Av",
"Chest 1",
"Baltic avenue",
"Tax",
"Reading Train",
"Oriental Av",
"Chance 1",
"Vermont Av",
"Connenticut Av",
"Jail", # TODO make it so we can get stuck here...
"St charles place",
"Elec Utility",
"States av",
"Virginia av",
"Penn Train",
"St James",
"Chest 1",
"Tennessee av",
"NY Av",
"Free parking",
"Kentucky av",
"Chance 2",
"Indiana av",
"Illinois",
"B&O Train",
"Atl av",
"Ventnor av",
"Water Utility",
"Marvin gardens",
"Go to prison",
"Pacific avenue",
"North carolina av",
"Chest 2",
"Penn av",
"Short Train",
"Chance 3",
"park place",
"luxury tax",
"Broadwalk"]
board = {}
locations = {}
for i, name in enumerate(squares):
board[i] = name
locations[name] = i
def go_to_nearest(start_pos, destination):
while True:
if destination in board[start_pos]:
return start_pos
start_pos += 1
start_pos = start_pos % len(squares)
def roll():
return (randint(1, 6), randint(1, 6))
def move(visits, position, n_rolls_this_turn):
die = roll()
distance = die[0] + die[1]
if n_rolls_this_turn == 3:
position = locations["Jail"]
else:
position += distance
position = position % len(squares)
if "Go to prison" in board[position]:
visits[board[position]] += 1
position = locations["Jail"]
if "Chest" in board[position]:
card = randint(1,16)
visits[board[position]] += 1
if (card == 1):
position = locations["Jail"]
if (card == 2):
position = locations["GO"]
if "Chance" in board[position]:
card = randint(1,16)
visits[board[position]] += 1
if card == 1:
position = locations["Jail"]
if card == 2:
position = locations["GO"]
if card == 3:
position = locations["Illinois"]
if card == 4:
# go to nearest utility
position = go_to_nearest(position, "Utility")
if card == 5:
# go to nearest train station
position = go_to_nearest(position, "Train")
if card == 6:
position -= 3
position = position % len(squares)
if card == 7:
position = locations["Jail"]
if card == 8:
position = locations["Reading Train"]
if card == 9:
position = locations["Broadwalk"]
visits[board[position]] += 1
if die[0] == die[1] & position != locations["Jail"]:
position = move(visits, position, n_rolls_this_turn+1)
return position
def main():
position = 0
visits = {}
for square in squares:
visits[square] = 0
for _ in xrange(200):
position = move(visits, position, 0)
print visits
if __name__ == '__main__':
main()