Commit d18c6aeb authored by Yildius's avatar Yildius

Comments on player.py

parent 77168e0b
## class Player
# This class handles the status of a player, without much responsibility.
# It takes care of:
# - unique ID, name
# - player status (playing, busted, all-in, etc)
# - player's chips (until they are sent to the pot)
# - related pot (when side-pots occur)
# - hand handling (receives its holecards, computes its hand with boardcards)
# - comparison operator with another player (based and hand value)
#
from uuid import uuid4
from enum import Enum
from player.hand import Hand
class PlayerState(Enum):
PLAYING = 0
FOLDED = 1
......@@ -95,6 +107,14 @@ class Player:
# PRIVATE METHODS
def __putMoneyOnTable(self, amount):
## called by 'call' or 'bet', puts money from the player's stack on the
# table, but not yet on the pot.
# This methode is in charge of putting the player all-in if necessary,
# and makes sure that the player's stack is nto negative.
# Receives the expected amount to be extracted from the stack, and
# returns the amount that was actually extracted.
#
amountBet = 0
if self.isAllIn:
print("Player {} is already All In".format(self.__name))
return 0
......@@ -113,6 +133,7 @@ class Player:
# PUBLIC METHODS
def newHand(self):
# Reset status for the next hand.
self.__hasHadAction = False
if self.__chips:
self.__playerState = PlayerState.PLAYING
......@@ -121,12 +142,15 @@ class Player:
self.__hand = Hand()
self.__potId = -1
self.__won = False
# self.__position = pos # Players are caracterized by uid, no need ATM
def computeHand(self, boardCards):
## Towards the end of the hand, give the player the board cards and
# let him find out his hand (the best combination of 5 cards from the 5
# cards from the board and its 2 hole cards).
# Returns the computed best hand.
#
assert len(boardCards) == 5
cards = boardCards + self.__cards
# print("Hole cards {}, cards {}".format(len(self.__cards), len(cards)))
self.__hand = Hand(boardCards)
for i in range(len(cards)):
for j in range(i+1, len(cards)):
......@@ -134,7 +158,6 @@ class Player:
for k in range(len(cards)):
if k != i and k != j:
newHandCards += [cards[k]]
# print("({0}, {1})/{2} : {3}".format(i, j, len(cards), len(newHandCards)))
newHand = Hand(newHandCards)
if self.__hand < newHand:
self.__hand = newHand
......@@ -169,40 +192,41 @@ class Player:
def giveBB(self, bigBlind):
return self.__putMoneyOnTable(bigBlind)
# Actions, called by Table.
# By calling these methods, Table authorises the transaction.
# amount is the money added
# Returns the amount added
def bet(self, amount):
# amount is the money to be added
# Returns the amount actually added
self.__hasHadAction = True
self.__playerState = PlayerState.RAISED
return self.__putMoneyOnTable(amount)
# Returns True if succeeds
def check(self):
# Returns True if succeeds
self.__hasHadAction = True
self.__playerState = PlayerState.CHECKED
return True
# Returns the amount added
def call(self, amountToCall):
# Returns the amount added
self.__hasHadAction = True
self.__playerState = PlayerState.CALLED
return self.__putMoneyOnTable(amountToCall - self.__chipsOnTable)
# Returns True if succeeds
def fold(self):
# Returns True if succeeds
self.__hasHadAction = True
self.__playerState = PlayerState.FOLDED
return True
# Timeout, shouldn't be needed (just check/fold called from Table)
def yieldAction(self):
# Timeout, shouldn't be needed (just check/fold called from Table)
self.__hasHadAction = True
# returns player state (all in, playing, folded)
def state(self):
# returns player state (all in, playing, folded)
if self.__playerState == PlayerState.FOLDED:
return "FOLD"
if self.__playerState == PlayerState.ALL_IN:
......@@ -218,6 +242,7 @@ class Player:
return ""
def __lt__(self, player):
# Compare 2 players based on the value of their hand
assert self.isComparable()
assert player.isComparable()
return self.hand < player.hand
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