Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 4960c31d authored by Rémi Garde's avatar Rémi Garde

cleanup & bet proper testing the edge cases

parent bdb74d09
......@@ -38,6 +38,9 @@ class Player:
def uniqueId(self):
return self.__uniqueId
@property
def isAllIn(self):
return self.__isAllIn
# PRIVATE METHODS
def __putMoneyOnTable(self, amount):
......@@ -58,11 +61,11 @@ class Player:
return True
# PUBLIC METHODS
def newHand(self, pos):
def newHand(self):
self.__hasHadAction = False
self.__isPlaying = True
self.__isAllIn = False
self.__position = pos
# self.__position = pos # Players are caracterized by uid, no need ATM
def computeHand(self, boardCards):
assert len(boardCards) == 5
......@@ -80,7 +83,7 @@ class Player:
if self.__hand < newHand:
self.__hand = newHand
return self.__hand
def endTurn(self):
ans = self.__chipsOnTable
self.__chipsOnTable = 0
......@@ -91,7 +94,7 @@ class Player:
def receiveChip(self, chips):
self.__chips += chips
def yieldBet(self):
self.__hasHadAction = False
temp = self.__chipsOnTable
......@@ -130,9 +133,7 @@ class Player:
# returnedCards.append(self.__cards.pop())
print("Player {} fold".format(self.__uniqueId))
self.__isPlaying = False
# return returnedCards
return True
def yieldAction(self):
self.__hasHadAction = True
......@@ -46,7 +46,7 @@ class Table(object):
self.button = 0
self.currentBet = 0
self.handNbr = 0
def addPlayer(self, p):
p.receiveChip(self.buyIn)
self.waitingPlayers.append(p)
......@@ -54,7 +54,7 @@ class Table(object):
# Return the player at required position, 0 is button
def __playerAtPos(self, pos):
return (self.button + pos) % len(self.players)
# Passes action to the next player in the hand
def __nextPos(self):
playerFound = False
......@@ -68,11 +68,8 @@ class Table(object):
def startHand(self):
self.deck.reset()
self.currentBet = self.blind
# print(len(self.players))
# print([p.uniqueId for p in self.waitingPlayers])
if len(self.waitingPlayers):
self.players.extend(self.waitingPlayers)
# print([p.uniqueId for p in self.players])
for i in range(len(self.players)):
if self.players[i].getRemainingChips() <= 0:
del self.players[i]
......@@ -81,13 +78,11 @@ class Table(object):
self.activePlayer = self.__playerAtPos(3)
self.players[self.__playerAtPos(1)].giveSB(self.smallBlind)
self.players[self.__playerAtPos(2)].giveBB(self.blind)
# print([p.uniqueId for p in self.players])
for p in self.players:
p.receiveCards(self.deck.drawCard(), self.deck.drawCard())
p.newHand((i - self.button) % len(self.players))
p.newHand()
self.handNbr += 1
self.gameState = GameState.PREFLOP
# print([p.uniqueId for p in self.players])
print("Starting hand {0} with {1} players.".format(self.handNbr, len(self.players)))
print("Action to player {}.".format(self.activePlayer))
......@@ -168,9 +163,17 @@ class Table(object):
print("Cant call, action currently to player {}".format(self.activePlayer))
return False
def bet(self, playerId, amount):
def bet(self, playerId, amount): # bet_by
if self.activePlayer == playerId:
self.players[playerId].bet(amount)
player = self.players[playerId]
# Test if betting is covering the current table bet
if amount < player.getRemainingChips and amount + player.getChipsOnTable < self.getCurrentBet:
print("Did not bet enough!")
return False
if not player.bet(amount):
return False # Betting could not happen for some reason
if not player.isAllIn: # Player actually raised the current table bet
self.currentBet = player.getChipsOnTable()
self.__nextPos()
if self.isBettingDone():
self.__nextStep()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment