From dea44d63d563130e72aac60e4ad37ba209ec3f70 Mon Sep 17 00:00:00 2001 From: roessig <27856832+roessig@users.noreply.github.com> Date: Sun, 12 Apr 2020 09:14:11 +0000 Subject: [PATCH 1/6] removed email --- lib/holdem_game.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/holdem_game.js b/lib/holdem_game.js index a046517..b64c735 100644 --- a/lib/holdem_game.js +++ b/lib/holdem_game.js @@ -101,7 +101,7 @@ HoldemGame.prototype.details = function() { HoldemGame.prototype.tick = function() { Room.prototype.tick.call(this); - + var room = this; if(room.is_ingame) { var gamer = room.in_gamers[0]; @@ -142,6 +142,8 @@ HoldemGame.prototype.gameStart = function() { var room = this; var seats = room.seats; var gamers = room.gamers; + console.log('gamestart'); + console.log(room.deal_order); room.is_ingame = true; room.ready_countdown = -1; @@ -160,6 +162,7 @@ HoldemGame.prototype.gameStart = function() { var i, j, uid, gamer, first = room.dealer_seat; var in_gamers = room.in_gamers = []; + console.log('room.dealer_seat is' + first ); for(i=first; i Date: Sun, 12 Apr 2020 10:52:12 +0000 Subject: [PATCH 2/6] fixed simple win casein client --- www/main.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/www/main.js b/www/main.js index b67b86e..1d78169 100644 --- a/www/main.js +++ b/www/main.js @@ -163,6 +163,7 @@ $(document).ready(function(){ client.on('countdown', function(ret){ addMsg(_T('count down:') + ret.seat + ', ' + ret.sec); }); + client.on('fold', function(ret){ addMsg( ret.uid + _T_('at seat') + ret.seat + _T_('fold')); @@ -237,27 +238,37 @@ $(document).ready(function(){ client.on('gameover', function(ret){ addMsg( _T('game over!')); - + // if only one player remained, we should not show the cards + var showdown = client.room.ingamers_count > 0; + if (!showdown) { + addMsg('Only one player remained.'); + } var shared_cards = client.room.shared_cards; var gamers = client.room.gamers; var cards = client.room.cards; var chips = client.room.chips; while(ret.length > 0) { + var gamer = ret.shift(); var uid = gamer.uid; var n = (gamer.prize - gamer.chips); if(n > 0) n = '+' + n; - + var mycards = gamer.cards; var pattern = ''; if(mycards.length === 3) { pattern = Jinhua.patternString(mycards); addMsg( '#' + gamer.seat + ', ' + uid + ': ' + n + ', ' + _T_(pattern) ); } else { - var maxFive = Holdem.sort( Holdem.maxFive(mycards, shared_cards) ); - pattern = Holdem.patternString( maxFive ); - addMsg( '#' + gamer.seat + ', ' + uid + ': ' + n + ', ' + _T_(pattern) + ' (' + Poker.visualize(maxFive) + ')' ); + if (showdown) { + var maxFive = Holdem.sort( Holdem.maxFive(mycards, shared_cards) ); + pattern = Holdem.patternString( maxFive ); + + addMsg( '#' + gamer.seat + ', ' + uid + ': ' + n + ', ' + _T_(pattern) + ' (' + Poker.visualize(maxFive) + ')' );} else { + addMsg( '#' + gamer.seat + ', ' + uid + ': ' + n); + } + } cards[ gamer.seat ] = gamer.cards; From 31fbaabd0cde1737b83f191a2362e6b3e673ecc4 Mon Sep 17 00:00:00 2001 From: roessig <27856832+roessig@users.noreply.github.com> Date: Sun, 12 Apr 2020 12:06:42 +0000 Subject: [PATCH 3/6] result display works --- lib/holdem_game.js | 42 ++++++++++++++++++++---------------------- www/main.js | 5 +++-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/holdem_game.js b/lib/holdem_game.js index b64c735..b979a17 100644 --- a/lib/holdem_game.js +++ b/lib/holdem_game.js @@ -105,22 +105,6 @@ HoldemGame.prototype.tick = function() { var room = this; if(room.is_ingame) { var gamer = room.in_gamers[0]; - if(room.turn_countdown > 0) { - room.notifyAll('countdown', { - seat: gamer.seat, - sec: room.turn_countdown - }); - room.turn_countdown --; - - } else if(room.turn_countdown === 0) { - // TODO: for test only - room.gamerMoveTurn(true); - //room.gamerGiveUp( gamer ); - - } else { - // not started, just wait - } - } else { if(room.ready_countdown > 0) { room.notifyAll('countdown', { @@ -162,7 +146,6 @@ HoldemGame.prototype.gameStart = function() { var i, j, uid, gamer, first = room.dealer_seat; var in_gamers = room.in_gamers = []; - console.log('room.dealer_seat is' + first ); for(i=first; i 0}); room.notifyAll('prompt', { fold: null, @@ -328,7 +313,7 @@ HoldemGame.prototype.gameOver = function() { // for next round, move deal seat to next for (i=0; i 1) { var average = Math.floor( prize / n ); @@ -661,11 +661,9 @@ HoldemGame.prototype.gamerShowDown = function() { } else { finals[0].prize = prize; } - } - - room.gameOver(); }; + HoldemGame.prototype.onGamer_ready = function(req, reply) { var room = this; var uid = req.uid; diff --git a/www/main.js b/www/main.js index 1d78169..a77baa9 100644 --- a/www/main.js +++ b/www/main.js @@ -236,10 +236,11 @@ $(document).ready(function(){ } }); - client.on('gameover', function(ret){ + client.on('gameover', function(args){ addMsg( _T('game over!')); // if only one player remained, we should not show the cards - var showdown = client.room.ingamers_count > 0; + var showdown = args.showdown; + var ret = args.scores; if (!showdown) { addMsg('Only one player remained.'); } From c10dca6e7af2e1a9d572a3d2548cdcf119b25b38 Mon Sep 17 00:00:00 2001 From: roessig <27856832+roessig@users.noreply.github.com> Date: Mon, 13 Apr 2020 11:41:13 +0000 Subject: [PATCH 4/6] implemented all in --- lib/holdem_game.js | 101 ++++++++++++++++++++++++++------------------- www/main.js | 19 +++++++++ 2 files changed, 78 insertions(+), 42 deletions(-) diff --git a/lib/holdem_game.js b/lib/holdem_game.js index b979a17..62aa9fb 100644 --- a/lib/holdem_game.js +++ b/lib/holdem_game.js @@ -412,7 +412,10 @@ HoldemGame.prototype.moveTurnToNext = function() { if(next.seat === room.first_turn) room.round_counter ++; // to avoid dead loop - if(next.seat === last.seat) break; + if(next.seat === last.seat){ + room.no_raise_counter = room.ingamers_count; + break; + } // we find the next one in game if(next.is_ingame) { @@ -432,8 +435,6 @@ HoldemGame.prototype.gamerMoveTurn = function(move) { var in_gamers = room.in_gamers, deal_order = room.deal_order; if(move) room.moveTurnToNext(); - - console.log('gamer move turn ', room.ingamers_count); var deal_card = false; if(room.no_raise_counter === room.ingamers_count) { @@ -561,10 +562,10 @@ HoldemGame.prototype.gamerShowDown = function() { var i, gamer, maxFive, someone_allin = false; for(i=0; iA>B>D>E>C,但F已盖牌不能分配任何彩池,则此局主池即为A于此局赢得的筹码($300), - * B可赢得第一个边池($1000),D参与至最后一个边池,且牌面胜过参与第二、第三及第四边池的所有牌手, - * 因此可赢得剩下所有的边池(400+450+600=$1450)。 - */ gamers_bychips.sort( function(a,b) { return a.chips - b.chips; } ); + num_players = gamers_bychips.length; + var not_in_game_prize = room.pot; + for (i=0; i < num_players; i++) { + gamers_bychips[i].chips_tmp = gamers_bychips[i].chips; + not_in_game_prize -= gamers_bychips[i].chips; + } + while (gamers_bychips[num_players - 1].chips_tmp > 0) { + var price_step = 0; + var current_prize = 0; + var start_index = -1; + for (i=0; i < num_players; i++) { + if (gamers_bychips[i].chips_tmp === 0) { + continue; + } + if (gamers_bychips[i].chips_tmp > 0 && price_step === 0) { + price_step = gamers_bychips[i].chips_tmp; + start_index = i; + } + gamers_bychips[i].chips_tmp -= price_step; + current_prize += price_step; + } + + // we must add the chips of players that are not left in the game, but + // only for the first pot evaluation. + current_prize += not_in_game_prize; + not_in_game_prize = 0; + // we must only consider those players with the highest rank + // for winning the (side) pot + var pot_winners = gamers_bychips.slice(start_index); + pot_winners.sort( function(a,b){ return b.maxFiveRank - a.maxFiveRank; } ); + for (i=0; i finals[i+1].maxFiveRank) { + // if rank at i+1 is strictly lower than rank of i, all gamers + // behind i are deleted. var losers = finals.splice(i+1, Number.MAX_VALUE); while(losers.length > 0) { var loser = losers.shift(); @@ -622,25 +635,29 @@ HoldemGame.prototype.gamerShowDown = function() { break; } } - - var prize = room.pot; - room.evaluate_pot(finals, prize); + room.evaluate_pot(finals, room.pot); } room.gameOver(); }; HoldemGame.prototype.evaluate_pot = function(finals, prize) { - /* Compute how much each gamer in finals shall receive - * of the prize. Prize value is adapted in finals. + /* + * Compute how much each gamer in finals shall receive + * of the prize. Prize value is adapted in finals. Prize + * is added up as to support several pots with the same + * gamer objects. */ var n = finals.length; - if(n > 1) { + + if(n > 1) { // pot is splitted due to tie var average = Math.floor( prize / n ); for(i=0; i 0) { // find the nearest winner after dealer seat @@ -659,7 +676,7 @@ HoldemGame.prototype.evaluate_pot = function(finals, prize) { finals[0].prize += odd; } } else { - finals[0].prize = prize; + finals[0].prize += prize; } }; diff --git a/www/main.js b/www/main.js index a77baa9..38d061c 100644 --- a/www/main.js +++ b/www/main.js @@ -170,6 +170,7 @@ $(document).ready(function(){ }); client.on('call', function(ret){ + var seat = parseInt(ret.seat); addMsg( ret.uid + _T_('at seat') + seat + _T_('call') + ret.call); @@ -208,6 +209,24 @@ $(document).ready(function(){ showRoom(client.room); }); + client.on('all_in', function(ret){ + + var seat = parseInt(ret.seat); + var gamers = client.room.gamers; + raise_sum = gamers[ret.uid].coins + client.room.pot += raise_sum + gamers[ret.uid].coins = 0 + addMsg(ret.uid + _T_('at seat') + seat + ' all in with raise of ' + raise_sum); + gamers[ret.uid].is_allin = true; + + var chips = client.room.chips; + if(chips) { + chips[ seat ] += raise_sum; + } + + showRoom(client.room); + }); + client.on('pk', function(ret){ addMsg( ret.uid + _T_('at seat') + ret.seat + _T('pk') + ret.pk_uid + _T_('at seat') + ret.pk_seat + ', ' + _T('result') + ': ' + (ret.win?_T('win'):_T('fail'))); From d2c8e54e1d14419df78d5a4ae9a4ebdd98beb578 Mon Sep 17 00:00:00 2001 From: roessig <27856832+roessig@users.noreply.github.com> Date: Sat, 25 Apr 2020 11:06:27 +0000 Subject: [PATCH 5/6] removed cards from left pane and fixed all in no_raise_counter behaviour --- lib/holdem_game.js | 7 +++---- www/main.js | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/holdem_game.js b/lib/holdem_game.js index 62aa9fb..7437f0f 100644 --- a/lib/holdem_game.js +++ b/lib/holdem_game.js @@ -152,6 +152,7 @@ HoldemGame.prototype.gameStart = function() { gamer = gamers[ uid ]; if(gamer.is_ready) { in_gamers.push( gamer ); + room.chips[gamer.seat] = 0; } } } @@ -403,11 +404,9 @@ HoldemGame.prototype.moveTurnToNext = function() { call: null, raise: null, all_in: null - }); - + }); do { in_gamers.push( in_gamers.shift() ); - next = in_gamers[0]; if(next.seat === room.first_turn) room.round_counter ++; @@ -437,7 +436,7 @@ HoldemGame.prototype.gamerMoveTurn = function(move) { if(move) room.moveTurnToNext(); var deal_card = false; - if(room.no_raise_counter === room.ingamers_count) { + if(room.no_raise_counter >= room.ingamers_count) { // >= for all in case room.state ++; switch(room.state) { diff --git a/www/main.js b/www/main.js index 38d061c..6755200 100644 --- a/www/main.js +++ b/www/main.js @@ -216,7 +216,7 @@ $(document).ready(function(){ raise_sum = gamers[ret.uid].coins client.room.pot += raise_sum gamers[ret.uid].coins = 0 - addMsg(ret.uid + _T_('at seat') + seat + ' all in with raise of ' + raise_sum); + addMsg(ret.uid + _T_('at seat') + seat + ' all in with ' + raise_sum ); gamers[ret.uid].is_allin = true; var chips = client.room.chips; @@ -629,7 +629,6 @@ function showRoom(room) { if(g) { str += g.uid + ' (' + g.name + ') [' + g.coins + ', ' + g.score + ', ' + g.exp + ', ' + g.level + ']'; if(cards && cards[i]) { - str += _T_('private cards') + '[ ' + Poker.visualize( cards[i] ) + ' ]'; if(g.uid === client.uid) { $('#mycards').html( client.uid + ', ' + _T('my cards') + ':
' + Poker.toHTML(cards[i]) ); From 2a90e3162e5bec2c58d9cabd5a8b0650e7fbdefa Mon Sep 17 00:00:00 2001 From: roessig <27856832+roessig@users.noreply.github.com> Date: Sun, 26 Apr 2020 12:41:27 +0200 Subject: [PATCH 6/6] Removed debug outputs --- lib/holdem_game.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/holdem_game.js b/lib/holdem_game.js index 7437f0f..a040715 100644 --- a/lib/holdem_game.js +++ b/lib/holdem_game.js @@ -126,8 +126,6 @@ HoldemGame.prototype.gameStart = function() { var room = this; var seats = room.seats; var gamers = room.gamers; - console.log('gamestart'); - console.log(room.deal_order); room.is_ingame = true; room.ready_countdown = -1; @@ -291,9 +289,7 @@ HoldemGame.prototype.gameOver = function() { item.prize = gamer.prize; scorelist.push(item); - console.log(item.seat, item.cards, item.chips, item.prize); } - console.log(room.shared_cards, room.pot, room.cards, room.ingamers_count); room.notifyAll('gameover', {scores: scorelist, showdown: room.ingamers_count > 0}); @@ -313,15 +309,12 @@ HoldemGame.prototype.gameOver = function() { // for next round, move deal seat to next for (i=0; i