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

player admission fixed in cash game mode + front display hand string description at the end of hand

parent 77367f0f
......@@ -31,7 +31,7 @@
.name-chips {
width:140px;
height:33px;
height:auto;
background-color:indianred;
font-size: 14px;
color:white;
......@@ -52,6 +52,10 @@ div.name-chips[disabled=disabled] {
.chips {
}
.hand-str {
width:100%;
}
.card {
width:50px;
height:73px;
......@@ -277,7 +281,7 @@ div.name-chips[disabled=disabled] {
text-align: center;
width:90px;
left:450px;
top:425px;
top:460px;
}
#game-timer {
......@@ -289,7 +293,7 @@ div.name-chips[disabled=disabled] {
text-align: center;
width:90px;
left:350px;
top:425px;
top:460px;
}
.timer-normal {
......
......@@ -138,7 +138,7 @@ function setHoleCards(holeCards, players) {
resetPlayerHoleCards(i+1)
}
for (var i = 0; i < holeCards.length; i++) {
setPlayerHoleCards(holeCards[i].cards, holeCards[i].seatNumber)
setPlayerHoleCards(holeCards[i].cards, holeCards[i].seatNumber, holeCards[i].handStr)
}
}
......@@ -149,15 +149,21 @@ function resetPlayerHoleCards(seat) {
setNoCard(card1);
setNoCard(card2);
var handStr = $('#seat' + seat).children('.name-chips').children('.hand-str');
handStr.text('')
}
function setPlayerHoleCards(hc, seat) {
function setPlayerHoleCards(hc, seat, hand) {
var holecards = $('#seat' + seat).children('.holecards');
var card1 = holecards.children('.holecard1');
var card2 = holecards.children('.holecard2');
setCard(card1, hc[0]);
setCard(card2, hc[1]);
var handStr = $('#seat' + seat).children('.name-chips').children('.hand-str');
handStr.text(hand)
}
function setBoard(cards) {
......
......@@ -22,7 +22,7 @@ class Player:
self.__chipsOnTable = int(0)
self.__position = int(0)
self.__hasHadAction = bool(False)
self.__state = PlayerState.PLAYING
self.__playerState = PlayerState.PLAYING
self.__name = name
self.__potId = -1
self.__won = False
......@@ -30,15 +30,15 @@ class Player:
# GETTERS & SETTERS
@property
def isPlaying(self):
return self.__state == PlayerState.PLAYING
return self.__playerState == PlayerState.PLAYING
@property
def isInHand(self):
return self.__state == PlayerState.PLAYING or self.__state == PlayerState.ALL_IN
return self.__playerState == PlayerState.PLAYING or self.__playerState == PlayerState.ALL_IN
@property
def isAllIn(self):
return self.__state == PlayerState.ALL_IN
return self.__playerState == PlayerState.ALL_IN
@property
def getChipsOnTable(self):
......@@ -84,6 +84,10 @@ class Player:
def won(self, won):
self.__won = won
@property
def playerState(self):
return self.__playerState
def isComparable(self):
return self.__hand.isLoaded()
......@@ -95,7 +99,7 @@ class Player:
return 0
if amount >= self.__chips:
print("Player {} is All In".format(self.__name))
self.__state = PlayerState.ALL_IN
self.__playerState = PlayerState.ALL_IN
amountBet = self.__chips
self.__chipsOnTable += self.__chips
self.__chips = 0
......@@ -110,11 +114,11 @@ class Player:
def newHand(self):
self.__hasHadAction = False
if self.__chips:
self.__state = PlayerState.PLAYING
self.__playerState = PlayerState.PLAYING
else:
self.__state = PlayerState.BUSTED
self.__playerState = PlayerState.BUSTED
self.__hand = Hand()
self.potIt = -1
self.__potId = -1
self.__won = False
# self.__position = pos # Players are caracterized by uid, no need ATM
......@@ -186,7 +190,7 @@ class Player:
# Returns True if succeeds
def fold(self):
self.__hasHadAction = True
self.__state = PlayerState.FOLDED
self.__playerState = PlayerState.FOLDED
return True
# Timeout, shouldn't be needed (just check/fold called from Table)
......@@ -195,11 +199,11 @@ class Player:
# returns player state (all in, playing, folded)
def state(self):
if self.__state == PlayerState.FOLDED:
if self.__playerState == PlayerState.FOLDED:
return "FOLDED"
if self.__state == PlayerState.ALL_IN:
if self.__playerState == PlayerState.ALL_IN:
return "ALL IN"
if self.__state == PlayerState.BUSTED:
if self.__playerState == PlayerState.BUSTED:
return "BUSTED"
return ""
......
import time
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from flask_socketio import SocketIO, emit
from table import Table
from table import Table, PlayingMode
from player.player import Player
from game import Game
app = Flask(__name__, static_url_path='/front/')
......@@ -93,20 +93,32 @@ def game():
p = Player(name)
if gameId in games.keys():
currentTable = games[gameId].table
if len(currentTable.waitingPlayers) + len(currentTable.players) < currentTable.maxPlayers:
if currentTable.playingMode == PlayingMode.CASHGAME:
currentTable.addPlayer(p)
if len(currentTable.waitingPlayers) + len(currentTable.players) == currentTable.maxPlayers:
if len(currentTable.waitingPlayers) == currentTable.maxPlayers and not len(currentTable.players):
currentTable.startTime = time.time()
currentTable.startHand()
resp = redirect("/game?gameId="+gameId)
resp = redirect("/game?gameId=" + gameId)
resp.set_cookie("username", name)
print(p.uniqueId)
resp.set_cookie("userId", str(p.uniqueId))
games.get(gameId).bCastState()
return resp
else:
print("Table already full")
return redirect(url_for('homePage', message="Table already full"))
elif currentTable.playingMode == PlayingMode.TOURNOI:
if len(currentTable.waitingPlayers) + len(currentTable.players) < currentTable.maxPlayers:
currentTable.addPlayer(p)
if len(currentTable.waitingPlayers) + len(currentTable.players) == currentTable.maxPlayers:
currentTable.startTime = time.time()
currentTable.startHand()
resp = redirect("/game?gameId="+gameId)
resp.set_cookie("username", name)
print(p.uniqueId)
resp.set_cookie("userId", str(p.uniqueId))
games.get(gameId).bCastState()
return resp
else:
print("Table already full")
return redirect(url_for('homePage', message="Table already full"))
else:
print("Wrong game Id")
return redirect(url_for('homePage', message="Wrong game Id"))
......
......@@ -18,7 +18,7 @@ import threading
from card import Card
from hand import Hand
from deck import Deck
from player.player import Player
from player.player import Player, PlayerState
from tableTimer import TableTimer
import json
......@@ -103,6 +103,10 @@ class Table(object):
def startTime(self, startTime):
self.__startTime = startTime
@property
def playingMode(self):
return self.__playingMode
def setBCastCB(self, callback):
self.__bCastCB = callback
......@@ -148,9 +152,19 @@ class Table(object):
self.__boardCards = []
self.__currentBet = self.__blind
self.__minRaise = self.__blind
if len(self.__waitingPlayers):
self.__players.extend(self.__waitingPlayers)
self.__waitingPlayers = []
if self.__playingMode == PlayingMode.CASHGAME:
for (i, p) in enumerate(self.__players): # remove busted players in cash game and replace with waiting players
p.newHand()
print("ENUMERATE PLAYERS", p.playerState, p.name)
print(len(self.__waitingPlayers))
if p.playerState == PlayerState.BUSTED and len(self.__waitingPlayers) > 0:
print("replacing busted players")
self.__players[i] = self.__waitingPlayers.pop(0)
while len(self.__waitingPlayers) > 0 and len(self.__players) < self.__maxPlayers: # add players till the max number is reached
self.__players.append(self.__waitingPlayers.pop(0))
elif self.__playingMode == PlayingMode.TOURNOI:
while len(self.__waitingPlayers) > 0 and len(self.__players) < self.__maxPlayers: # add players till the max number is reached
self.__players.append(self.__waitingPlayers.pop(0))
nbrPlayers = 0
for p in self.__players:
p.newHand()
......@@ -187,7 +201,7 @@ class Table(object):
self.__button = self.__playerAtPos(1)
self.__bCastCB()
print("hallahhhhhhh")
self.__endOfHandTimer = threading.Timer(6, self.startHand)
self.__endOfHandTimer = threading.Timer(20, self.startHand)
self.__endOfHandTimer.start()
else:
if self.__gameState == GameState.PREFLOP:
......@@ -446,7 +460,7 @@ class Table(object):
rtn.append({
'cards': [card.json for card in p.holeCards],
'seatNumber': pId+1,
'handStr':p.hand.handStr()
'handStr': p.hand.handStr()
})
else:
player = self.__players[userIndex]
......
......@@ -19,6 +19,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 1</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......@@ -31,6 +32,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 2</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......@@ -44,6 +46,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 3</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......@@ -58,6 +61,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 4</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......@@ -72,6 +76,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 5</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......@@ -86,6 +91,7 @@
<div class="name-chips" disabled="disabled">
<div class="player-name">Player 6</div>
<div class="chips">$1000.00</div>
<div class="hand-str"></div>
</div>
<div class="bet">$80.00</div>
</div>
......
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