-
Notifications
You must be signed in to change notification settings - Fork 0
/
goldenballs_ver2.py
212 lines (179 loc) · 7.5 KB
/
goldenballs_ver2.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#Golden Balls Game (based off of UK TV Series) using print statements
from GoldenBank import GoldenBank
from DistributionPanel import DistributionPanel
from AI import AI
from User import User
from BinOrWinTable import BinOrWinTable
from SplitOrSteal import SplitOrSteal
from TheVote import TheVote
import random
class GoldenBalls:
def __init__(self):
self.goldenBank = GoldenBank("goldenballvalues.txt")
self.distributionPanel = DistributionPanel()
self.playerLyst = [User("user"), AI("com1"), AI("com2"), AI("com3")]
self.binOrWinTable = BinOrWinTable()
self.splitOrSteal = SplitOrSteal()
self.theVote = TheVote()
def newGame(self):
self.goldenBank.reset()
self.goldenBank.randomize()
self.distributionPanel.reset()
def roundOne(self):
print("Round 1 Started! \n")
#adds 12 balls to the distribution panel and 4 killers
self.addMoneyBallsToDistPanel(12)
self.addKillersToDistPanel(4)
self.distributeToPlayers()
self.displayToUser()
eliminated = self.theVote.findMajority(self.getVotes())
self.eliminate(eliminated)
if eliminated != "user":
self.roundTwo()
def roundTwo(self):
print("Round 2 Started! \n")
self.returnToDistPanel()
self.addMoneyBallsToDistPanel(2)
self.addKillersToDistPanel(1)
self.distributeToPlayers()
self.displayToUser()
eliminated = self.theVote.findMajority(self.getVotes())
self.eliminate(eliminated)
if eliminated != "user":
self.binOrWin()
def binOrWin(self):
'''binOrWin phase of the game'''
print("Bin or Win Started! \n")
self.returnToDistPanel()
self.addKillersToDistPanel(1)
self.binOrWinTable.addBalls(self.distributionPanel.returnBalls())
#user alternates in picking balls to bin and win
for i in range(5):
while True:
try:
userinput = int(input("Pick a Golden Ball from 1 to 11 that you HAVE NOT PICKED to BIN: "))
except:
print("Please only enter integer values between 1 and 11")
else:
binnedVal = self.binOrWinTable.binBall(int(userinput))
if binnedVal != "-1":
if binnedVal == "KILLER":
print("Congratulations! You have binned a KILLER ball!")
else:
print("You binned a golden ball with a value of... ", binnedVal)
break
else:
print("Please pick a ball number you haven't picked yet: ")
print(self.binOrWinTable.getRemainingBalls())
while True:
try:
userinput = int(input("Pick a Golden Ball from 1 to 11 that you HAVE NOT PICKED to WIN: "))
except:
print("Please only enter integer values between 1 and 11")
else:
winVal = self.binOrWinTable.winBall(int(userinput))
if winVal != "-1":
if winVal == "KILLER":
print("Oh no! You have picked a KILLER ball! Your pot value has been reduced by a factor of 10 :(")
else:
print("You added a golden ball with a value of... ", winVal, "to the pot!")
break
else:
print("Please pick a ball number you haven't picked yet: ")
print(self.binOrWinTable.getRemainingBalls())
#bin the last ball
lastBallNum = self.binOrWinTable.getRemainingBalls().strip()
print("The last ball, ball #", lastBallNum, ", has also been binned: ", sep="")
binnedVal = self.binOrWinTable.binBall(int(lastBallNum))
if binnedVal == "KILLER":
print("Congratulations! You have binned a KILLER ball!")
else:
print("You binned a golden ball with a value of... ", binnedVal, "\n")
print("Your final pot contains... ${:.2f}".format(self.binOrWinTable.getPot()))
#starts the splitOrSteal round
self.finalRound()
def finalRound(self):
#implement userDecision and comDecision
while True:
userDecision = input('''Are you going to SPLIT, STEAL, or COUNTER the \
pot of ${:.2f} with the computer? '''.format(self.binOrWinTable.getPot()))
if userDecision.upper() in "STEAL SPLIT COUNTER":
break
else:
print("Please only enter the phrases \"SPLIT\", \"STEAL\", or \"COUNTER\"")
#todo: implement trust factor
comDecision = random.choice(["SPLIT", "STEAL", "COUNTER"])
print("The computer has decided to...", comDecision)
proportions = self.splitOrSteal.makeDecision(userDecision.upper(), comDecision)
#todo: edit messages
print("You have won ${:.2f}!".format(proportions[0] * self.binOrWinTable.getPot()))
print("The computer has won ${:.2f}!".format(proportions[1] * self.binOrWinTable.getPot()))
def returnToDistPanel(self):
'''adds players' balls back to the distribution panel'''
for player in self.playerLyst:
for ball in player.returnBalls():
self.distributionPanel.addBall(ball)
def distributeToPlayers(self):
'''randomize and distribute balls to players'''
self.distributionPanel.randomize()
self.distributionPanel.distribute(self.playerLyst)
self.recalculateMultiplier()
def recalculateMultiplier(self):
'''recalculates the voting multiplier for AI to use in probability'''
for player in self.playerLyst:
player.resetMultiplier()
#TODO: implement feature to input people's own revelation of their back balls
player.calculateMultiplier(player.showFrontBalls())
def addMoneyBallsToDistPanel(self, n):
'''adds n money balls to distribution panel'''
for i in range(n):
self.distributionPanel.addBall(self.goldenBank.generateBall())
def addKillersToDistPanel(self, n):
'''adds n killer balls to distribution panel'''
for i in range(n):
self.distributionPanel.addKiller()
def displayToUser(self):
'''displays ALL of user's balls + front 2 of each other player'''
print("Your Golden Balls are...", self.playerLyst[0].showBalls())
for player in self.playerLyst[1:]:
print("The front balls of", player.getName(), "are...", player.showFrontBalls())
print()
def getPlayerNames(self):
'''returns string of player names'''
playerNames = ""
for player in self.playerLyst[1:]:
playerNames = playerNames + player.getName() + " "
return playerNames
def getUserVote(self):
'''takes user input and returns their valid vote'''
playerNames = self.getPlayerNames()
while True:
userinput = input("Who do you want vote to eliminate? \n")
if userinput.lower() in playerNames:
return userinput.lower()
else:
print("Please only input one of the following names: " + playerNames)
def eliminate(self, eliminated):
for i in range(len(self.playerLyst)):
if eliminated == self.playerLyst[i].getName():
print(self.playerLyst[i].getName(), "has been eliminated!")
print(self.playerLyst[i].getName() + "'s binned balls are " + str(self.playerLyst[i].showBalls()) + "\n")
self.playerLyst.pop(i)
return
def getVotes(self):
voteLyst = [self.getUserVote()]
for i in range(1, len(self.playerLyst[1:])+1):
compVote = self.playerLyst[i].getVote(self.playerLyst[:i] + self.playerLyst[i+1:])
print(self.playerLyst[i].getName(), "has voted for", compVote + "!")
voteLyst.append(compVote)
print()
return voteLyst
if __name__ == "__main__":
while True:
userinput = input("Press 'N' to start a new game! Press 'X' to stop playing...\n")
if userinput == 'X':
break
elif userinput == 'N':
goldenBallsGame = GoldenBalls()
goldenBallsGame.newGame()
goldenBallsGame.roundOne()