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 c6dc492c authored by Arnaud Chevalier's avatar Arnaud Chevalier

fixed player

parent 6b8b9e48
......@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.7 (POOker)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
......@@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (POOker)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -3,9 +3,12 @@ from hand import Hand
class Player:
idPlayers = int(0)
# INIT
def __init__(self):
self.__uniqueId = Player.idPlayers
Player.idPlayers += 1
self.__hand = Hand()
self.__chips = int(0)
self.__cards = []
......@@ -31,19 +34,24 @@ class Player:
def getRemainingChips(self):
return self.__chips
@property
def uniqueId(self):
return self.__uniqueId
# PRIVATE METHODS
def __putMoneyOnTable(self, amount):
if self.__isAllIn:
print("Player {} is already All In".format(self.__position))
print("Player {} is already All In".format(self.__uniqueId))
return False
else:
if amount >= self.__chips:
print("Player {} is All In".format(self.__position))
print("Player {} is All In".format(self.__uniqueId))
self.__isAllIn = True
self.__chipsOnTable += self.__chips
self.__chips = 0
else:
print("Player {} bet {}".format(self.__position, amount))
print("Player {} bet {}".format(self.__uniqueId, amount))
self.__isAllIn = False
self.__chips -= amount
self.__chipsOnTable += amount
......@@ -103,13 +111,13 @@ class Player:
def check(self):
self.__hasHadAction = True
# TODO
print("Player {} checked".format(self.__position))
print("Player {} checked".format(self.__uniqueId))
return True
def call(self, amountToCall):
self.__hasHadAction = True
# TODO check poker rules
print("Player {} called".format(self.__position))
print("Player {} called".format(self.__uniqueId))
deltaCall = amountToCall - self.__chipsOnTable
return self.__putMoneyOnTable(deltaCall)
......
......@@ -27,6 +27,7 @@ class GameState(Enum):
TURN = 3
RIVER = 4
class Table(object):
def __init__(self):
self.gameState = GameState.IDLE
......@@ -48,7 +49,7 @@ class Table(object):
def addPlayer(self, p):
p.receiveChip(self.buyIn)
self.waitingPlayers += [p]
self.waitingPlayers.append(p)
# Return the player at required position, 0 is button
def __playerAtPos(self, pos):
......@@ -67,8 +68,11 @@ 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 += 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]
......@@ -77,12 +81,15 @@ 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))
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))
def __nextStep(self):
for p in self.players:
......@@ -151,7 +158,7 @@ class Table(object):
def call(self, playerId):
if self.activePlayer == playerId:
self.players[playerId].call()
self.players[playerId].call(self.currentBet)
self.__nextPos()
if self.isBettingDone():
self.__nextStep()
......
import table
import player.player
t = table.Table()
player1 = player.player.Player()
print(player1.uniqueId)
player2 = player.player.Player()
print(player2.uniqueId)
t.addPlayer(player1)
t.addPlayer(player2)
t.startHand()
t.call(1)
t.bet(0, 1)
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