From 52a2a08058bcf290a9bcad4ae6141dd2431a7f36 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 3 Jul 2020 21:43:02 -0400 Subject: [PATCH 01/12] Try fix for infinite loop all-in --- src/app.js | 2 +- src/classes/game.js | 45 +++++++++++++++++++------------------------ src/classes/player.js | 16 --------------- 3 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/app.js b/src/app.js index 7067bd4..b9aefba 100644 --- a/src/app.js +++ b/src/app.js @@ -23,7 +23,7 @@ io.on('connection', (socket) => { let code; do { code = "" + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10); - } while (rooms.length != 0 && (rooms.some(r => r.getCode == code))); + } while (rooms.length != 0 && (rooms.some(r => r.getCode() === code))); const game = new Game(code, data.username); rooms.push(game); game.addPlayer(data.username, socket); diff --git a/src/classes/game.js b/src/classes/game.js index 6f245c2..f751696 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -1,7 +1,6 @@ // server-side game logic for a texas hold 'em game const Deck = require('./deck.js'); const Player = require('./player.js'); -const Card = require('./card.js'); const Hand = require('pokersolver').Hand; const Game = function (name, host) { @@ -14,12 +13,12 @@ const Game = function (name, host) { this.gameWinner = null; this.gameName = name; this.roundNum = 0; - this.roundData = { + this.roundData = { dealer: 0, - bigBlind: '', - smallBlind: '', - turn: '', - bets: [] + bigBlind: '', + smallBlind: '', + turn: '', + bets: [] }; this.community = []; this.foldPot = 0; @@ -207,17 +206,17 @@ const Game = function (name, host) { this.playerIsChecked = (playr) => { if (this.roundData.bets) { - const bets = this.getCurrentRoundBets() || []; + const bets = this.getCurrentRoundBets() || []; return bets.some(a => ((a.player == playr.getUsername()) && (a.bet == 0))); } } this.findFirstToGoPlayer = () => { - if (this.players[this.roundData.smallBlind].getStatus() == 'Fold') { + if (this.players[this.roundData.smallBlind].getStatus() == 'Fold' || this.players[this.roundData.smallBlind].allIn) { let index = this.roundData.smallBlind; do { index = (index - 1 < 0) ? (this.players.length - 1) : index - 1; - } while (this.players[index].getStatus() == 'Fold'); + } while (this.players[index].getStatus() == 'Fold' || this.players[index].allIn); return index; } else { return this.roundData.smallBlind; @@ -387,6 +386,16 @@ const Game = function (name, host) { return totalBetInStage; } + this.getTotalInvested = (player) => { + return this.getPlayerBetInStageNum(player, 1) + this.getPlayerBetInStageNum(player, 2) + + this.getPlayerBetInStageNum(player, 3) + this.getPlayerBetInStageNum(player, 4); + } + + // this.distributeMoney = (winners) => { + // const playerInvestments = this.players.map(p => ({ 'player': p, 'invested': this.getTotalInvested(player) })); + // console.log(playerInvestments); + // } + this.distributeMoney = (winners) => { const numWinners = winners.length; const potTotal = this.getCurrentPot(); @@ -457,12 +466,7 @@ const Game = function (name, host) { sidepot4.push({ bet: this.roundData.bets[3][i].bet, players: [this.roundData.bets[3][i].player] }) } } - this.log('sidepot 1 ' + JSON.stringify(sidepot1)); - this.log('sidepot 2 ' + JSON.stringify(sidepot2)); - this.log('sidepot 3 ' + JSON.stringify(sidepot3)); - this.log('sidepot 4 ' + JSON.stringify(sidepot4)); let winnings = 0; - //NOTE: does not handle more than two winners correctly yet for (const pot of sidepot1) { if (pot.players.includes(winner.getUsername())) { if (winners.length == 1) @@ -592,7 +596,7 @@ const Game = function (name, host) { player.money += toAdd; } } else if (potRemaining < 0) { - this.log('yikes'); + this.log('yikes'); } } @@ -763,7 +767,6 @@ const Game = function (name, host) { this.dealCards(); this.emitPlayers('startGame', { 'players': this.players.map(p => { return p.username; }) }); this.startNewRound(); - this.printPretty(); }; this.dealCards = () => { @@ -803,14 +806,6 @@ const Game = function (name, host) { return { socket: { id: 0 } }; }; - this.printPretty = () => { - this.log('----------------- GAME'); - this.log('Status', this.status); - this.log('Players:'); - this.players.map(p => p.printPretty()); - this.log('----------------- GAME'); - }; - this.disconnectPlayer = (player) => { this.disconnectedPlayers.push(player); if (player.getStatus() == 'Their Turn') { @@ -831,7 +826,7 @@ const Game = function (name, host) { this.checkBigBlindWent = (socket) => { if (this.findPlayer(socket.id).blindValue == 'Big Blind' && this.roundData.bets.length == 1) { this.bigBlindWent = true; - } + } } this.getCurrentRoundBets = () => { diff --git a/src/classes/player.js b/src/classes/player.js index e82c519..e37c7b3 100644 --- a/src/classes/player.js +++ b/src/classes/player.js @@ -12,8 +12,6 @@ const Player = function (playerName, socket, debug) { this.goAgainStatus = false; this.debug = debug || false; - const constructor = function () { }(this); - this.addCard = (card) => { this.cards.push(card); }; @@ -37,20 +35,6 @@ const Player = function (playerName, socket, debug) { this.emit = (eventName, payload) => { this.socket.emit(eventName, payload); }; - - this.printPretty = () => { - let cardsMsg = 'Cards: '; - for (i = 0; i < this.cards.length; i++) { - cardsMsg += this.cards[i].getValue() + " " + this.cards[i].getSuit() + ', '; - } - - this.log('----------------- PLAYER'); - this.log('Username:', this.username); - this.log(cardsMsg); - this.log('SocketID: ', this.socket.id); - this.log('----------------- PLAYER'); - }; - }; module.exports = Player; \ No newline at end of file From ad440e11d6770f946d2c5c33b1b8c0f3ebb98909 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 6 Jul 2020 03:20:09 -0400 Subject: [PATCH 02/12] Implement working distributeMoney() method --- src/classes/game.js | 432 ++++++++++++++++++++++++-------------------- 1 file changed, 232 insertions(+), 200 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index f751696..9253420 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -389,217 +389,249 @@ const Game = function (name, host) { this.getTotalInvested = (player) => { return this.getPlayerBetInStageNum(player, 1) + this.getPlayerBetInStageNum(player, 2) + this.getPlayerBetInStageNum(player, 3) + this.getPlayerBetInStageNum(player, 4); - } - // this.distributeMoney = (winners) => { - // const playerInvestments = this.players.map(p => ({ 'player': p, 'invested': this.getTotalInvested(player) })); - // console.log(playerInvestments); - // } + } this.distributeMoney = (winners) => { - const numWinners = winners.length; - const potTotal = this.getCurrentPot(); - const potEligible = Math.floor(potTotal / numWinners); - let potRemaining = potTotal; - this.log('winners: ' + winners.map((w) => w.username).toString()); - for (const winner of winners) { - if (winner.allIn || winner.getMoney() == 0) { - // calculate what all-in player is eligible for (side pot calculation). - // returns money to players - let sidepot1 = []; - let sidepot2 = []; - let sidepot3 = []; - let sidepot4 = []; - for (let i = 0; i < 4; i++) { - this.roundData.bets[i] = this.roundData.bets[i].filter(a => typeof a.bet === 'number'); - this.roundData.bets[i].sort((a, b) => a.bet - b.bet); - } - for (let i = 0; i < this.roundData.bets[0].length; i++) { - if (sidepot1.some(a => this.roundData.bets[0][i].bet == a.bet)) { - for (let j = 0; j < sidepot1.length; j++) { - if (sidepot1[j].bet == this.roundData.bets[0][i].bet) { - let pot = sidepot1[j]; - pot.players.push(this.roundData.bets[0][i].player); - sidepot1[j] = pot; - } - } - } else { - sidepot1.push({ bet: this.roundData.bets[0][i].bet, players: [this.roundData.bets[0][i].player] }) - } - } - for (let i = 0; i < this.roundData.bets[1].length; i++) { - if (sidepot2.some(a => this.roundData.bets[1][i].bet == a.bet)) { - for (let j = 0; j < sidepot2.length; j++) { - if (sidepot2[j].bet == this.roundData.bets[1][i].bet) { - let pot = sidepot2[j]; - pot.players.push(this.roundData.bets[1][i].player); - sidepot2[j] = pot; - } - } - } else { - sidepot2.push({ bet: this.roundData.bets[1][i].bet, players: [this.roundData.bets[1][i].player] }) - } - } - for (let i = 0; i < this.roundData.bets[2].length; i++) { - if (sidepot3.some(a => this.roundData.bets[2][i].bet == a.bet)) { - for (let j = 0; j < sidepot3.length; j++) { - if (sidepot3[j].bet == this.roundData.bets[2][i].bet) { - let pot = sidepot3[j]; - pot.players.push(this.roundData.bets[2][i].player); - sidepot3[j] = pot; - } - } - } else { - sidepot3.push({ bet: this.roundData.bets[2][i].bet, players: [this.roundData.bets[2][i].player] }) - } - } - for (let i = 0; i < this.roundData.bets[3].length; i++) { - if (sidepot4.some(a => this.roundData.bets[3][i].bet == a.bet)) { - for (let j = 0; j < sidepot4.length; j++) { - if (sidepot4[j].bet == this.roundData.bets[3][i].bet) { - let pot = sidepot4[j]; - pot.players.push(this.roundData.bets[3][i].player); - sidepot4[j] = pot; - } - } - } else { - sidepot4.push({ bet: this.roundData.bets[3][i].bet, players: [this.roundData.bets[3][i].player] }) - } - } - let winnings = 0; - for (const pot of sidepot1) { - if (pot.players.includes(winner.getUsername())) { - if (winners.length == 1) - winnings += pot.bet * pot.players.length; - else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - winnings += (pot.bet * pot.players.length) / winners.length; - } - } - } else { - for (const player of pot.players) { - //return money - let playerObj = this.players.find(a => a.getUsername() == player); - if (playerObj == undefined) { this.log('yikes'); break; } - if (winners.length == 1) { - const toAdd = Math.floor(pot.bet / pot.players.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } - } - } - } - } - for (const pot of sidepot2) { - if (pot.players.includes(winner.getUsername())) { - if (winners.length == 1) - winnings += pot.bet * pot.players.length; - else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - winnings += (pot.bet * pot.players.length) / winners.length; - } - } - } else { - for (const player of pot.players) { - //return money - let playerObj = this.players.find(a => a.getUsername() == player); - if (playerObj == undefined) { this.log('yikes'); break; } - if (winners.length == 1) { - const toAdd = Math.floor(pot.bet / pot.players.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } - } - } - } - } - for (const pot of sidepot3) { - if (pot.players.includes(winner.getUsername())) { - if (winners.length == 1) - winnings += pot.bet * pot.players.length; - else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - winnings += (pot.bet * pot.players.length) / winners.length; - } - } - } else { - for (const player of pot.players) { - //return money - let playerObj = this.players.find(a => a.getUsername() == player); - if (playerObj == undefined) { this.log('yikes'); break; } - if (winners.length == 1) { - const toAdd = Math.floor(pot.bet / pot.players.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } - } - } - } - } - for (const pot of sidepot4) { - if (pot.players.includes(winner.getUsername())) { - if (winners.length == 1) - winnings += pot.bet * pot.players.length; - else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - winnings += (pot.bet * pot.players.length) / winners.length; - } - } - } else { - for (const player of pot.players) { - //return money - let playerObj = this.players.find(a => a.getUsername() == player); - if (playerObj == undefined) { this.log('yikes'); break; } - if (winners.length == 1) { - const toAdd = Math.floor(pot.bet / pot.players.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } else { - if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - playerObj.money = playerObj.money + toAdd; - potRemaining -= toAdd; - } - } - } - } + let playerInvestments = this.players.map(p => ({ 'player': p, 'invested': this.getTotalInvested(p), 'result': -this.getTotalInvested(p) })); + + let winnerPot = winners.reduce((acc, currPlayer) => acc + this.getTotalInvested(currPlayer), 0); + + const endHandPlayerData = []; + while (playerInvestments.length > 1) { + const minStack = playerInvestments.reduce((acc, curr) => acc.invested < curr.invested ? acc.invested : curr.invested); + winnerPot += minStack * playerInvestments.length; + for (p of playerInvestments) { + p.invested -= minStack; + } + for (p of playerInvestments) { + if (winners.includes(p.player)) { + p.result += winnerPot / winners.length; } - winner.money = winner.money + winnings; - potRemaining -= winnings; - } else { - winner.money = winner.money + potEligible; - potRemaining -= potEligible; } + endHandPlayerData.push(...playerInvestments.filter(p => p.invested <= 0)); + playerInvestments = playerInvestments.filter(p => p.invested > 0); + + winnerPot = 0; + } + if (playerInvestments.length === 1) { + let p = playerInvestments[0]; + p.result += p.invested; + endHandPlayerData.push(p); } - this.log('potRemaining: ' + potRemaining); - if (potRemaining > 0) { - // Adding rounded value to first players - const mod = potRemaining % winners.length; - for (const [index, player] of Object.entries(winners)) { - const toAdd = Math.floor(potRemaining / winners.length) + (index == 0 ? mod : 0); - player.money += toAdd; + for (p of endHandPlayerData) { + if (!winners.includes(p.player)) { + p.player.money += this.getTotalInvested(p.player); } - } else if (potRemaining < 0) { - this.log('yikes'); + p.player.money += p.result; } } + // this.distributeMoney = (winners) => { + // const numWinners = winners.length; + // const potTotal = this.getCurrentPot(); + // const potEligible = Math.floor(potTotal / numWinners); + // let potRemaining = potTotal; + // this.log('winners: ' + winners.map((w) => w.username).toString()); + // for (const winner of winners) { + // if (winner.allIn || winner.getMoney() == 0) { + // // calculate what all-in player is eligible for (side pot calculation). + // // returns money to players + // let sidepot1 = []; + // let sidepot2 = []; + // let sidepot3 = []; + // let sidepot4 = []; + // for (let i = 0; i < 4; i++) { + // this.roundData.bets[i] = this.roundData.bets[i].filter(a => typeof a.bet === 'number'); + // this.roundData.bets[i].sort((a, b) => a.bet - b.bet); + // } + // for (let i = 0; i < this.roundData.bets[0].length; i++) { + // if (sidepot1.some(a => this.roundData.bets[0][i].bet == a.bet)) { + // for (let j = 0; j < sidepot1.length; j++) { + // if (sidepot1[j].bet == this.roundData.bets[0][i].bet) { + // let pot = sidepot1[j]; + // pot.players.push(this.roundData.bets[0][i].player); + // sidepot1[j] = pot; + // } + // } + // } else { + // sidepot1.push({ bet: this.roundData.bets[0][i].bet, players: [this.roundData.bets[0][i].player] }) + // } + // } + // for (let i = 0; i < this.roundData.bets[1].length; i++) { + // if (sidepot2.some(a => this.roundData.bets[1][i].bet == a.bet)) { + // for (let j = 0; j < sidepot2.length; j++) { + // if (sidepot2[j].bet == this.roundData.bets[1][i].bet) { + // let pot = sidepot2[j]; + // pot.players.push(this.roundData.bets[1][i].player); + // sidepot2[j] = pot; + // } + // } + // } else { + // sidepot2.push({ bet: this.roundData.bets[1][i].bet, players: [this.roundData.bets[1][i].player] }) + // } + // } + // for (let i = 0; i < this.roundData.bets[2].length; i++) { + // if (sidepot3.some(a => this.roundData.bets[2][i].bet == a.bet)) { + // for (let j = 0; j < sidepot3.length; j++) { + // if (sidepot3[j].bet == this.roundData.bets[2][i].bet) { + // let pot = sidepot3[j]; + // pot.players.push(this.roundData.bets[2][i].player); + // sidepot3[j] = pot; + // } + // } + // } else { + // sidepot3.push({ bet: this.roundData.bets[2][i].bet, players: [this.roundData.bets[2][i].player] }) + // } + // } + // for (let i = 0; i < this.roundData.bets[3].length; i++) { + // if (sidepot4.some(a => this.roundData.bets[3][i].bet == a.bet)) { + // for (let j = 0; j < sidepot4.length; j++) { + // if (sidepot4[j].bet == this.roundData.bets[3][i].bet) { + // let pot = sidepot4[j]; + // pot.players.push(this.roundData.bets[3][i].player); + // sidepot4[j] = pot; + // } + // } + // } else { + // sidepot4.push({ bet: this.roundData.bets[3][i].bet, players: [this.roundData.bets[3][i].player] }) + // } + // } + // let winnings = 0; + // for (const pot of sidepot1) { + // if (pot.players.includes(winner.getUsername())) { + // if (winners.length == 1) + // winnings += pot.bet * pot.players.length; + // else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // winnings += (pot.bet * pot.players.length) / winners.length; + // } + // } + // } else { + // for (const player of pot.players) { + // //return money + // let playerObj = this.players.find(a => a.getUsername() == player); + // if (playerObj == undefined) { this.log('yikes'); break; } + // if (winners.length == 1) { + // const toAdd = Math.floor(pot.bet / pot.players.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } + // } + // } + // } + // } + // for (const pot of sidepot2) { + // if (pot.players.includes(winner.getUsername())) { + // if (winners.length == 1) + // winnings += pot.bet * pot.players.length; + // else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // winnings += (pot.bet * pot.players.length) / winners.length; + // } + // } + // } else { + // for (const player of pot.players) { + // //return money + // let playerObj = this.players.find(a => a.getUsername() == player); + // if (playerObj == undefined) { this.log('yikes'); break; } + // if (winners.length == 1) { + // const toAdd = Math.floor(pot.bet / pot.players.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } + // } + // } + // } + // } + // for (const pot of sidepot3) { + // if (pot.players.includes(winner.getUsername())) { + // if (winners.length == 1) + // winnings += pot.bet * pot.players.length; + // else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // winnings += (pot.bet * pot.players.length) / winners.length; + // } + // } + // } else { + // for (const player of pot.players) { + // //return money + // let playerObj = this.players.find(a => a.getUsername() == player); + // if (playerObj == undefined) { this.log('yikes'); break; } + // if (winners.length == 1) { + // const toAdd = Math.floor(pot.bet / pot.players.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } + // } + // } + // } + // } + // for (const pot of sidepot4) { + // if (pot.players.includes(winner.getUsername())) { + // if (winners.length == 1) + // winnings += pot.bet * pot.players.length; + // else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // winnings += (pot.bet * pot.players.length) / winners.length; + // } + // } + // } else { + // for (const player of pot.players) { + // //return money + // let playerObj = this.players.find(a => a.getUsername() == player); + // if (playerObj == undefined) { this.log('yikes'); break; } + // if (winners.length == 1) { + // const toAdd = Math.floor(pot.bet / pot.players.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } else { + // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { + // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); + // playerObj.money = playerObj.money + toAdd; + // potRemaining -= toAdd; + // } + // } + // } + // } + // } + // winner.money = winner.money + winnings; + // potRemaining -= winnings; + // } else { + // winner.money = winner.money + potEligible; + // potRemaining -= potEligible; + // } + // } + + // this.log('potRemaining: ' + potRemaining); + // if (potRemaining > 0) { + // // Adding rounded value to first players + // const mod = potRemaining % winners.length; + // for (const [index, player] of Object.entries(winners)) { + // const toAdd = Math.floor(potRemaining / winners.length) + (index == 0 ? mod : 0); + // player.money += toAdd; + // } + // } else if (potRemaining < 0) { + // this.log('yikes'); + // } + // } + this.evaluateWinners = () => { let handArray = []; let playerArray = []; From 4262ac3a95181ee824a71e822607c86dd5427bc0 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Tue, 7 Jul 2020 17:06:22 +0200 Subject: [PATCH 03/12] Rewrite distributeMoney with pure method calculateMoney can be tested without dependencies --- src/classes/game.js | 261 +++++--------------------------------- test/classes/game.test.js | 104 ++++++++++++++- 2 files changed, 132 insertions(+), 233 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index 9253420..2c7e2d4 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -301,12 +301,8 @@ const Game = function (name, host) { for (playerResult of roundResults.playersData) { playerResult.player.setStatus(playerResult.hand.name); } - let winningPlayers = []; - for (winner of roundResults.winnerData) { - winningPlayers.push(winner.player); - } - this.distributeMoney(winningPlayers); - this.revealCards(winningPlayers.map(a => a.getUsername())); + this.distributeMoney(roundResults); + this.revealCards(roundResults.playersData.map(a => a.player.getUsername())); } else { this.log('This stage of the round is INVALID!!'); @@ -392,246 +388,51 @@ const Game = function (name, host) { } - this.distributeMoney = (winners) => { - let playerInvestments = this.players.map(p => ({ 'player': p, 'invested': this.getTotalInvested(p), 'result': -this.getTotalInvested(p) })); - - let winnerPot = winners.reduce((acc, currPlayer) => acc + this.getTotalInvested(currPlayer), 0); - - const endHandPlayerData = []; + this.calculateMoney = (winnerPot, players) => { + let playerInvestments = [...players]; while (playerInvestments.length > 1) { - const minStack = playerInvestments.reduce((acc, curr) => acc.invested < curr.invested ? acc.invested : curr.invested); + const sortedByInvested = playerInvestments.sort((a, b) => a.invested < b.invested ? -1 : 1); + const minStack = sortedByInvested[0].invested; winnerPot += minStack * playerInvestments.length; for (p of playerInvestments) { p.invested -= minStack; } - for (p of playerInvestments) { - if (winners.includes(p.player)) { - p.result += winnerPot / winners.length; - } + const sortedByHandStrength = playerInvestments.sort((a, b) => a.handStrength > b.handStrength ? -1 : 1); + const maxHand = sortedByHandStrength[0].handStrength; + const winners = playerInvestments.filter((p) => p.handStrength === maxHand); + for (p of winners) { + p.result += winnerPot / winners.length; } - endHandPlayerData.push(...playerInvestments.filter(p => p.invested <= 0)); playerInvestments = playerInvestments.filter(p => p.invested > 0); - winnerPot = 0; } + if (playerInvestments.length === 1) { let p = playerInvestments[0]; p.result += p.invested; - endHandPlayerData.push(p); } + } - for (p of endHandPlayerData) { - if (!winners.includes(p.player)) { - p.player.money += this.getTotalInvested(p.player); + this.distributeMoney = (result) => { + let playerInvestments = this.players.map(p => { + const winData = result.winnerData.find((w) => w.player === p); + const invested = this.getTotalInvested(p); + return { + player: p, + invested: invested, + handStrength: winData ? winData.rank : 0, + result: -invested } + }); + let winnerPot = result.winnerData.reduce((acc, currPlayer) => acc + this.getTotalInvested(currPlayer.player), 0); + + this.calculateMoney(winnerPot, playerInvestments); + + for (p of playerInvestments) { p.player.money += p.result; } } - // this.distributeMoney = (winners) => { - // const numWinners = winners.length; - // const potTotal = this.getCurrentPot(); - // const potEligible = Math.floor(potTotal / numWinners); - // let potRemaining = potTotal; - // this.log('winners: ' + winners.map((w) => w.username).toString()); - // for (const winner of winners) { - // if (winner.allIn || winner.getMoney() == 0) { - // // calculate what all-in player is eligible for (side pot calculation). - // // returns money to players - // let sidepot1 = []; - // let sidepot2 = []; - // let sidepot3 = []; - // let sidepot4 = []; - // for (let i = 0; i < 4; i++) { - // this.roundData.bets[i] = this.roundData.bets[i].filter(a => typeof a.bet === 'number'); - // this.roundData.bets[i].sort((a, b) => a.bet - b.bet); - // } - // for (let i = 0; i < this.roundData.bets[0].length; i++) { - // if (sidepot1.some(a => this.roundData.bets[0][i].bet == a.bet)) { - // for (let j = 0; j < sidepot1.length; j++) { - // if (sidepot1[j].bet == this.roundData.bets[0][i].bet) { - // let pot = sidepot1[j]; - // pot.players.push(this.roundData.bets[0][i].player); - // sidepot1[j] = pot; - // } - // } - // } else { - // sidepot1.push({ bet: this.roundData.bets[0][i].bet, players: [this.roundData.bets[0][i].player] }) - // } - // } - // for (let i = 0; i < this.roundData.bets[1].length; i++) { - // if (sidepot2.some(a => this.roundData.bets[1][i].bet == a.bet)) { - // for (let j = 0; j < sidepot2.length; j++) { - // if (sidepot2[j].bet == this.roundData.bets[1][i].bet) { - // let pot = sidepot2[j]; - // pot.players.push(this.roundData.bets[1][i].player); - // sidepot2[j] = pot; - // } - // } - // } else { - // sidepot2.push({ bet: this.roundData.bets[1][i].bet, players: [this.roundData.bets[1][i].player] }) - // } - // } - // for (let i = 0; i < this.roundData.bets[2].length; i++) { - // if (sidepot3.some(a => this.roundData.bets[2][i].bet == a.bet)) { - // for (let j = 0; j < sidepot3.length; j++) { - // if (sidepot3[j].bet == this.roundData.bets[2][i].bet) { - // let pot = sidepot3[j]; - // pot.players.push(this.roundData.bets[2][i].player); - // sidepot3[j] = pot; - // } - // } - // } else { - // sidepot3.push({ bet: this.roundData.bets[2][i].bet, players: [this.roundData.bets[2][i].player] }) - // } - // } - // for (let i = 0; i < this.roundData.bets[3].length; i++) { - // if (sidepot4.some(a => this.roundData.bets[3][i].bet == a.bet)) { - // for (let j = 0; j < sidepot4.length; j++) { - // if (sidepot4[j].bet == this.roundData.bets[3][i].bet) { - // let pot = sidepot4[j]; - // pot.players.push(this.roundData.bets[3][i].player); - // sidepot4[j] = pot; - // } - // } - // } else { - // sidepot4.push({ bet: this.roundData.bets[3][i].bet, players: [this.roundData.bets[3][i].player] }) - // } - // } - // let winnings = 0; - // for (const pot of sidepot1) { - // if (pot.players.includes(winner.getUsername())) { - // if (winners.length == 1) - // winnings += pot.bet * pot.players.length; - // else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // winnings += (pot.bet * pot.players.length) / winners.length; - // } - // } - // } else { - // for (const player of pot.players) { - // //return money - // let playerObj = this.players.find(a => a.getUsername() == player); - // if (playerObj == undefined) { this.log('yikes'); break; } - // if (winners.length == 1) { - // const toAdd = Math.floor(pot.bet / pot.players.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } - // } - // } - // } - // } - // for (const pot of sidepot2) { - // if (pot.players.includes(winner.getUsername())) { - // if (winners.length == 1) - // winnings += pot.bet * pot.players.length; - // else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // winnings += (pot.bet * pot.players.length) / winners.length; - // } - // } - // } else { - // for (const player of pot.players) { - // //return money - // let playerObj = this.players.find(a => a.getUsername() == player); - // if (playerObj == undefined) { this.log('yikes'); break; } - // if (winners.length == 1) { - // const toAdd = Math.floor(pot.bet / pot.players.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } - // } - // } - // } - // } - // for (const pot of sidepot3) { - // if (pot.players.includes(winner.getUsername())) { - // if (winners.length == 1) - // winnings += pot.bet * pot.players.length; - // else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // winnings += (pot.bet * pot.players.length) / winners.length; - // } - // } - // } else { - // for (const player of pot.players) { - // //return money - // let playerObj = this.players.find(a => a.getUsername() == player); - // if (playerObj == undefined) { this.log('yikes'); break; } - // if (winners.length == 1) { - // const toAdd = Math.floor(pot.bet / pot.players.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } - // } - // } - // } - // } - // for (const pot of sidepot4) { - // if (pot.players.includes(winner.getUsername())) { - // if (winners.length == 1) - // winnings += pot.bet * pot.players.length; - // else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // winnings += (pot.bet * pot.players.length) / winners.length; - // } - // } - // } else { - // for (const player of pot.players) { - // //return money - // let playerObj = this.players.find(a => a.getUsername() == player); - // if (playerObj == undefined) { this.log('yikes'); break; } - // if (winners.length == 1) { - // const toAdd = Math.floor(pot.bet / pot.players.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } else { - // if (pot.players.includes(winners[1].getUsername()) || (winners.length == 3 && pot.players.includes(winners[2].getUsername()))) { - // const toAdd = Math.floor((pot.bet / pot.players.length) / winners.length); - // playerObj.money = playerObj.money + toAdd; - // potRemaining -= toAdd; - // } - // } - // } - // } - // } - // winner.money = winner.money + winnings; - // potRemaining -= winnings; - // } else { - // winner.money = winner.money + potEligible; - // potRemaining -= potEligible; - // } - // } - - // this.log('potRemaining: ' + potRemaining); - // if (potRemaining > 0) { - // // Adding rounded value to first players - // const mod = potRemaining % winners.length; - // for (const [index, player] of Object.entries(winners)) { - // const toAdd = Math.floor(potRemaining / winners.length) + (index == 0 ? mod : 0); - // player.money += toAdd; - // } - // } else if (potRemaining < 0) { - // this.log('yikes'); - // } - // } - this.evaluateWinners = () => { let handArray = []; let playerArray = []; @@ -650,7 +451,11 @@ const Game = function (name, host) { for (playerHand of playerArray) { let winnerArray = winner.toString().split(', '); if (this.arraysEqual(playerHand.hand.cards.sort(), winnerArray.sort())) { - winnerData.push({ player: playerHand.player, handTitle: playerHand.hand.name }); + winnerData.push({ + player: playerHand.player, + rank: playerHand.hand.rank, + handTitle: playerHand.hand.name + }); break; } } diff --git a/test/classes/game.test.js b/test/classes/game.test.js index edc27a2..ba3462d 100644 --- a/test/classes/game.test.js +++ b/test/classes/game.test.js @@ -535,9 +535,9 @@ test('Test all-in 3 players low credits win', () => { expect(game.call(currentPlayer.socket)).toBe(true); // Winner has to be p3 with 4 as - expect(p1.money).toBe(45); - expect(p2.money).toBe(45); - expect(p3.money).toBe(160); + expect(p1.money).toBe(50); + expect(p2.money).toBe(50); + expect(p3.money).toBe(150); expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(250); expect(game.roundData.bets.length).toBe(4); @@ -638,9 +638,103 @@ test('Test all-in 3 players high credits win', () => { // Winner has to be p2 with 4 as expect(p1.money).toBe(0); - expect(p2.money).toBe(210); - expect(p3.money).toBe(40); + expect(p2.money).toBe(250); + expect(p3.money).toBe(0); expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(250); expect(game.roundData.bets.length).toBe(4); +}); + +test('Test fold', () => { + const game = new Game('best-game', '1'); + game.smallBlind = 5; + game.bigBlind = 10; + + // Mock socket + const sock1 = new events.EventEmitter(); + sock1.id = 1; + const sock2 = new events.EventEmitter(); + sock2.id = 2; + const sock3 = new events.EventEmitter(); + sock3.id = 3; + + const p1 = game.addPlayer("1", sock1); + expect(p1.money).toBe(100); + + const p2 = game.addPlayer("2", sock2); + expect(p2.money).toBe(100); + + const p3 = game.addPlayer("3", sock3); + expect(p3.money).toBe(100); + + expect(game.findPlayer(1)).toBe(p1); + expect(game.findPlayer(2)).toBe(p2); + expect(game.findPlayer(3)).toBe(p3); + + expect(game.players.length).toBe(3); + + expect(game.roundNum).toBe(0); + expect(game.roundData.bets.length).toBe(0); + game.startGame(); + + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBeGreaterThan(0); + + let currentPlayer; + + // Pre-Flop + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.raise(currentPlayer.socket, 30)).toBe(true); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.call(currentPlayer.socket)).toBe(true); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.fold(currentPlayer.socket)).toBe(true); + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(2); + + // Flop + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(2); + + // Turn + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(3); + + // River + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.check(currentPlayer.socket); + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(4); + + expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); +}); + +test('Test _distributeMoney', () => { + const game = new Game('best-game', '1'); + const pot = 100; + const players = [ + {live: true, invested: 20, handStrength: 100, result: 0}, + {live: true, invested: 50, handStrength: 200, result: 0}, + {live: true, invested: 80, handStrength: 90, result: 0}, + {live: true, invested: 80, handStrength: 100, result: 0}, + {live: true, invested: 1000, handStrength: 0, result: 0}, + ]; + + game.calculateMoney(pot, players); + + expect(players[0].result).toBe(0); + expect(players[1].result).toBe(320); + expect(players[2].result).toBe(0); + expect(players[3].result).toBe(90); + expect(players[4].result).toBe(920); }); \ No newline at end of file From acd8c8947359a1833fd049974c9843f312258695 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Tue, 7 Jul 2020 19:02:38 +0200 Subject: [PATCH 04/12] May be fix ? --- src/classes/game.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index 2c7e2d4..fdd1f7d 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -420,16 +420,16 @@ const Game = function (name, host) { return { player: p, invested: invested, - handStrength: winData ? winData.rank : 0, + originalInvested: invested, + handStrength: winData ? winData.rank : -1, result: -invested } }); - let winnerPot = result.winnerData.reduce((acc, currPlayer) => acc + this.getTotalInvested(currPlayer.player), 0); - - this.calculateMoney(winnerPot, playerInvestments); + let pot = 0; + this.calculateMoney(pot, playerInvestments); for (p of playerInvestments) { - p.player.money += p.result; + p.player.money += p.originalInvested + p.result; } } From 0a8902a82f45c8718fd702d95c28a88c21ed258c Mon Sep 17 00:00:00 2001 From: Aurelien Date: Tue, 7 Jul 2020 19:10:44 +0200 Subject: [PATCH 05/12] Fix Fold test --- src/classes/game.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index fdd1f7d..22b82ca 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -399,7 +399,7 @@ const Game = function (name, host) { } const sortedByHandStrength = playerInvestments.sort((a, b) => a.handStrength > b.handStrength ? -1 : 1); const maxHand = sortedByHandStrength[0].handStrength; - const winners = playerInvestments.filter((p) => p.handStrength === maxHand); + const winners = playerInvestments.filter((p) => p.handStrength === maxHand && p.live); for (p of winners) { p.result += winnerPot / winners.length; } @@ -409,7 +409,7 @@ const Game = function (name, host) { if (playerInvestments.length === 1) { let p = playerInvestments[0]; - p.result += p.invested; + p.result += winnerPot + p.invested; } } @@ -422,10 +422,11 @@ const Game = function (name, host) { invested: invested, originalInvested: invested, handStrength: winData ? winData.rank : -1, - result: -invested + result: -invested, + live: p.getStatus() !== 'Fold' } }); - let pot = 0; + let pot = this.foldPot; this.calculateMoney(pot, playerInvestments); for (p of playerInvestments) { From 04085f772795a4beba8bdd9034a6af3844ba1d38 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Thu, 9 Jul 2020 10:33:30 +0200 Subject: [PATCH 06/12] Fix reveal event, with player won more than 0 credits --- src/classes/game.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index 22b82ca..2b5d123 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -301,8 +301,8 @@ const Game = function (name, host) { for (playerResult of roundResults.playersData) { playerResult.player.setStatus(playerResult.hand.name); } - this.distributeMoney(roundResults); - this.revealCards(roundResults.playersData.map(a => a.player.getUsername())); + const winningData = this.distributeMoney(roundResults); + this.revealCards(winningData.filter(a => a.winner).map(a => a.player.getUsername())); } else { this.log('This stage of the round is INVALID!!'); @@ -423,15 +423,22 @@ const Game = function (name, host) { originalInvested: invested, handStrength: winData ? winData.rank : -1, result: -invested, - live: p.getStatus() !== 'Fold' + live: p.getStatus() !== 'Fold', + winner: false, + gain: 0 } }); let pot = this.foldPot; this.calculateMoney(pot, playerInvestments); for (p of playerInvestments) { - p.player.money += p.originalInvested + p.result; + p.gain = p.originalInvested + p.result; + p.player.money += p.gain; + if (p.gain > 0) { + p.winner = true; + } } + return playerInvestments; } this.evaluateWinners = () => { From aebacab3dbcd9d3ffeda17e33a77177dedadea6d Mon Sep 17 00:00:00 2001 From: Aurelien Date: Thu, 9 Jul 2020 10:51:18 +0200 Subject: [PATCH 07/12] Add test all fold --- test/classes/game.test.js | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/test/classes/game.test.js b/test/classes/game.test.js index ba3462d..33efd78 100644 --- a/test/classes/game.test.js +++ b/test/classes/game.test.js @@ -719,6 +719,67 @@ test('Test fold', () => { expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); }); +test('Test all fold', () => { + const game = new Game('best-game', '1'); + game.smallBlind = 5; + game.bigBlind = 10; + + // Mock socket + const sock1 = new events.EventEmitter(); + sock1.id = 1; + const sock2 = new events.EventEmitter(); + sock2.id = 2; + const sock3 = new events.EventEmitter(); + sock3.id = 3; + + const p1 = game.addPlayer("1", sock1); + expect(p1.money).toBe(100); + + const p2 = game.addPlayer("2", sock2); + expect(p2.money).toBe(100); + + const p3 = game.addPlayer("3", sock3); + expect(p3.money).toBe(100); + + expect(game.findPlayer(1)).toBe(p1); + expect(game.findPlayer(2)).toBe(p2); + expect(game.findPlayer(3)).toBe(p3); + + expect(game.players.length).toBe(3); + + expect(game.roundNum).toBe(0); + expect(game.roundData.bets.length).toBe(0); + game.startGame(); + + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBeGreaterThan(0); + + let currentPlayer; + + // Pre-Flop + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.raise(currentPlayer.socket, 30)).toBe(true); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.call(currentPlayer.socket)).toBe(true); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + expect(game.call(currentPlayer.socket)).toBe(true); + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(2); + expect(game.roundInProgress).toBe(true); + + // Flop + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.fold(currentPlayer.socket); + currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + game.fold(currentPlayer.socket); + + expect(game.roundNum).toBe(1); + expect(game.roundData.bets.length).toBe(2); + expect(game.roundInProgress).toBe(false); + + expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); +}); + test('Test _distributeMoney', () => { const game = new Game('best-game', '1'); const pot = 100; From 6457d4b01766ba3ae945528ac61a2de058da06ed Mon Sep 17 00:00:00 2001 From: Aurelien Date: Thu, 9 Jul 2020 11:59:44 +0200 Subject: [PATCH 08/12] Add gain in reveal cards data --- src/classes/game.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index 2b5d123..a94ccc8 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -302,7 +302,7 @@ const Game = function (name, host) { playerResult.player.setStatus(playerResult.hand.name); } const winningData = this.distributeMoney(roundResults); - this.revealCards(winningData.filter(a => a.winner).map(a => a.player.getUsername())); + this.revealCards(winningData.filter(a => a.winner)); } else { this.log('This stage of the round is INVALID!!'); @@ -530,28 +530,30 @@ const Game = function (name, host) { } } - this.revealCards = (winnersUsernames) => { + this.revealCards = (winners) => { this.log('revealllllll'); this.roundInProgress = false; let cardData = []; for (let i = 0; i < this.players.length; i++) { + const winData = winners.find(w => w.player.username === this.players[i].getUsername()); cardData.push({ - 'username': this.players[i].getUsername(), - 'cards': this.players[i].cards, - 'hand': this.players[i].getStatus(), - 'folded': this.players[i].getStatus() == 'Fold', - 'money': this.players[i].getMoney(), - 'buyIns': this.players[i].buyIns + username: this.players[i].getUsername(), + cards: this.players[i].cards, + hand: this.players[i].getStatus(), + folded: this.players[i].getStatus() == 'Fold', + money: this.players[i].getMoney(), + buyIns: this.players[i].buyIns, + gain: winData ? winData.gain : null }); } for (let pn = 0; pn < this.getNumPlayers(); pn++) { this.players[pn].emit('reveal', { - 'username': this.players[pn].getUsername(), - 'money': this.players[pn].getMoney(), - 'cards': cardData, - 'bets': this.roundData.bets, - 'winners': winnersUsernames.toString(), - 'hand': this.players[pn].getStatus() + username: this.players[pn].getUsername(), + money: this.players[pn].getMoney(), + cards: cardData, + bets: this.roundData.bets, + winners: winnersUsernames.map(a => a.player.getUsername()).toString(), + hand: this.players[pn].getStatus() }); } } From 5f81f3d6151a31a31fc94fd327eeeda76b705070 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Thu, 9 Jul 2020 12:01:03 +0200 Subject: [PATCH 09/12] Match player with instance ref --- src/classes/game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/game.js b/src/classes/game.js index a94ccc8..8df5634 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -535,7 +535,7 @@ const Game = function (name, host) { this.roundInProgress = false; let cardData = []; for (let i = 0; i < this.players.length; i++) { - const winData = winners.find(w => w.player.username === this.players[i].getUsername()); + const winData = winners.find(w => w.player === this.players[i]); cardData.push({ username: this.players[i].getUsername(), cards: this.players[i].cards, From 0696c340894ef4b752183990a75d7431beec5dd0 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Thu, 9 Jul 2020 12:02:58 +0200 Subject: [PATCH 10/12] Fix winnersUsernames --- src/classes/game.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/classes/game.js b/src/classes/game.js index 8df5634..cffb65c 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -546,13 +546,14 @@ const Game = function (name, host) { gain: winData ? winData.gain : null }); } + const winnersUsernames = winners.map(a => a.player.getUsername()).toString() for (let pn = 0; pn < this.getNumPlayers(); pn++) { this.players[pn].emit('reveal', { username: this.players[pn].getUsername(), money: this.players[pn].getMoney(), cards: cardData, bets: this.roundData.bets, - winners: winnersUsernames.map(a => a.player.getUsername()).toString(), + winners: winnersUsernames, hand: this.players[pn].getStatus() }); } From d58d7ad8d27342785b3b19f80111246e2a23133f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 11 Jul 2020 17:14:44 -0400 Subject: [PATCH 11/12] Add check for roundInProgress at end of Test fold case --- src/classes/game.js | 14 +++---- test/classes/game.test.js | 78 +++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index cffb65c..f74b945 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -417,9 +417,9 @@ const Game = function (name, host) { let playerInvestments = this.players.map(p => { const winData = result.winnerData.find((w) => w.player === p); const invested = this.getTotalInvested(p); - return { - player: p, - invested: invested, + return { + player: p, + invested: invested, originalInvested: invested, handStrength: winData ? winData.rank : -1, result: -invested, @@ -459,10 +459,10 @@ const Game = function (name, host) { for (playerHand of playerArray) { let winnerArray = winner.toString().split(', '); if (this.arraysEqual(playerHand.hand.cards.sort(), winnerArray.sort())) { - winnerData.push({ - player: playerHand.player, - rank: playerHand.hand.rank, - handTitle: playerHand.hand.name + winnerData.push({ + player: playerHand.player, + rank: playerHand.hand.rank, + handTitle: playerHand.hand.name }); break; } diff --git a/test/classes/game.test.js b/test/classes/game.test.js index 33efd78..0bf94c5 100644 --- a/test/classes/game.test.js +++ b/test/classes/game.test.js @@ -21,7 +21,7 @@ test('Test call until fold then check', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -86,7 +86,7 @@ test('Test raise more than possessed', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -131,7 +131,7 @@ test('Test bet more than possessed', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -183,7 +183,7 @@ test('Test all-in / call', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -240,7 +240,7 @@ test('Test all-in 3 players', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -252,7 +252,7 @@ test('Test all-in 3 players', () => { const thirdPlayer = game.players.filter((p) => [smallPlayer, bigPlayer].indexOf(p) === -1)[0]; let currentPlayer; - + // Pre-Flop currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; expect(game.call(currentPlayer.socket)).toBe(true); @@ -302,7 +302,7 @@ test('Test disconnected', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -353,7 +353,7 @@ test('Test init blind and dealer', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); game.startGame(); expect(game.roundNum).toBe(1); @@ -416,7 +416,7 @@ test('Test raise', () => { expect(game.findPlayer(2)).toBe(p2); expect(game.players.length).toBe(2); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -424,7 +424,7 @@ test('Test raise', () => { expect(game.roundData.bets.length).toBeGreaterThan(0); let currentPlayer; - + // Pre-Flop currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; expect(game.bet(currentPlayer.socket, 30)).toBe(true); @@ -469,7 +469,7 @@ test('Test all-in 3 players low credits win', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -495,7 +495,7 @@ test('Test all-in 3 players low credits win', () => { expect(game.roundData.bets.length).toBeGreaterThan(0); let currentPlayer; - + // Pre-Flop currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; expect(game.call(currentPlayer.socket)).toBe(true); @@ -571,7 +571,7 @@ test('Test all-in 3 players high credits win', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -597,7 +597,7 @@ test('Test all-in 3 players high credits win', () => { expect(game.roundData.bets.length).toBeGreaterThan(0); let currentPlayer; - + // Pre-Flop currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; expect(game.call(currentPlayer.socket)).toBe(true); @@ -645,6 +645,12 @@ test('Test all-in 3 players high credits win', () => { expect(game.roundData.bets.length).toBe(4); }); +function getCurrentPlayer(players) { + const currentTurnArr = players.filter((p) => p.status === 'Their Turn'); + expect(currentTurnArr.length).toBe(1); + return currentTurnArr[0]; +} + test('Test fold', () => { const game = new Game('best-game', '1'); game.smallBlind = 5; @@ -672,7 +678,7 @@ test('Test fold', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -681,40 +687,48 @@ test('Test fold', () => { expect(game.roundData.bets.length).toBeGreaterThan(0); let currentPlayer; - + // Pre-Flop - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); expect(game.raise(currentPlayer.socket, 30)).toBe(true); - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); expect(game.call(currentPlayer.socket)).toBe(true); - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); expect(game.fold(currentPlayer.socket)).toBe(true); expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(2); + console.log(game.players); + // Flop - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(2); + console.log(game.players); + // Turn - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(3); + console.log(game.players); + // River - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); - currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(4); + expect(game.roundInProgress).toBe(false); + console.log(game.players); expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); }); @@ -746,7 +760,7 @@ test('Test all fold', () => { expect(game.findPlayer(3)).toBe(p3); expect(game.players.length).toBe(3); - + expect(game.roundNum).toBe(0); expect(game.roundData.bets.length).toBe(0); game.startGame(); @@ -755,7 +769,7 @@ test('Test all fold', () => { expect(game.roundData.bets.length).toBeGreaterThan(0); let currentPlayer; - + // Pre-Flop currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; expect(game.raise(currentPlayer.socket, 30)).toBe(true); @@ -784,11 +798,11 @@ test('Test _distributeMoney', () => { const game = new Game('best-game', '1'); const pot = 100; const players = [ - {live: true, invested: 20, handStrength: 100, result: 0}, - {live: true, invested: 50, handStrength: 200, result: 0}, - {live: true, invested: 80, handStrength: 90, result: 0}, - {live: true, invested: 80, handStrength: 100, result: 0}, - {live: true, invested: 1000, handStrength: 0, result: 0}, + { live: true, invested: 20, handStrength: 100, result: 0 }, + { live: true, invested: 50, handStrength: 200, result: 0 }, + { live: true, invested: 80, handStrength: 90, result: 0 }, + { live: true, invested: 80, handStrength: 100, result: 0 }, + { live: true, invested: 1000, handStrength: 0, result: 0 }, ]; game.calculateMoney(pot, players); From daf1b92abb4fc9a4c50b0a3a78314e786f7bc75a Mon Sep 17 00:00:00 2001 From: Aurelien Date: Sun, 12 Jul 2020 17:04:41 +0200 Subject: [PATCH 12/12] Refactor / Optimisation / Fix fold --- src/classes/game.js | 116 ++++++++++++++++---------------------- test/classes/game.test.js | 15 ++--- 2 files changed, 53 insertions(+), 78 deletions(-) diff --git a/src/classes/game.js b/src/classes/game.js index f74b945..dceecbc 100644 --- a/src/classes/game.js +++ b/src/classes/game.js @@ -223,9 +223,31 @@ const Game = function (name, host) { } } + this.getNonFoldedPlayer = () => { + let numNonFolds = 0; + let nonFolderPlayer; + for (let i = 0; i < this.getNumPlayers(); i++) { + if (this.players[i].getStatus() != 'Fold') { + numNonFolds++; + nonFolderPlayer = this.players[i]; + } + } + return [numNonFolds, nonFolderPlayer]; + } + + this.updateStage = () => { + for (let i = 0; i < this.players.length; i++) { + if (i === this.findFirstToGoPlayer() && this.players[i].getStatus() !== 'Fold') { + this.players[i].setStatus('Their Turn'); + } else if (this.players[i].getStatus() !== 'Fold') { + this.players[i].setStatus(''); + } + } + this.roundData.bets.push([]); + } + this.moveOntoNextPlayer = () => { let handOver = false; - this.log(this.getCurrentRoundBets()); if (this.isStageComplete()) { this.log('stage complete'); if (this.allPlayersAllIn()) { @@ -248,14 +270,7 @@ const Game = function (name, host) { } // stage-by-stage logic. // check if everyone folded but one - let numNonFolds = 0; - let nonFolderPlayer; - for (let i = 0; i < this.getNumPlayers(); i++) { - if (this.players[i].getStatus() != 'Fold') { - numNonFolds++; - nonFolderPlayer = this.players[i]; - } - } + const [numNonFolds, nonFolderPlayer] = this.getNonFoldedPlayer(); if (numNonFolds == 1) { // everyone folded, start new round, give pot to player this.log('everyone folded except one'); @@ -267,34 +282,13 @@ const Game = function (name, host) { this.community.push(this.deck.dealRandomCard()); this.community.push(this.deck.dealRandomCard()); this.community.push(this.deck.dealRandomCard()); - for (let i = 0; i < this.players.length; i++) { - if (i === this.findFirstToGoPlayer() && this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus('Their Turn'); - } else if (this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus(''); - } - } - this.roundData.bets.push([]); + this.updateStage(); } else if (this.roundData.bets.length == 2) { this.community.push(this.deck.dealRandomCard()); - for (let i = 0; i < this.players.length; i++) { - if (i === this.findFirstToGoPlayer() && this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus('Their Turn'); - } else if (this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus(''); - } - } - this.roundData.bets.push([]); + this.updateStage(); } else if (this.roundData.bets.length == 3) { this.community.push(this.deck.dealRandomCard()); - for (let i = 0; i < this.players.length; i++) { - if (i === this.findFirstToGoPlayer() && this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus('Their Turn'); - } else if (this.players[i].getStatus() !== 'Fold') { - this.players[i].setStatus(''); - } - } - this.roundData.bets.push([]); + this.updateStage(); } else if (this.roundData.bets.length == 4) { handOver = true; const roundResults = this.evaluateWinners(); @@ -311,14 +305,7 @@ const Game = function (name, host) { } else { this.log('stage not complete'); //check if everyone folded except one player - let numNonFolds = 0; - let nonFolderPlayer; - for (let i = 0; i < this.getNumPlayers(); i++) { - if (this.players[i].getStatus() != 'Fold') { - numNonFolds++; - nonFolderPlayer = this.players[i]; - } - } + const [numNonFolds, nonFolderPlayer] = this.getNonFoldedPlayer(); if (!handOver && numNonFolds == 1) { // everyone folded, start new round, give pot to player this.log('everyone folded except one'); @@ -329,20 +316,11 @@ const Game = function (name, host) { let currTurnIndex = 0; //check if move just made was a fold if (this.lastMoveParsed.move == 'Fold') { - for (let i = 0; i < this.players.length; i++) { - if (this.players[i].username == this.lastMoveParsed.player.username) { - currTurnIndex = i; - break; - } - } + currTurnIndex = this.players.findIndex((p) => p === this.lastMoveParsed.player); this.lastMoveParsed = { 'move': '', 'player': '' }; } else { - for (let i = 0; i < this.players.length; i++) { - if (this.players[i].getStatus() == 'Their Turn') { - currTurnIndex = i; - this.players[i].setStatus(''); - } - } + currTurnIndex = this.players.findIndex((p) => p.getStatus() === 'Their Turn'); + this.players[currTurnIndex].setStatus(''); } do { currTurnIndex = (currTurnIndex - 1 < 0) ? (this.players.length - 1) : (currTurnIndex - 1) @@ -687,20 +665,21 @@ const Game = function (name, host) { this.fold = (socket) => { this.checkBigBlindWent(socket); + const player = this.findPlayer(socket.id); let preFoldBetAmount = 0; - let roundDataStage = this.getCurrentRoundBets().find(a => a.player == this.findPlayer(socket.id).username); + let roundDataStage = this.getCurrentRoundBets().find(a => a.player == player.getUsername()); if (roundDataStage != undefined && roundDataStage.bet != 'Fold') { preFoldBetAmount += roundDataStage.bet; } - this.findPlayer(socket.id).setStatus('Fold'); + player.setStatus('Fold'); this.foldPot = this.foldPot + preFoldBetAmount; - if (this.getCurrentRoundBets().some(a => a.player == this.findPlayer(socket.id).username)) { - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: 'Fold' } : a)); + if (this.getCurrentRoundBets().some(a => a.player == player.getUsername())) { + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.getUsername() ? { player: player.getUsername(), bet: 'Fold' } : a)); } else { - this.getCurrentRoundBets().push({ player: this.findPlayer(socket.id).getUsername(), bet: 'Fold' }); + this.getCurrentRoundBets().push({ player: player.getUsername(), bet: 'Fold' }); } - this.lastMoveParsed = { 'move': 'Fold', 'player': this.findPlayer(socket.id) }; + this.lastMoveParsed = { move: 'Fold', player: player }; this.moveOntoNextPlayer(); return true; } @@ -713,11 +692,11 @@ const Game = function (name, host) { if (currBet === 0) { if (this.getCurrentRoundBets().some(a => a.player == player.getUsername())) { if (player.getMoney() - topBet <= 0) { - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: player.getMoney() } : a)); + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.username ? { player: player.getUsername(), bet: player.getMoney() } : a)); player.money = 0; player.allIn = true; } else { - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: topBet } : a)); + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.username ? { player: player.getUsername(), bet: topBet } : a)); player.money = player.money - topBet; } } else { @@ -741,12 +720,12 @@ const Game = function (name, host) { } else { if (this.getCurrentRoundBets().some(a => a.player == player.getUsername())) { if ((player.getMoney() + currBet) - topBet <= 0) { - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: player.getMoney() + currBet } : a)); + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.username ? { player: player.getUsername(), bet: player.getMoney() + currBet } : a)); player.money = 0; player.allIn = true; this.moveOntoNextPlayer(); } else { - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: topBet } : a)); + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.username ? { player: player.getUsername(), bet: topBet } : a)); player.money = player.money - (topBet - currBet); this.moveOntoNextPlayer(); } @@ -775,11 +754,12 @@ const Game = function (name, host) { this.check = (socket) => { this.checkBigBlindWent(socket); let currBet = 0; - if (this.getCurrentRoundBets().find(a => a.player == this.findPlayer(socket.id).username) != undefined) { - currBet = this.getCurrentRoundBets().find(a => a.player == this.findPlayer(socket.id).username).bet; - this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == this.findPlayer(socket.id).username ? { player: this.findPlayer(socket.id).getUsername(), bet: currBet } : a)); + const player = this.findPlayer(socket.id); + if (this.getCurrentRoundBets().find(a => a.player == player.getUsername()) != undefined) { + currBet = this.getCurrentRoundBets().find(a => a.player == player.getUsername()).bet; + this.setCurrentRoundBets(this.getCurrentRoundBets().map(a => a.player == player.getUsername() ? { player: player.getUsername(), bet: currBet } : a)); } else { - this.getCurrentRoundBets().push({ player: this.findPlayer(socket.id).getUsername(), bet: currBet }); + this.getCurrentRoundBets().push({ player: player.getUsername(), bet: currBet }); } this.moveOntoNextPlayer(); return true; @@ -787,9 +767,9 @@ const Game = function (name, host) { this.raise = (socket, bet) => { this.checkBigBlindWent(socket); - const currBet = this.getPlayerBetInStage(this.findPlayer(socket.id)); const topBet = this.getCurrentTopBet(); const player = this.findPlayer(socket.id); + const currBet = this.getPlayerBetInStage(player); const moneyToRemove = bet - currBet; if (moneyToRemove > 0 && bet >= topBet && player.getMoney() - moneyToRemove >= 0) { if (currBet === 0) { diff --git a/test/classes/game.test.js b/test/classes/game.test.js index 0bf94c5..1539c6b 100644 --- a/test/classes/game.test.js +++ b/test/classes/game.test.js @@ -694,21 +694,19 @@ test('Test fold', () => { currentPlayer = getCurrentPlayer(game.players); expect(game.call(currentPlayer.socket)).toBe(true); currentPlayer = getCurrentPlayer(game.players); - expect(game.fold(currentPlayer.socket)).toBe(true); + expect(game.call(currentPlayer.socket)).toBe(true); expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(2); - console.log(game.players); - // Flop currentPlayer = getCurrentPlayer(game.players); + game.fold(currentPlayer.socket); + currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); expect(game.roundNum).toBe(1); - expect(game.roundData.bets.length).toBe(2); - - console.log(game.players); + expect(game.roundData.bets.length).toBe(3); // Turn currentPlayer = getCurrentPlayer(game.players); @@ -716,9 +714,7 @@ test('Test fold', () => { currentPlayer = getCurrentPlayer(game.players); game.check(currentPlayer.socket); expect(game.roundNum).toBe(1); - expect(game.roundData.bets.length).toBe(3); - - console.log(game.players); + expect(game.roundData.bets.length).toBe(4); // River currentPlayer = getCurrentPlayer(game.players); @@ -728,7 +724,6 @@ test('Test fold', () => { expect(game.roundNum).toBe(1); expect(game.roundData.bets.length).toBe(4); expect(game.roundInProgress).toBe(false); - console.log(game.players); expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); });