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

New all-in system

parent 5271288c
import json
from uuid import uuid4
from enum import Enum
from hand import Hand
class PlayerState(Enum):
PLAYING = 0
FOLDED = 1
ALL_IN = 2
BUSTED = 3
class Player:
......@@ -14,14 +22,23 @@ class Player:
self.__chipsOnTable = int(0)
self.__position = int(0)
self.__hasHadAction = bool(False)
self.__isPlaying = bool(False)
self.__isAllIn = bool(False)
self.__state = PlayerState.PLAYING
self.__name = name
self.potId = -1
self.won = False
# GETTERS & SETTERS
@property
def isPlaying(self):
return self.__isPlaying
return self.__state == PlayerState.PLAYING
@property
def isInHand(self):
return self.__state == PlayerState.PLAYING or self.__state == PlayerState.ALL_IN
@property
def isAllIn(self):
return self.__state == PlayerState.ALL_IN
@property
def getChipsOnTable(self):
......@@ -47,29 +64,27 @@ class Player:
def uniqueId(self):
return self.__uniqueId
@property
def isAllIn(self):
return self.__isAllIn
@property
def name(self):
return self.__name
def isComparable(self):
return self.__hand.isLoaded()
# PRIVATE METHODS
def __putMoneyOnTable(self, amount):
amountBet = 0
if self.__isAllIn:
if self.isAllIn:
print("Player {} is already All In".format(self.__name))
return 0
if amount >= self.__chips:
print("Player {} is All In".format(self.__name))
self.__isAllIn = True
self.__state = PlayerState.ALL_IN
amountBet = self.__chips
self.__chipsOnTable += self.__chips
self.__chips = 0
else:
print("Player {} bet {}".format(self.__name, amount))
self.__isAllIn = False
amountBet = amount
self.__chips -= amount
self.__chipsOnTable += amount
......@@ -78,8 +93,13 @@ class Player:
# PUBLIC METHODS
def newHand(self):
self.__hasHadAction = False
self.__isPlaying = True
self.__isAllIn = False
if self.__chips:
self.__state = PlayerState.PLAYING
else:
self.__state = PlayerState.BUSTED
self.__hand = Hand()
self.potIt = -1
self.won = False
# self.__position = pos # Players are caracterized by uid, no need ATM
def computeHand(self, boardCards):
......@@ -116,6 +136,12 @@ class Player:
self.__chipsOnTable = 0
return temp
def yieldPartialBet(self, value):
self.__hasHadAction = False
chips = min(value, self.__chipsOnTable)
self.__chipsOnTable -= chips
return chips
def giveSB(self, smallBlind):
return self.__putMoneyOnTable(smallBlind)
......@@ -144,7 +170,7 @@ class Player:
# Returns True if succeeds
def fold(self):
self.__hasHadAction = True
self.__isPlaying = False
self.__state = PlayerState.FOLDED
return True
# Timeout, shouldn't be needed (just check/fold called from Table)
......@@ -153,9 +179,15 @@ class Player:
# returns player state (all in, playing, folded)
def state(self):
if not self.__isPlaying:
if self.__state == PlayerState.FOLDED:
return "FOLDED"
elif self.__isAllIn:
if self.__state == PlayerState.ALL_IN:
return "ALL IN"
else:
return ""
if self.__state == PlayerState.BUSTED:
return "BUSTED"
return ""
def __lt__(self, player):
assert self.isComparable()
assert player.isComparable()
return self.hand < player.hand
This diff is collapsed.
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