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

front fix

parent e153c11f
......@@ -57,11 +57,9 @@ function updateGameState() {
url: '/api/game/' + gameId,
// data: id
success: function (msg) {
$("#history").text(JSON.stringify(msg));
catchUp(msg)
},
error: function (msg) {
$("#history").text(JSON.stringify(msg))
}
})
}
......@@ -204,7 +202,8 @@ function setCurrentPot(amount) {
}
function checkClicked() {
$('#history').append("\n you clicked check");
var history = document.getElementById('history');
history.innerHTML += 'You clicked CHECK <br>';
var url = '/api/game/' + gameId + "/action";
console.log(url);
$.ajax({
......@@ -215,14 +214,14 @@ function checkClicked() {
},
dataType: 'json',
success: function (msg) {
$("#history").text(JSON.stringify(msg));
catchUp(msg)
}
})
}
function foldClicked() {
$('#history').append("\n you clicked fold");
var history = document.getElementById('history');
history.innerHTML += 'You clicked FLOD <br>';
var url = '/api/game/' + gameId + "/action";
console.log(url);
$.ajax({
......@@ -233,14 +232,14 @@ function foldClicked() {
},
dataType: 'json',
success: function (msg) {
$("#history").text(JSON.stringify(msg));
catchUp(msg)
}
})
}
function callClicked() {
$('#history').append("/\n/ you clicked call");
var history = document.getElementById('history');
history.innerHTML += 'You clicked CALL <br>';
var url = '/api/game/' + gameId + "/action";
console.log(url);
$.ajax({
......@@ -251,14 +250,14 @@ function callClicked() {
},
dataType: 'json',
success: function (msg) {
$("#history").text(JSON.stringify(msg));
catchUp(msg)
}
})
}
function raiseClicked() {
$('#history').append("\n you clicked raise");
var history = document.getElementById('history');
history.innerHTML += 'You clicked RAISE <br>';
var url = '/api/game/' + gameId + "/action";
console.log(url);
var amount = document.forms[0].amount.value;
......@@ -271,7 +270,6 @@ function raiseClicked() {
},
dataType: 'json',
success: function (msg) {
$("#history").text(JSON.stringify(msg));
catchUp(msg)
}
})
......@@ -317,7 +315,6 @@ socket.on('connect', function () {
socket.on('state', function(msg) {
state = JSON.parse(msg);
$("#history").text(msg);
console.log("receive msg");
catchUp(state)
});
......@@ -8,6 +8,9 @@ class PlayerState(Enum):
FOLDED = 1
ALL_IN = 2
BUSTED = 3
CALLED = 4
CHECKED = 5
RAISED = 6
class Player:
......@@ -29,11 +32,11 @@ class Player:
# GETTERS & SETTERS
@property
def isPlaying(self):
return self.__playerState == PlayerState.PLAYING
return self.__playerState == PlayerState.PLAYING or self.__playerState == PlayerState.CHECKED or self.__playerState == PlayerState.CALLED or self.__playerState == PlayerState.RAISED
@property
def isInHand(self):
return self.__playerState == PlayerState.PLAYING or self.__playerState == PlayerState.ALL_IN
return self.__playerState == PlayerState.PLAYING or self.__playerState == PlayerState.CHECKED or self.__playerState == PlayerState.CALLED or self.__playerState == PlayerState.RAISED or self.__playerState == PlayerState.ALL_IN
@property
def isAllIn(self):
......@@ -92,7 +95,6 @@ class Player:
# PRIVATE METHODS
def __putMoneyOnTable(self, amount):
amountBet = 0
if self.isAllIn:
print("Player {} is already All In".format(self.__name))
return 0
......@@ -168,22 +170,25 @@ class Player:
return self.__putMoneyOnTable(bigBlind)
# Actions, called by Table.
# By calling these methodes, Table authorises the transaction.
# By calling these methods, Table authorises the transaction.
# amount is the money added
# Returns the amount added
def bet(self, amount):
self.__hasHadAction = True
self.__playerState = PlayerState.RAISED
return self.__putMoneyOnTable(amount)
# Returns True if succeeds
def check(self):
self.__hasHadAction = True
self.__playerState = PlayerState.CHECKED
return True
# Returns the amount added
def call(self, amountToCall):
self.__hasHadAction = True
self.__playerState = PlayerState.CALLED
return self.__putMoneyOnTable(amountToCall - self.__chipsOnTable)
# Returns True if succeeds
......@@ -199,11 +204,17 @@ class Player:
# returns player state (all in, playing, folded)
def state(self):
if self.__playerState == PlayerState.FOLDED:
return "FOLDED"
return "FOLD"
if self.__playerState == PlayerState.ALL_IN:
return "ALL IN"
if self.__playerState == PlayerState.BUSTED:
return "BUSTED"
if self.__playerState == PlayerState.CALLED:
return "CALL"
if self.__playerState == PlayerState.CHECKED:
return "CHECK"
if self.__playerState == PlayerState.RAISED:
return "RAISE"
return ""
def __lt__(self, player):
......
......@@ -93,6 +93,7 @@ def game():
p = Player(name)
if gameId in games.keys():
currentTable = games[gameId].table
# Players new players are added to the waiting line, they will be admitted to the game when a player is busted
if currentTable.playingMode == PlayingMode.CASHGAME:
currentTable.addPlayer(p)
if len(currentTable.waitingPlayers) == currentTable.maxPlayers and not len(currentTable.players):
......@@ -104,6 +105,7 @@ def game():
resp.set_cookie("userId", str(p.uniqueId))
games.get(gameId).bCastState()
return resp
# No more player than the maximum number of players can be admitted, players are eliminated until 1 last remains
elif currentTable.playingMode == PlayingMode.TOURNOI:
if len(currentTable.waitingPlayers) + len(currentTable.players) < currentTable.maxPlayers:
currentTable.addPlayer(p)
......
......@@ -8,8 +8,7 @@
# t.call(1)
# t.call(0)
# Then repeat the last 2 at will
#
# TODO: fix bug with wrong player action at the start of the second hand.
import time
from math import exp
from uuid import uuid4
......@@ -199,8 +198,11 @@ class Table(object):
self.__givePot()
self.__button = self.__playerAtPos(1)
self.__bCastCB()
print("hallahhhhhhh")
self.__endOfHandTimer = threading.Timer(20, self.startHand)
if self.__gameState == GameState.HAND_ENDED_NO_SHOW:
t = 5
else:
t = 10
self.__endOfHandTimer = threading.Timer(t, self.startHand)
self.__endOfHandTimer.start()
else:
if self.__gameState == GameState.PREFLOP:
......@@ -262,11 +264,9 @@ class Table(object):
def __givePot(self):
# Only one player left
if self.__nbrPlayersInHand == 1:
winner = 0
winningPlayer = self.__players[0]
for (i, p) in enumerate(self.__players):
if p.isPlaying:
winner = i
winningPlayer = p
print("Hand ended, player {} won {}.".format(winningPlayer.name, self.__pots[0]))
winningPlayer.won = True
......@@ -371,7 +371,7 @@ class Table(object):
def __fold(self, p):
if not p.fold():
print("Player {} cant fold, fold failed (unexpected).".format(p.name))
return False # fold could not happen for some reason
return False # fold could not happen for some reason
self.__nbrPlayersInHand -= 1
print("Player {} folded.".format(p.name))
return True
......@@ -455,7 +455,7 @@ class Table(object):
elif self.__gameState == GameState.HAND_ENDED:
for pId in range(len(self.__players)):
p = self.__players[pId]
if p.isPlaying:
if p.isInHand:
rtn.append({
'cards': [card.json for card in p.holeCards],
'seatNumber': pId+1,
......@@ -522,14 +522,14 @@ class Table(object):
self.__smallBlind = val / 2
"""
t = Table(3, 0)
p0 = Player("p0")
p1 = Player("p1")
p2 = Player("p2")
t.addPlayer(p0)
t.addPlayer(p1)
t.addPlayer(p2)
t.startHand()
"""
# """
# t = Table(3, 0)
# p0 = Player("p0")
# p1 = Player("p1")
# p2 = Player("p2")
# t.addPlayer(p0)
# t.addPlayer(p1)
# t.addPlayer(p2)
#
# t.startHand()
# """
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