MonoLedger.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # A ledger and calculator for Monopoly games
  2. # Enables equal distributions to all (other) players
  3. # This was the original experiment
  4. numPlayers = 0
  5. accounts = []
  6. # accounts[0] is the pot, players are after that
  7. def printBalances():
  8. for account in accounts:
  9. print(account[0] + ": " + str(account[1]))
  10. def initialize():
  11. global numPlayers
  12. global accounts
  13. numPlayers = int(input("How many players (>1)? "))
  14. if numPlayers < 2:
  15. initialize()
  16. return
  17. startingValue = int(input("How much for each player? "))
  18. accounts.append(["Pot",0])
  19. while len(accounts) < numPlayers + 1:
  20. i = len(accounts)
  21. accounts.append(["Player " + str(i), startingValue])
  22. print ("Created:\n")
  23. printBalances()
  24. print("Let the game begin!\n")
  25. def play():
  26. global accounts
  27. playing = True
  28. while playing:
  29. option = input("[b]alances, [s]end, [q]uit: ")
  30. if option == "q":
  31. print("Game over!")
  32. playing = False
  33. if option == "b":
  34. printBalances()
  35. if option == "s":
  36. fromAcc = input("From (Choose pot, bank, or 1-" +
  37. str(numPlayers) + " for players): ")
  38. toAcc = input("To (Choose pot, bank, 1-" +
  39. str(numPlayers) +
  40. " for players, or all): ")
  41. amount = int((input("Amount (integer): ")))
  42. #DEBIT
  43. if fromAcc != "bank":
  44. if fromAcc == "pot":
  45. fromAcc = 0
  46. else:
  47. fromAcc = int(fromAcc)
  48. accounts[fromAcc][1] = accounts[fromAcc][1] - amount
  49. #CREDIT
  50. if toAcc != "bank":
  51. if toAcc == "all":
  52. remainder = amount
  53. i = 1
  54. while remainder > 0:
  55. if i != fromAcc:
  56. remainder -= 1
  57. accounts[i][1] += 1
  58. i += 1
  59. if i > numPlayers:
  60. i = 1
  61. else:
  62. if toAcc == "pot":
  63. toAcc = 0
  64. else:
  65. toAcc = int(toAcc)
  66. accounts[toAcc][1] = accounts[toAcc][1] + amount
  67. printBalances()
  68. initialize()
  69. play()