fixed bug

This commit is contained in:
wzdwc
2021-01-21 00:04:57 +08:00
parent 70ecee7d87
commit f8d86528a7
24 changed files with 304 additions and 190 deletions
BIN
View File
Binary file not shown.
+22 -13
View File
@@ -45,7 +45,7 @@ export enum EGameStatus {
* Action time
* @type {number}
*/
const ACTION_TIME = 30 * 1000;
const ACTION_TIME = 60 * 1000;
/**
* Class representing a poker game
@@ -387,12 +387,15 @@ export class PokerGame {
&& this.prevSize !== this.smallBlind * 2 && this.prevSize !== 0), 'tst', size, nextPlayer.actionSize, this.prevSize);
// all check actionSize === -1
// all player allin
// only 2 player, curr player fold, next player alrecommand add errorady action
// only one player ,one player fold,other player allin
// only 2 player, curr player fold, next player already action
// only one player,one player fold,other player allin
// pre flop big blind check and other player call
// pre flop big blind fold and other player call
if (this.playerSize === 0
|| (this.playerSize === 1 && this.currActionAllinPlayer.length === 0)
|| (this.playerSize === 1
&& (this.currActionAllinPlayer.length === 0
|| (command === ECommand.ALL_IN
&& this.currPlayer.node.actionSize < this.prevSize)))
|| (this.commonCard.length !== 0 && nextPlayer.actionSize === this.smallBlind * 2
&& nextPlayer.actionSize === size && size === this.prevSize)
|| (nextPlayer.actionSize === this.prevSize
@@ -571,18 +574,24 @@ export class PokerGame {
counting() {
let prevEvPot = 0;
this.winner.forEach((winnerList, key) => {
if (key !== 0) {
prevEvPot = this.winner[key - 1][0].evPot;
}
winnerList.sort((prev, next) => prev.inPot - next.inPot);
let roundPotCount = 0;
winnerList.forEach((winner, index) => {
const pot = winner.evPot === Infinity ? this.pot : winner.evPot;
const pot = winner.evPot >= this.pot ? this.pot : winner.evPot;
const leftPot = pot - prevEvPot;
const isDivide = leftPot % winnerList.length;
let income = leftPot / winnerList.length;
if (index === 0 && winnerList.length > 1 && isDivide > 0) {
income = ((leftPot - isDivide) / winnerList.length) + isDivide;
let income = leftPot / (winnerList.length - index);
if (index === winnerList.length - 1) {
// not only one winner
if (index !== 0) {
income = pot - roundPotCount;
}
winner.setIncome(income);
prevEvPot = winner.evPot;
} else {
roundPotCount += income;
winner.setIncome(income);
}
winner.setIncome(income);
console.log('winner----------', winnerList, roundPotCount, pot, leftPot);
});
});
}
+12 -31
View File
@@ -137,36 +137,17 @@ export class PokerStyle implements IPokerStyle {
}
console.log('come in -------', isThree);
if (this.isShort) {
// three of kind
if (isThree.length > 0) {
isThreeKind = isThree.join('');
isThreeKind += highCard[0] + highCard[1];
this.pokerStyle[5] = isThreeKind;
return;
}
// straight
if (this.isStraight() !== '0') {
this.pokerStyle[6] = `${this.isStraight()}`;
return;
}
} else {
// straight
if (this.isStraight() !== '0') {
this.pokerStyle[5] = `${this.isStraight()}`;
return;
}
// three of kind
if (isThree.length > 0) {
isThreeKind = isThree.join('');
isThreeKind += highCard[0] + highCard[1];
this.pokerStyle[6] = isThreeKind;
return;
}
// straight
if (this.isStraight() !== '0') {
this.pokerStyle[5] = `${this.isStraight()}`;
return;
}
// three of kind
if (isThree.length > 0) {
isThreeKind = isThree.join('');
isThreeKind += highCard[0] + highCard[1];
this.pokerStyle[6] = isThreeKind;
return;
}
// tow pair
@@ -240,7 +221,7 @@ export class PokerStyle implements IPokerStyle {
let isFlush = false;
this.pokerStyle.forEach((style, key) => {
if (style !== '0') {
isFlush = key === 1 || key === 4;
isFlush = key === 1 || this.isShort ? key === 3 : key === 4;
valueStyle = style;
}
});
+24 -6
View File
@@ -76,7 +76,7 @@ class GameController extends BaseSocketController {
roomInfo.game = new PokerGame({
users: sitDownPlayer,
isShort: roomInfo.config.isShort,
smallBlind: 1,
smallBlind: roomInfo.config.smallBlind,
actionRoundComplete: async () => {
let slidePots: number [] = [];
if (roomInfo.game) {
@@ -197,9 +197,9 @@ class GameController extends BaseSocketController {
userId: BB.userId,
type: BB.type,
gameStatus: 0,
pot: 3,
pot: roomInfo.config.smallBlind * 3,
commonCard: '',
command: 'bb:2',
command: `bb:${roomInfo.config.smallBlind * 2}`,
gameId: result.id,
counter: BB.counter,
};
@@ -208,9 +208,9 @@ class GameController extends BaseSocketController {
userId: SB.userId,
type: SB.type,
gameStatus: 0,
pot: 1,
pot: roomInfo.config.smallBlind,
commonCard: '',
command: 'sb:1',
command: `sb:${roomInfo.config.smallBlind}`,
gameId: result.id,
counter: SB.counter,
};
@@ -370,6 +370,7 @@ class GameController extends BaseSocketController {
const { payload } = this.message;
const sitList = payload.sitList;
const roomInfo = await this.getRoomInfo();
console.log('sitList=============', sitList);
roomInfo.sit = sitList;
await this.adapter('online', 'sitList', {
sitList,
@@ -378,7 +379,24 @@ class GameController extends BaseSocketController {
console.log(e);
}
}
async standUp() {
try {
console.log('come in');
const userInfo: IPlayer = await this.getUserInfo();
const roomInfo = await this.getRoomInfo();
roomInfo.sit.forEach((s: ISit) => {
if (s.player && s.player.userId === userInfo.userId) {
delete s.player;
}
});
const sitList = roomInfo.sit;
await this.adapter('online', 'sitList', {
sitList,
});
} catch (e) {
console.log(e);
}
}
async action() {
try {
const { payload } = this.message;
+1
View File
@@ -111,6 +111,7 @@ export default function join(): any {
currPlayer: {
userId: roomInfo.game?.currPlayer.node.userId,
},
smallBlind: roomInfo.config.smallBlind,
};
const game = ctx.helper.parseMsg('gameInfo', {
data: gameInfo,
+2
View File
@@ -7,4 +7,6 @@ export default function (app: Application) {
app.io.of('/socket').route('playGame', app.io.controller.game.playGame);
app.io.of('/socket').route('action', app.io.controller.game.action);
app.io.of('/socket').route('sitDown', app.io.controller.game.sitDown);
app.io.of('/socket').route('standUp', app.io.controller.game.standUp);
}
+1
View File
@@ -75,6 +75,7 @@ export default class BaseSocketController extends Controller {
currPlayer: {
userId: roomInfo.game.currPlayer.node.userId,
},
smallBlind: roomInfo.config.smallBlind,
};
await this.adapter('online', 'gameInfo', gameInfo);
}