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 e9423438 authored by Yildius's avatar Yildius

Print fixes and cosmetic

parent 6924d33b
......@@ -21,6 +21,7 @@ class Player:
self.__name = name
# GETTERS & SETTERS
@property
def isPlaying(self):
return self.__isPlaying
......
......@@ -64,15 +64,15 @@ class Table(object):
playerFound = False
while not playerFound:
self.activePlayer = (self.activePlayer + 1) % len(self.players)
if self.players[self.activePlayer].isPlaying():
if self.players[self.activePlayer].isPlaying:
playerFound = True
print("Action to player {}.".format(self.activePlayer))
print("Action to player {}.".format(self.players[self.activePlayer].name))
print("Pot {}, min raise {}".format(self.pot, self.minRaise))
for p in self.players:
if p.isPlaying:
print("Player {} : {} ({} chips)".format(p.uniqueId, p.getChipsOnTable, p.getRemainingChips))
print("Player {} : {} ({} chips)".format(p.name, p.getChipsOnTable, p.getRemainingChips))
else:
print("Player {} : out ({} chips)".format(p.uniqueId, p.getRemainingChips))
print("Player {} : out ({} chips)".format(p.name, p.getRemainingChips))
return self.activePlayer
def startHand(self):
......@@ -98,8 +98,8 @@ class Table(object):
self.gameState = GameState.PREFLOP
print("Starting hand {0} with {1} players.".format(self.handNbr, len(self.players)))
for p in self.players:
print("Player {} : {} chips".format(p.uniqueId, p.getRemainingChips))
print("Action to player {}.".format(self.activePlayer))
print("Player {} : {} chips".format(p.name, p.getRemainingChips))
print("Action to player {}.".format(self.players[self.activePlayer].name))
def __nextStep(self):
for p in self.players:
......@@ -112,13 +112,13 @@ class Table(object):
self.players[winner].receiveChip(self.pot)
self.pot = 0
self.button = self.__playerAtPos(1)
print("Hand ended, player {0} won.".format(winner))
print("Hand ended, player {0} won.".format(self.players[winner].name))
self.startHand()
elif self.gameState == GameState.RIVER:
remainingPlayerIds = []
for i in range(len(self.players)):
self.players[i].computeHand(self.boardCards)
if self.players[i].isPlaying():
if self.players[i].isPlaying:
remainingPlayerIds.append(i)
winner = remainingPlayerIds[0]
for i in remainingPlayerIds:
......@@ -175,19 +175,20 @@ class Table(object):
if self.nbrPlayersInHand <= 1:
return True
for p in self.players:
if p.isPlaying() and (not p.hasHadAction or p.getChipsOnTable != self.currentBet):
if p.isPlaying and (not p.hasHadAction or p.getChipsOnTable != self.currentBet):
return False
return True
def fold(self, playerId):
p = self.players[playerId]
if self.activePlayer != playerId:
print("Player {} cant fold, action currently to player {}".format(playerId, self.activePlayer))
print("Player {} cant fold, action currently to player {}".format(p.name, self.activePlayer))
return False
if not self.players[playerId].fold():
print("Player {} cant fold, fold failed (unexpected).".format(playerId))
if not p.fold():
print("Player {} cant fold, fold failed (unexpected).".format(p.name))
return False # fold could not happen for some reason
self.nbrPlayersInHand -= 1
print("Player {} folded.".format(playerId))
print("Player {} folded.".format(p.name))
if self.isBettingDone():
self.__nextStep()
else:
......@@ -195,16 +196,17 @@ class Table(object):
return True
def check(self, playerId):
p = self.players[playerId]
if self.activePlayer != playerId:
print("Player {} cant check, action currently to player {}".format(playerId, self.activePlayer))
print("Player {} cant check, action currently to player {}".format(p.name, self.activePlayer))
return False
if self.players[playerId].getChipsOnTable != self.currentBet:
print("Player {} cant check, needs to call ({}/{})".format(playerId, self.players[playerId].getChipsOnTable, self.currentBet))
if p.getChipsOnTable != self.currentBet:
print("Player {} cant check, needs to call ({}/{})".format(p.name, self.players[playerId].getChipsOnTable, self.currentBet))
return False
if not self.players[playerId].check():
print("Player {} cant check, check failed (unexpected).".format(playerId))
if not p.check():
print("Player {} cant check, check failed (unexpected).".format(p.name))
return False # Check could not happen for some reason
print("Player {} checked.".format(playerId))
print("Player {} checked.".format(p.name))
if self.isBettingDone():
self.__nextStep()
else:
......@@ -212,14 +214,15 @@ class Table(object):
return True
def call(self, playerId):
p = self.players[playerId]
if self.activePlayer != playerId:
print("Player {} cant call, action currently to player {}".format(playerId, self.activePlayer))
print("Player {} cant call, action currently to player {}".format(p.name, self.activePlayer))
return False
amountCalled = self.players[playerId].call(self.currentBet)
amountCalled = p.call(self.currentBet)
if not amountCalled:
print("Player {} cant call, call failed (unexpected).".format(playerId))
print("Player {} cant call, call failed (unexpected).".format(p.name))
return False # call could not happen for some reason
print("Player {} called {} ({} more).".format(playerId, self.currentBet, amountCalled))
print("Player {} called {} ({} more).".format(p.name, self.currentBet, amountCalled))
if self.isBettingDone():
self.__nextStep()
else:
......@@ -227,23 +230,24 @@ class Table(object):
return True
def bet(self, playerId, amount): # bet_by
p = self.players[playerId]
if self.activePlayer != playerId:
print("Player {} cant bet, action currently to player {}".format(playerId, self.activePlayer))
print("Player {} cant bet, action currently to player {}".format(p.name, self.activePlayer))
return False
if amount + self.players[playerId].getChipsOnTable < self.currentBet + self.minRaise:
print("Player {} cant bet, not adding enough money (would be {}/{})".format(playerId, amount + self.players[playerId].getChipsOnTable, self.currentBet + self.minRaise))
if amount + p.getChipsOnTable < self.currentBet + self.minRaise:
print("Player {} cant bet, not adding enough money (would be {}/{})".format(p.name, amount + p.getChipsOnTable, self.currentBet + self.minRaise))
return False
if amount > self.players[playerId].getRemainingChips:
print("Player {} cant bet, not enough money ({}/{})".format(playerId, self.activePlayer, amount, self.players[playerId].getRemainingChips))
if amount > p.getRemainingChips:
print("Player {} cant bet, not enough money ({}/{})".format(p.name, amount, self.players[playerId].getRemainingChips))
return False
if not self.players[playerId].bet(amount):
print("Player {} cant bet, betting failed (unexpected).".format(playerId))
if not p.bet(amount):
print("Player {} cant bet, betting failed (unexpected).".format(p.name))
return False # Betting could not happen for some reason
if not self.currentBet:
self.minRaise = amount
if self.players[playerId].getChipsOnTable > self.currentBet:
self.currentBet = self.players[playerId].getChipsOnTable
print("Player {} added {}, current bet to {}, minraise at {}.".format(playerId, amount, self.currentBet, self.minRaise))
if p.getChipsOnTable > self.currentBet:
self.currentBet = p.getChipsOnTable
print("Player {} added {}, current bet to {}, minraise at {}.".format(p.name, amount, self.currentBet, self.minRaise))
if self.isBettingDone():
self.__nextStep()
else:
......@@ -266,7 +270,7 @@ class Table(object):
"players": [{
"name": player.name,
"chips": player.getRemainingChips,
"isActive": player.isPlaying(),
"isActive": player.isPlaying,
"chipsOnTable": player.getChipsOnTable,
} for player in self.players],
"holeCards": self._getHoleCards(userId)
......
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