Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # NEW Monopoly Simulator
- # Board - http://ecx.images-amazon.com/images/I/81oC5pYhh2L._SL1500_.jpg
- # General Rules - http://richard_wilding.tripod.com/monorules.htm
- # Tax Rules - https://en.wikibooks.org/wiki/Monopoly/Official_Rules
- from random import randint
- #Initialize Variables
- board = {
- # 0 1 2 3 4 5
- # [ Place on board | Initial Cost | Rent | Owns? (No. of player) | Frequency p1 | Frequency p2 ]
- "brown" : [[ 1, 60, 2, 0, 0, 0], [ 3, 60, 4, 0, 0, 0]],
- "lblue" : [[ 6, 100, 6, 0, 0, 0], [ 8, 100, 6, 0, 0, 0], [ 9, 120, 8, 0, 0, 0]],
- "pink" : [[11, 140, 10, 0, 0, 0], [13, 140, 10, 0, 0, 0], [14, 160, 12, 0, 0, 0]],
- "orange" : [[16, 180, 14, 0, 0, 0], [18, 180, 14, 0, 0, 0], [19, 200, 16, 0, 0, 0]],
- "red" : [[21, 220, 18, 0, 0, 0], [23, 220, 18, 0, 0, 0], [24, 240, 20, 0, 0, 0]],
- "yellow" : [[26, 260, 22, 0, 0, 0], [27, 260, 22, 0, 0, 0], [29, 280, 22, 0, 0, 0]],
- "green" : [[31, 300, 26, 0, 0, 0], [32, 300, 26, 0, 0, 0], [34, 320, 28, 0, 0, 0]],
- "dblue" : [[37, 350, 35, 0, 0, 0], [39, 400, 50, 0, 0, 0]],
- "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]],
- "utilities" : [[12, 150, 4, 0, 0, 0], [28, 150, 4, 0, 0, 0]],
- # 0 1 2
- # [ Place on board | Freqeuncy p1 | Frequency p2 ]
- "GO" : [[ 0, 0, 0]],
- "tax" : [[ 4, 0, 0], [38, 0, 0]],
- "free parking" : [[20, 0, 0]],
- "jail" : [[10, 0, 0]],
- "go to jail" : [[30, 0, 0]],
- "chance" : [[7, 0, 0], [22, 0, 0], [36, 0, 0]],
- "chest" : [[2, 0, 0], [17, 0, 0], [33, 0, 0]]
- }
- #This array contains the second part of the dictionary
- notmade = [0, 4, 10, 30, 38, 20, 7, 22, 36, 2, 17, 33]
- #chance_cards = []
- #chest_cards = []
- #num = input("How many rounds do you want to simulate? ")
- roll = 0
- jail = 0
- iteration = 0
- double = 0
- end = 0
- # 0 1 2 3
- #Player System (Currently not dynamic) [player number | balance | place on board | in jail?]
- player1 = [1, 1500, 0, 0]
- player2 = [2, 1500, 0, 0]
- players = [player1, player2]
- #Rounds begin
- for h in range(1000):
- for player in players:
- while True:
- #Dice Roll
- a = randint(1,6)
- b = randint(1,6)
- player[2] += a + b
- #Sends you to jail if 3 consecutive doubles
- if double == 3:
- player[2] == 10
- player[3] == 3
- #Takes you out of jail if you roll a double
- if player[3] != 0 and a == b:
- player[3] == 0
- #Accounts for going around board
- if player[2] >= 40:
- player[2] -= 40
- iteration += 1
- print("\nThis is round %d" %(h+1)) ###Optional Text
- print("Player 1 is on")
- print(player1[2])
- print("Player 2 is on")
- print(player2[2])
- print("Roll was %d" %(a+b))
- print("\n")
- #Iterates through all items in board
- for key, value in board.items():
- for place in value:
- #If not in jail
- if player[3] == 0:
- if player[2] == place[0]:
- #Counts how many times property is landed on
- if player[2] not in notmade:
- place[(player[0]+3)] += 1
- else:
- place[player[0]] += 1
- #If lands on GO
- if place[0] == 0:
- player[1] += 200
- #If lands on income tax
- elif place[0] == 4:
- if player[1]/10 < 200:
- player[1] -= player[1]/10
- else:
- player[1] -= 200
- #If lands on luxury tax
- elif place[0] == 38:
- player[1] -= 100
- #If lands on go to jail
- elif place[0] == 30:
- player[2] == 10
- player[3] == 3
- #If chance/community chest/jail/free parking
- elif place[0] in notmade:
- pass
- #Buys property if currently not bought
- elif place[3] == 0:
- if player[1] > place[1]:
- player[1] -= place[1]
- place[3] = player[0]
- #Pays rent if owned by other player
- elif place[3] != 0 and place[3] != player[0]:
- player[1] -= place[2]
- players[(place[3]-1)][1] += place[2]
- #Accounting for a double
- if a == b:
- double += 1
- else:
- break
- double = 0
- ### For Game End
- if player1[1] <= 0:
- end = h
- break
- if player2[1] <= 0:
- end = h
- break
- #Printing the Statistics
- order1 = ["brown", "lblue", "pink", "orange", "red", "green", "dblue", "railroad", "utilities"]
- order2 = ["GO", "tax", "free parking", "jail", "go to jail", "chance", "chest"]
- #Finds number of digit of largest number
- length = 0
- for block in order1:
- for place in board[block]:
- if len(str(place[4])) > length:
- length = len(str(place[4]))
- if len(str(place[5])) > length:
- length = len(str(place[5]))
- number = 1
- #Frequency Displayer
- for i in range(4,6):
- if i == 4:
- print("Player 1 Frequency Statistics\n")
- if i == 5:
- print("\nPlayer 2 Frequency Statistics\n")
- for block in order1:
- for place in board[block]:
- print(" %s%d = %d" %(block, number, place[i]))
- number += 1
- number = 1
- #print("\n")
- for block in order2:
- for place in board[block]:
- print(" %s%d = %d" %(block, number, place[i-3]))
- number += 1
- number = 1
- #print("\n")
- #Total Frequency
- print("\nTotal Frequency\n")
- for block in order1:
- for place in board[block]:
- print(" %s%d = %d" %(block, number, place[4] + place[5]))
- number += 1
- number = 1
- #print("\n")
- for block in order2:
- for place in board[block]:
- print(" %s%d = %d" %(block, number, place[1] + place[2]))
- number += 1
- number = 1
- #print("\n")
- #Property Owner Displayer
- p1prop = []
- p2prop = []
- for block in order1:
- for place in board[block]:
- if place[3] == 1:
- p1prop.append("%s%d" %(block, number))
- elif place[3] == 2:
- p2prop.append("%s%d" %(block, number))
- number += 1
- number = 1
- print("\nPlayer 1 owns:\n")
- for prop in p1prop:
- print" ", prop
- print("\nPlayer 2 owns:\n")
- for prop in p2prop:
- print" ", prop
- print("\n")
- #Balance Displayer
- print("Player 1 Balance: %d" %(player1[1]))
- print("Player 2 Balance: %d" %(player2[1]))
- if player1[1] > player2[1]:
- print("\nPlayer 1 wins!")
- else:
- print("\nPlayer 2 wins!")
- print("Game ended on Round %d" %(end+1)) ### For Game End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement