diff --git a/src/utils/assistant.util.ts b/src/utils/assistant.util.ts index fdd24f6..7ed233f 100644 --- a/src/utils/assistant.util.ts +++ b/src/utils/assistant.util.ts @@ -33,6 +33,9 @@ function pushMapVal(map: Map, key: number, value: Card) { function seekPairWithSpecial(pointMap: Map, special?: Card) { let minCount = new GameEnv().otherEatCount let result: Card[] = [] + if (!special) { + return result + } for (let [point, arr] of pointMap) { if (point == special?.number && arr.length >= minCount) { result = arr @@ -48,18 +51,13 @@ function seekPairWithSpecial(pointMap: Map, special?: Card) { * @param {number} special * @return {Card[]} */ -function seekPairNoSpecial(pointMap: Map, special?: Card) { +function seekPairNoSpecial(pointMap: Map) { let minCount = new GameEnv().selfEatCount let result: Card[] = [] - for (let [point, arr] of pointMap) { + for (let [, arr] of pointMap) { if (arr.length >= minCount ) { - if (!!special && point !== special?.number) { - result = arr - break - } else if (!special) { - result = arr - break - } + arr.cloneTo(result) + break } } return result @@ -69,11 +67,8 @@ function seekPairNoSpecial(pointMap: Map, special?: Card) { * @param pointMap * @param {number[]} points 升序的distinct点数数组 * @param {number} special 特殊点数 - * @param {boolean} hasSpecial true: 必须包含特殊点数 - * false: 不包含特殊点数, - * 如果特殊点数不存在, 那么忽略该值 */ -function seekSeq(pointMap: Map, points: number[], hasSpecial: boolean, special?: Card) { +function seekSeq(pointMap: Map, points: number[], special?: Card) { let minLength = special? new GameEnv().otherEatCount : new GameEnv().selfEatCount let tmp: number[] = [] for (let i = 0, length = points.length; i < length; i++) { @@ -83,7 +78,7 @@ function seekSeq(pointMap: Map, points: number[], hasSpecial: bo if (tmp.length < minLength) { tmp.length = 0 } else { - if (hasSpecial && !!special && tmp.indexOf(special.number) == -1) { + if (!!special && tmp.indexOf(special.number) == -1) { tmp.length = 0 } else { break @@ -91,16 +86,13 @@ function seekSeq(pointMap: Map, points: number[], hasSpecial: bo } } } - if ((!hasSpecial && !!special && cur == special.number) ) { - continue - } tmp.push(cur) } // 将获取到的点数sequence转换为Card数组 let result: Card[] = [] if (tmp.length > minLength) { for (let point of tmp) { - if (special && point === special.number) { + if (!!special && point === special.number) { result.push(special) } else { result.push(pointMap.get(point)[0]) @@ -203,17 +195,21 @@ let assistantUtil = { pushMapVal(pointMap, c.number, c) cardPointSet.add(c.number) } + let cardPoints = [...cardPointSet] + cardPoints.sort((a, b) => a - b) + let normalPairs = seekPairNoSpecial(pointMap) + let normalSecs = seekSeq(pointMap, cardPoints ) + if (eatCard && (eatCard.type == CardType.general || eatCard.type == CardType.variable_unit)) { pushMapVal(pointMap, eatCard.number, eatCard) cardPointSet.add(eatCard.number) } - let cardPoints = [...cardPointSet] + + cardPoints = [...cardPointSet] cardPoints.sort((a, b) => a - b) let eatPairs = seekPairWithSpecial(pointMap, eatCard) - let normalPairs = seekPairNoSpecial(pointMap, eatCard) - let eatSecs = seekSeq(pointMap, cardPoints, true, eatCard) - let normalSecs = seekSeq(pointMap, cardPoints, false, eatCard) + let eatSecs = seekSeq(pointMap, cardPoints, eatCard) const selfEat = normalPairs.length > 0 || normalSecs.length > 0 const otherEat = eatPairs.length > 0 || eatSecs.length > 0 return {