# Monopoly

Jun 2nd, 2016
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # NEW Monopoly Simulator
2.
3. # Board         - http://ecx.images-amazon.com/images/I/81oC5pYhh2L._SL1500_.jpg
4. # General Rules - http://richard_wilding.tripod.com/monorules.htm
5. # Tax Rules     - https://en.wikibooks.org/wiki/Monopoly/Official_Rules
6.
7. from random import randint
8.
9. #Initialize Variables
10.
11. board = {
12.
13.     #          0               1          2              3                   4              5
14.     # [ Place on board | Initial Cost | Rent | Owns? (No. of player) | Frequency p1 | Frequency p2 ]
15.     "brown"     : [[ 1,  60,  2, 0, 0, 0], [ 3,  60,  4, 0, 0, 0]],
16.     "lblue"     : [[ 6, 100,  6, 0, 0, 0], [ 8, 100,  6, 0, 0, 0], [ 9, 120,  8, 0, 0, 0]],
17.     "pink"      : [[11, 140, 10, 0, 0, 0], [13, 140, 10, 0, 0, 0], [14, 160, 12, 0, 0, 0]],
18.     "orange"    : [[16, 180, 14, 0, 0, 0], [18, 180, 14, 0, 0, 0], [19, 200, 16, 0, 0, 0]],
19.     "red"       : [[21, 220, 18, 0, 0, 0], [23, 220, 18, 0, 0, 0], [24, 240, 20, 0, 0, 0]],
20.     "yellow"    : [[26, 260, 22, 0, 0, 0], [27, 260, 22, 0, 0, 0], [29, 280, 22, 0, 0, 0]],
21.     "green"     : [[31, 300, 26, 0, 0, 0], [32, 300, 26, 0, 0, 0], [34, 320, 28, 0, 0, 0]],
22.     "dblue"     : [[37, 350, 35, 0, 0, 0], [39, 400, 50, 0, 0, 0]],
23.
24.     "railroad"  : [[ 5, 200, 25, 0, 0, 0], [15, 200, 25, 0, 0, 0], [25, 200, 25, 0, 0, 0], [35, 200, 25, 0, 0, 0]],
25.     "utilities" : [[12, 150,  4, 0, 0, 0], [28, 150,  4, 0, 0, 0]],
26.
27.     #          0               1              2
28.     # [ Place on board | Freqeuncy p1 | Frequency p2 ]
29.     "GO"           : [[ 0, 0, 0]],
30.     "tax"          : [[ 4, 0, 0], [38, 0, 0]],
31.     "free parking" : [[20, 0, 0]],
32.
33.     "jail"         : [[10, 0, 0]],
34.     "go to jail"   : [[30, 0, 0]],
35.     "chance"       : [[7, 0, 0], [22, 0, 0], [36, 0, 0]],
36.     "chest"        : [[2, 0, 0], [17, 0, 0], [33, 0, 0]]
37. }
38.
39. #This array contains the second part of the dictionary
40. notmade = [0, 4, 10, 30, 38, 20, 7, 22, 36, 2, 17, 33]
41.
42. #chance_cards = []
43. #chest_cards  = []
44.
45. #num = input("How many rounds do you want to simulate? ")
46. roll = 0
47. jail = 0
48. iteration = 0
49. double = 0
50. end = 0
51.
52. #                                             0            1             2             3
53. #Player System (Currently not dynamic) [player number | balance | place on board | in jail?]
54.
55. player1 = [1, 1500, 0, 0]
56. player2 = [2, 1500, 0, 0]
57. players = [player1, player2]
58.
59. #Rounds begin
60.
61. for h in range(1000):
62.     for player in players:
63.
64.         while True:
65.
66.             #Dice Roll
67.             a = randint(1,6)
68.             b = randint(1,6)
69.             player[2] += a + b
70.
71.
72.             #Sends you to jail if 3 consecutive doubles
73.             if double == 3:
74.                 player[2] == 10
75.                 player[3] == 3
76.
77.             #Takes you out of jail if you roll a double
78.             if player[3] != 0 and a == b:
79.                 player[3] == 0
80.
81.             #Accounts for going around board
82.             if player[2] >= 40:
83.                 player[2] -= 40
84.                 iteration += 1
85.
86.             print("\nThis is round %d" %(h+1)) ###Optional Text
87.             print("Player 1 is on")
88.             print(player1[2])
89.             print("Player 2 is on")
90.             print(player2[2])
91.             print("Roll was %d" %(a+b))
92.             print("\n")
93.
94.             #Iterates through all items in board
95.             for key, value in board.items():
96.                 for place in value:
97.
98.                     #If not in jail
99.                     if player[3] == 0:
100.
101.                         if player[2] == place[0]:
102.
103.                             #Counts how many times property is landed on
104.                             if player[2] not in notmade:
105.                                 place[(player[0]+3)] += 1
106.                             else:
107.                                 place[player[0]] += 1
108.
109.                             #If lands on GO
110.                             if place[0] == 0:
111.                                 player[1] += 200
112.
113.                             #If lands on income tax
114.                             elif place[0] == 4:
115.                                 if player[1]/10 < 200:
116.                                     player[1] -= player[1]/10
117.                                 else:
118.                                     player[1] -= 200
119.
120.                             #If lands on luxury tax
121.                             elif place[0] == 38:
122.                                 player[1] -= 100
123.
124.                             #If lands on go to jail
125.                             elif place[0] == 30:
126.                                 player[2] == 10
127.                                 player[3] == 3
128.
129.                             #If chance/community chest/jail/free parking
131.                                 pass
132.
133.                             #Buys property if currently not bought
134.                             elif place[3] == 0:
135.                                 if player[1] > place[1]:
136.                                     player[1] -= place[1]
137.                                     place[3] = player[0]
138.
139.                             #Pays rent if owned by other player
140.                             elif place[3] != 0 and place[3] != player[0]:
141.                                 player[1] -= place[2]
142.                                 players[(place[3]-1)][1] += place[2]
143.
144.             #Accounting for a double
145.             if a == b:
146.                 double += 1
147.             else:
148.                 break
149.
150.         double = 0
151.
152.     ### For Game End
153.     if player1[1] <= 0:
154.         end = h
155.         break
156.     if player2[1] <= 0:
157.         end = h
158.         break
159.
160. #Printing the Statistics
161.
162. order1 = ["brown", "lblue", "pink", "orange", "red", "green", "dblue", "railroad", "utilities"]
163. order2 = ["GO", "tax", "free parking", "jail", "go to jail", "chance", "chest"]
164.
165. #Finds number of digit of largest number
166.
167. length = 0
168.
169. for block in order1:
170.     for place in board[block]:
171.         if len(str(place[4])) > length:
172.             length = len(str(place[4]))
173.         if len(str(place[5])) > length:
174.             length = len(str(place[5]))
175.
176. number = 1
177.
178. #Frequency Displayer
179.
180. for i in range(4,6):
181.     if i == 4:
182.         print("Player 1 Frequency Statistics\n")
183.     if i == 5:
184.         print("\nPlayer 2 Frequency Statistics\n")
185.
186.     for block in order1:
187.         for place in board[block]:
188.             print("     %s%d = %d" %(block, number, place[i]))
189.             number += 1
190.         number = 1
191.         #print("\n")
192.
193.     for block in order2:
194.         for place in board[block]:
195.             print("     %s%d = %d" %(block, number, place[i-3]))
196.             number += 1
197.         number = 1
198.         #print("\n")
199.
200. #Total Frequency
201.
202. print("\nTotal Frequency\n")
203.
204. for block in order1:
205.     for place in board[block]:
206.         print("     %s%d = %d" %(block, number, place[4] + place[5]))
207.         number += 1
208.     number = 1
209.     #print("\n")
210.
211. for block in order2:
212.     for place in board[block]:
213.         print("     %s%d = %d" %(block, number, place[1] + place[2]))
214.         number += 1
215.     number = 1
216.     #print("\n")
217.
218.
219. #Property Owner Displayer
220.
221. p1prop = []
222. p2prop = []
223.
224. for block in order1:
225.     for place in board[block]:
226.         if place[3] == 1:
227.             p1prop.append("%s%d" %(block, number))
228.         elif place[3] == 2:
229.             p2prop.append("%s%d" %(block, number))
230.         number += 1
231.     number = 1
232.
233. print("\nPlayer 1 owns:\n")
234. for prop in p1prop:
235.     print"     ", prop
236.
237. print("\nPlayer 2 owns:\n")
238. for prop in p2prop:
239.     print"     ", prop
240.
241. print("\n")
242.
243. #Balance Displayer
244.
245. print("Player 1 Balance: %d" %(player1[1]))
246. print("Player 2 Balance: %d" %(player2[1]))
247.
248. if player1[1] > player2[1]:
249.     print("\nPlayer 1 wins!")
250. else:
251.     print("\nPlayer 2 wins!")
252.
253. print("Game ended on Round %d" %(end+1)) ### For Game End