From caa8669417b823cac73b0ec6ffb92dded9c71c22 Mon Sep 17 00:00:00 2001 From: wzdwc Date: Fri, 26 Jun 2020 00:31:45 +0800 Subject: [PATCH] fixed bug --- .idea/workspace.xml | 44 +- client/src/components/Action.vue | 12 +- client/src/components/BuyIn.vue | 212 ++++----- client/src/components/SitList.vue | 4 +- client/src/components/gameRecord.vue | 101 ++++ client/src/components/player.vue | 176 +++++++ client/src/components/range.vue | 198 ++++---- client/src/interface/IRoom.ts | 6 + client/src/service/index.ts | 60 +-- client/src/utils/PokerStyle.ts | 591 +++++++++++++----------- client/src/views/Home.vue | 43 +- client/src/views/game.vue | 14 +- server/src.zip | Bin 0 -> 64665 bytes server/src/app/controller/gameRecord.ts | 79 ++++ server/src/app/controller/room.ts | 7 +- server/src/app/core/Poker.ts | 18 +- server/src/app/core/PokerGame.ts | 33 +- server/src/app/core/PokerStyle.ts | 70 ++- server/src/app/io/controller/game.ts | 87 +++- server/src/app/io/middleware/join.ts | 11 +- server/src/interface/ICommandRecord.ts | 6 +- server/src/interface/IGame.ts | 3 +- server/src/interface/IGameRecord.ts | 13 - server/src/interface/IGameRoom.ts | 7 + server/src/interface/IPlayer.ts | 14 + server/src/interface/IRoom.ts | 8 +- server/src/interface/IUser.ts | 2 +- server/src/service/account.ts | 4 +- server/src/service/commandRecord.ts | 27 +- server/src/service/game.ts | 20 +- server/src/service/gameRecord.ts | 22 - server/src/service/player.ts | 26 ++ server/src/service/room.ts | 18 +- server/src/service/user.ts | 2 +- server/test/app/core/pokerGame.test.ts | 1 + server/test/app/core/pokerStyle.test.ts | 6 + 36 files changed, 1298 insertions(+), 647 deletions(-) create mode 100644 client/src/components/gameRecord.vue create mode 100644 client/src/components/player.vue create mode 100644 client/src/interface/IRoom.ts create mode 100644 server/src.zip create mode 100644 server/src/app/controller/gameRecord.ts delete mode 100644 server/src/interface/IGameRecord.ts create mode 100644 server/src/interface/IPlayer.ts delete mode 100644 server/src/service/gameRecord.ts create mode 100644 server/src/service/player.ts diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 579c20d..39fcab3 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,37 +2,36 @@ + - - - - - - - - - - - - - - - + + + + + - + + + + + + + + + @@ -128,6 +128,10 @@ + + + + @@ -141,10 +145,10 @@ - + - + diff --git a/client/src/components/Action.vue b/client/src/components/Action.vue index ef62b29..aa4ec3c 100644 --- a/client/src/components/Action.vue +++ b/client/src/components/Action.vue @@ -110,11 +110,13 @@ import { IPlayer } from '@/interface/IPlayer'; } private action(command: string) { - this.actioned = true; - console.log('command:', command) - this.$emit('action', command); - // this.isAction = false; - this.isRaise = false; + if (!this.actioned) { + this.actioned = true; + this.$emit('action', command); + // this.isAction = false; + this.isRaise = false; + this.actioned = false; + } } private showActionSize(multiple: number) { diff --git a/client/src/components/BuyIn.vue b/client/src/components/BuyIn.vue index db1aabe..7e4005b 100644 --- a/client/src/components/BuyIn.vue +++ b/client/src/components/BuyIn.vue @@ -1,106 +1,106 @@ - - - - - - + + + + + + diff --git a/client/src/components/SitList.vue b/client/src/components/SitList.vue index a839f5b..2807f33 100644 --- a/client/src/components/SitList.vue +++ b/client/src/components/SitList.vue @@ -92,6 +92,7 @@ import BuyIn from '@/components/BuyIn.vue'; import { PokerStyle } from '@/utils/PokerStyle'; import map from '../utils/map'; + import {IRoom} from '@/interface/IRoom'; @Component({ components: { @@ -107,6 +108,7 @@ @Prop() private handCard!: string[]; @Prop() private winner!: IPlayer[][]; @Prop() private isPlay!: boolean; + @Prop() private roomConfig!: IRoom; @Prop() private actionUserId!: string; @Prop() private valueCards!: string; @Prop({ default: 30, type: Number }) private time!: number; @@ -141,7 +143,7 @@ handCard = cards; } const card = [...handCard, ...commonCard]; - const style = new PokerStyle(card); + const style = new PokerStyle(card, this.roomConfig.isShort); return style.getPokerStyleName(); } diff --git a/client/src/components/gameRecord.vue b/client/src/components/gameRecord.vue new file mode 100644 index 0000000..fd3c0d2 --- /dev/null +++ b/client/src/components/gameRecord.vue @@ -0,0 +1,101 @@ + + + + + + diff --git a/client/src/components/player.vue b/client/src/components/player.vue new file mode 100644 index 0000000..2ce2f39 --- /dev/null +++ b/client/src/components/player.vue @@ -0,0 +1,176 @@ + + + + + + diff --git a/client/src/components/range.vue b/client/src/components/range.vue index 7484e84..88b5860 100644 --- a/client/src/components/range.vue +++ b/client/src/components/range.vue @@ -1,99 +1,99 @@ - - - - - - + + + + + + diff --git a/client/src/interface/IRoom.ts b/client/src/interface/IRoom.ts new file mode 100644 index 0000000..94cebc2 --- /dev/null +++ b/client/src/interface/IRoom.ts @@ -0,0 +1,6 @@ +export interface IRoom { + roomNumber?: string; + isShort: boolean; + time?: number; + smallBlind: number; +} diff --git a/client/src/service/index.ts b/client/src/service/index.ts index 5cd3862..580c7ca 100644 --- a/client/src/service/index.ts +++ b/client/src/service/index.ts @@ -1,28 +1,32 @@ -import request from '../utils/request'; - -export default { - register: ({ userAccount = '', password = '', nickName = '' }) => request({ - url: '/user/register', - body: { userAccount, password, nickName }, - }), - login: (userAccount: string, password: string ) => request({ - url: '/user/login', - body: { userAccount, password }, - }), - checkLogin: () => request({ - url: '/user', - body: {}, - }), - createRoom: () => request({ - url: '/game/room', - body: { }, - }), - findRoom: (roomNumber: string) => request({ - url: '/game/room/find', - body: { roomNumber }, - }), - buyIn: (buyInSize: number) => request({ - url: '/game/buyIn', - body: { buyInSize }, - }), -}; +import request from '../utils/request'; + +export default { + register: ({ userAccount = '', password = '', nickName = '' }) => request({ + url: '/user/register', + body: { userAccount, password, nickName }, + }), + login: (userAccount: string, password: string ) => request({ + url: '/user/login', + body: { userAccount, password }, + }), + checkLogin: () => request({ + url: '/user', + body: {}, + }), + createRoom: (isShort: boolean, smallBlind: number, time: number) => request({ + url: '/game/room', + body: { isShort, smallBlind, time }, + }), + findRoom: (roomNumber: string) => request({ + url: '/game/room/find', + body: { roomNumber }, + }), + buyIn: (buyInSize: number) => request({ + url: '/game/buyIn', + body: { buyInSize }, + }), + recordList: (roomNumber: string) => request({ + url: '/game/record/find', + body: { roomNumber }, + }), +}; diff --git a/client/src/utils/PokerStyle.ts b/client/src/utils/PokerStyle.ts index 095bc15..ffb499f 100644 --- a/client/src/utils/PokerStyle.ts +++ b/client/src/utils/PokerStyle.ts @@ -1,265 +1,326 @@ -const POKER_STR = 'abcdefghijklm'; - -function sort(cards: string []): string[] { - let temp = ''; - // 排序 - for (let i = 0; i < cards.length; i++) { - for (let j = i + 1; j < cards.length; j++) { - if (cards[i] > cards[j]) { - temp = cards[i]; - cards[i] = cards[j]; - cards[j] = temp; - } - } - } - return cards; -} - -interface IPokerStyle { - init(): void; - - isStraight(str?: string []): string; -} - -enum PokerStyleEnum { - 'ROYAL_FlUSH', - 'STRAIGHT_FLUSH', - 'FOUR_KIND', - 'FULL_HOUSE', - 'FLUSH', - 'STRAIGHT', - 'THREE_KIND', - 'TWO_PAIR', - 'PAIR', - 'HIGH_CARD', -} -export class PokerStyle implements IPokerStyle { - private readonly cards: string[] = []; - private flushObj: { [key: string]: any } = { - 1: [], - 2: [], - 3: [], - 4: [], - }; - private flushColor: string = ''; - private straightArr: string[] = []; - private styleName = [ - 'ROYAL_FlUSH', - 'STRAIGHT_FLUSH', - 'FOUR_KIND', - 'FULL_HOUSE', - 'FLUSH', - 'STRAIGHT', - 'THREE_KIND', - 'TWO_PAIR', - 'PAIR', - 'HIGH_CARD']; - private pokerStyle: string[] = [ - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0', - '0']; - private numObj: Map = new Map( - POKER_STR.split('').map((m) => [m, 0])); - - constructor(cards: string[]) { - this.cards = sort(cards); - this.init(); - } - - public isStraight(str?: string []): string { - const straightStr = str && str.join('') || [ ...new Set(this.straightArr) ].join(''); - let first = -1; - let second = -1; - let three = -1; - function indexOf(pokeString: string): number { - return POKER_STR.indexOf(pokeString); - } - if (straightStr.length === 5 && indexOf(straightStr) > -1) { - return POKER_STR.slice(indexOf(straightStr), indexOf(straightStr) + 5); - } - if (straightStr.length === 6) { - first = indexOf(straightStr.slice(0, 5)); - second = indexOf(straightStr.slice(1, 6)); - if (Math.max(first, second) > -1) { - const max = Math.max(first, second); - return POKER_STR.slice(max, max + 5); - } - } - if (straightStr.length === 7) { - first = indexOf(straightStr.slice(0, 5)); - second = indexOf(straightStr.slice(1, 6)); - three = indexOf(straightStr.slice(2, 7)); - if (Math.max(first, second, three) > -1) { - const max = Math.max(first, second, three); - return POKER_STR.slice(max, max + 5); - } - } - // special straight "A2345",'m' -> A - if (straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) { - return 'mabcd'; - } - return '0'; - } - - public getPokerWeight() { - return this.pokerStyle.join(''); - } - - public getPokerStyleName() { - for (let i = 0; i < this.pokerStyle.length; i++) { - if (this.pokerStyle[i] !== '0') { - return this.styleName[i]; - } - } - } - - public init() { - let i = 0; - const isTwo = []; - const isThree = []; - let isFour = '0'; - let isFullHouse = '0'; - // const isStraightFlush = '0'; - let isFlush: string[] = []; - let isRoyalFlush = '0'; - let isThreeKind = ''; - let isTowPair = ''; - let isPair = ''; - const highCard = []; - - while (i < this.cards.length) { - const color = this.cards[i][1]; - const num = this.cards[i][0]; - this.straightArr.push(this.cards[i][0]); - this.flushObj[color].push(num); - let value = this.numObj.get(num) || 0; - value++; - this.numObj.set(num, value); - i++; - } - - // find flush - for (const f in this.flushObj) { - if (this.flushObj[f].length >= 5) { - // flush is order,so flush[length - 1] is max flush card - isFlush = this.flushObj[f]; - this.flushColor = f; - } - } - - // find two,three,four - for (const [key, value] of this.numObj) { - // high card - if (value === 1) { - highCard.unshift(key); - } - // pairs max count 3, source is small to large - if (value >= 2) { - isTwo.unshift(key); - } - // three of kind max count 2 - if (value === 3) { - isThree.unshift(key); - } - // four of kind only one - if (value === 4) { - isFour = key; - } - } - // straight flush - if (isFlush.length !== 0 && this.isStraight(isFlush) !== '0') { - if (this.isStraight(isFlush) === 'ijklm') { - isRoyalFlush = 'ijklm'; - this.pokerStyle[0] = isRoyalFlush; - return; - } - this.pokerStyle[1] = this.isStraight(isFlush).split('').reverse().join(''); - return; - } - - // four of kind - if (isFour !== '0') { - isFour += highCard[0]; - this.pokerStyle[2] = isFour; - return; - } - - // full house - if (isThree.length > 0 && isTwo.length > isThree.length || - isThree.length === 2) { - const maxTwoCard = isThree.length === 2 ? isThree[1] : isThree[0] === - isTwo[0] ? isTwo[1] : isTwo[0]; - const maxThree = isThree[0]; - isFullHouse = maxThree + maxTwoCard; - this.pokerStyle[3] = isFullHouse; - return; - } - - // flush - if (isFlush.length !== 0) { - isFlush.reverse().length = 5; - this.pokerStyle[4] = isFlush.join(''); - 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 - if (isTwo.length >= 2) { - isTowPair = isTwo.join(''); - // third tow pair card big then high card - const highCardForTowPair = isTwo[3] && isTwo[3] > highCard[0] - ? isTwo[3] - : highCard[0]; - isTowPair += highCardForTowPair; - this.pokerStyle[7] = isTowPair; - return; - } - // pair - if (isTwo.length === 1) { - isPair = isTwo.join(''); - isPair += highCard[0] + highCard[1] + highCard[2]; - this.pokerStyle[8] = isPair; - return; - } - // High card - highCard.length = 5; - this.pokerStyle[9] = highCard.join(''); - } - public getPokerValueCard() { - let valueStyle = ''; - let isFlush = false; - this.pokerStyle.forEach((style, key) => { - if (style !== '0') { - isFlush = key === 1 || key === 4; - valueStyle = style; - } - }); - const cards = this.cards.filter((card) => { - if (isFlush) { - return valueStyle.indexOf(card[0]) > -1 && card[1] === this.flushColor; - } - return valueStyle.indexOf(card[0]) > -1; - }); - cards.reverse().length = 5; - return cards; - } -} +const POKER_STR = 'abcdefghijklm'; + +function sort(cards: string []): string[] { + let temp = ''; + // 排序 + for (let i = 0; i < cards.length; i++) { + for (let j = i + 1; j < cards.length; j++) { + if (cards[i] > cards[j]) { + temp = cards[i]; + cards[i] = cards[j]; + cards[j] = temp; + } + } + } + return cards; +} + +interface IPokerStyle { + init(): void; + + isStraight(str?: string []): string; +} + +enum PokerStyleEnum { + 'ROYAL_FlUSH', + 'STRAIGHT_FLUSH', + 'FOUR_KIND', + 'FULL_HOUSE', + 'FLUSH', + 'STRAIGHT', + 'THREE_KIND', + 'TWO_PAIR', + 'PAIR', + 'HIGH_CARD', +} + +enum ShortPokerStyleEnum { + 'ROYAL_FlUSH', + 'STRAIGHT_FLUSH', + 'FOUR_KIND', + 'FLUSH', + 'FULL_HOUSE', + 'THREE_KIND', + 'STRAIGHT', + 'TWO_PAIR', + 'PAIR', + 'HIGH_CARD', +} + +export class PokerStyle implements IPokerStyle { + private readonly cards: string[] = []; + private readonly isShort: boolean; + private flushObj: { [key: string]: any } = { + 1: [], + 2: [], + 3: [], + 4: [], + }; + private flushColor: string = ''; + private straightArr: string[] = []; + private styleName = [ + 'ROYAL_FlUSH', + 'STRAIGHT_FLUSH', + 'FOUR_KIND', + 'FULL_HOUSE', + 'FLUSH', + 'STRAIGHT', + 'THREE_KIND', + 'TWO_PAIR', + 'PAIR', + 'HIGH_CARD']; + private pokerStyle: string[] = [ + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0', + '0']; + private numObj: Map = new Map( + POKER_STR.split('').map((m) => [m, 0])); + + constructor(cards: string[], isShort= false) { + this.cards = sort(cards); + this.isShort = isShort; + if (this.isShort) { + this.styleName = [ + 'ROYAL_FlUSH', + 'STRAIGHT_FLUSH', + 'FOUR_KIND', + 'FLUSH', + 'FULL_HOUSE', + 'THREE_KIND', + 'STRAIGHT', + 'TWO_PAIR', + 'PAIR', + 'HIGH_CARD', + ]; + } + this.init(); + } + + public isStraight(str?: string []): string { + const straightStr = str && str.join('') || [ ...new Set(this.straightArr) ].join(''); + let first = -1; + let second = -1; + let three = -1; + function indexOf(pokeString: string): number { + return POKER_STR.indexOf(pokeString); + } + if (straightStr.length === 5 && indexOf(straightStr) > -1) { + return POKER_STR.slice(indexOf(straightStr), indexOf(straightStr) + 5); + } + if (straightStr.length === 6) { + first = indexOf(straightStr.slice(0, 5)); + second = indexOf(straightStr.slice(1, 6)); + if (Math.max(first, second) > -1) { + const max = Math.max(first, second); + return POKER_STR.slice(max, max + 5); + } + } + if (straightStr.length === 7) { + first = indexOf(straightStr.slice(0, 5)); + second = indexOf(straightStr.slice(1, 6)); + three = indexOf(straightStr.slice(2, 7)); + if (Math.max(first, second, three) > -1) { + const max = Math.max(first, second, three); + return POKER_STR.slice(max, max + 5); + } + } + // special straight "A2345",'m' -> A + if (!this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('abcd') > -1) { + return 'abcdm'; + } + // special straight "A2345",'m' -> A + if (this.isShort && straightStr.indexOf('m') > -1 && straightStr.indexOf('efgh') > -1) { + return 'efghm'; + } + return '0'; + } + + public getPokerWeight() { + return this.pokerStyle.join(''); + } + + public getPokerStyleName() { + for (let i = 0; i < this.pokerStyle.length; i++) { + if (this.pokerStyle[i] !== '0') { + return this.styleName[i]; + } + } + } + + public init() { + let i = 0; + const isTwo = []; + const isThree = []; + let isFour = '0'; + let isFullHouse = '0'; + // const isStraightFlush = '0'; + let isFlush: string[] = []; + let isRoyalFlush = '0'; + let isThreeKind = ''; + let isTowPair = ''; + let isPair = ''; + const highCard = []; + + while (i < this.cards.length) { + const color = this.cards[i][1]; + const num = this.cards[i][0]; + this.straightArr.push(this.cards[i][0]); + this.flushObj[color].push(num); + let value = this.numObj.get(num) || 0; + value++; + this.numObj.set(num, value); + i++; + } + + // find flush + for (const f in this.flushObj) { + if (this.flushObj[f].length >= 5) { + // flush is order,so flush[length - 1] is max flush card + isFlush = this.flushObj[f]; + this.flushColor = f; + } + } + + // find two,three,four + for (const [key, value] of this.numObj) { + // high card + if (value === 1) { + highCard.unshift(key); + } + // pairs max count 3, source is small to large + if (value >= 2) { + isTwo.unshift(key); + } + // three of kind max count 2 + if (value === 3) { + isThree.unshift(key); + } + // four of kind only one + if (value === 4) { + isFour = key; + } + } + // straight flush + if (isFlush.length !== 0 && this.isStraight(isFlush) !== '0') { + if (this.isStraight(isFlush) === 'ijklm') { + isRoyalFlush = 'ijklm'; + this.pokerStyle[0] = isRoyalFlush; + return; + } + this.pokerStyle[1] = this.isStraight(isFlush).split('').reverse().join(''); + return; + } + + // four of kind + if (isFour !== '0') { + isFour += highCard[0]; + this.pokerStyle[2] = isFour; + return; + } + + // full house + if (isThree.length > 0 && isTwo.length > isThree.length || + isThree.length === 2) { + const maxTwoCard = isThree.length === 2 ? isThree[1] : isThree[0] === + isTwo[0] ? isTwo[1] : isTwo[0]; + const maxThree = isThree[0]; + isFullHouse = maxThree + maxTwoCard; + if (this.isShort) { + this.pokerStyle[4] = isFullHouse; + } else { + this.pokerStyle[3] = isFullHouse; + } + return; + } + + // flush + if (isFlush.length !== 0) { + isFlush.reverse().length = 5; + if (this.isShort) { + this.pokerStyle[3] = isFlush.join(''); + } else { + this.pokerStyle[4] = isFlush.join(''); + } + return; + } + 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; + } + } + + // tow pair + if (isTwo.length >= 2) { + const towPair = isTwo; + towPair.length = 2; + isTowPair = towPair.join(''); + // third tow pair card big then high card + const highCardForTowPair = isTwo[3] && isTwo[3] > highCard[0] ? isTwo[3] : highCard[0]; + isTowPair += highCardForTowPair; + this.pokerStyle[7] = isTowPair; + return; + } + // pair + if (isTwo.length === 1) { + isPair = isTwo.join(''); + isPair += highCard[0] + highCard[1] + highCard[2]; + this.pokerStyle[8] = isPair; + return; + } + // High card + highCard.length = 5; + this.pokerStyle[9] = highCard.join(''); + } + public getPokerValueCard() { + let valueStyle = ''; + let isFlush = false; + this.pokerStyle.forEach((style, key) => { + if (style !== '0') { + isFlush = key === 1 || this.isShort ? key === 3 : key === 4; + valueStyle = style; + } + }); + const cards = this.cards.filter((card) => { + if (isFlush) { + return valueStyle.indexOf(card[0]) > -1 && card[1] === this.flushColor; + } + return valueStyle.indexOf(card[0]) > -1; + }); + cards.reverse().length = 5; + return cards; + } +} diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 4827b4a..8c66cae 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -2,12 +2,29 @@
+
+
smallBlind:
+
+ +
+
+
+
isShort:
+
+ +
+
create room
join room
+
test record +
@@ -34,6 +51,7 @@ import { Vue } from 'vue-property-decorator'; import Component from 'vue-class-component'; import service from '../service'; + import cookie from 'js-cookie'; @Component export default class Home extends Vue { @@ -41,12 +59,18 @@ private isJoin = false; private showBtn = true; private isError = false; + private isShort = false; + private smallBlind = 1; private async createRoom() { try { - const result = await service.createRoom(); + const result = await service.createRoom(this.isShort, this.smallBlind, 0); const { roomNumber } = result.data; - console.log(result); + const roomConfig = { + isShort: this.isShort, + smallBlind: this.smallBlind, + } + cookie.set('roomConfig', roomConfig, {expires: 1}); this.$router.push({ name: 'game', params: { roomNumber, isOwner: '1' } }); } catch (e) { console.log(e); @@ -65,7 +89,11 @@ } try { const { data } = await service.findRoom(this.roomNumber); - if (data.hasRoom) { + if (data) { + const roomConfig ={ + ...data + } + cookie.set('roomConfig', roomConfig, {expires: 1}); this.$router.push({ name: 'game', params: { roomNumber: this.roomNumber } }); } else { this.$plugin.toast('can\'t find the room'); @@ -75,6 +103,15 @@ this.$plugin.toast('can\'t find the room'); } } + + private async getRecord() { + try { + const { data } = await service.recordList('170432'); + console.log(data); + } catch (e) { + this.$plugin.toast('can\'t find the room'); + } + } }