修改机器人吃牌逻辑
This commit is contained in:
parent
289e654175
commit
15534cdd70
@ -33,6 +33,9 @@ function pushMapVal(map: Map<number, Card[]>, key: number, value: Card) {
|
||||
function seekPairWithSpecial(pointMap: Map<number, Card[]>, 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<number, Card[]>, special?: Card) {
|
||||
* @param {number} special
|
||||
* @return {Card[]}
|
||||
*/
|
||||
function seekPairNoSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
||||
function seekPairNoSpecial(pointMap: Map<number, Card[]>) {
|
||||
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
|
||||
arr.cloneTo(result)
|
||||
break
|
||||
} else if (!special) {
|
||||
result = arr
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
@ -69,11 +67,8 @@ function seekPairNoSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
||||
* @param pointMap
|
||||
* @param {number[]} points 升序的distinct点数数组
|
||||
* @param {number} special 特殊点数
|
||||
* @param {boolean} hasSpecial true: 必须包含特殊点数
|
||||
* false: 不包含特殊点数,
|
||||
* 如果特殊点数不存在, 那么忽略该值
|
||||
*/
|
||||
function seekSeq(pointMap: Map<number, Card[]>, points: number[], hasSpecial: boolean, special?: Card) {
|
||||
function seekSeq(pointMap: Map<number, Card[]>, 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<number, Card[]>, 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<number, Card[]>, 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user