修改机器人吃牌逻辑
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) {
|
function seekPairWithSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
||||||
let minCount = new GameEnv().otherEatCount
|
let minCount = new GameEnv().otherEatCount
|
||||||
let result: Card[] = []
|
let result: Card[] = []
|
||||||
|
if (!special) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
for (let [point, arr] of pointMap) {
|
for (let [point, arr] of pointMap) {
|
||||||
if (point == special?.number && arr.length >= minCount) {
|
if (point == special?.number && arr.length >= minCount) {
|
||||||
result = arr
|
result = arr
|
||||||
@ -48,18 +51,13 @@ function seekPairWithSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
|||||||
* @param {number} special
|
* @param {number} special
|
||||||
* @return {Card[]}
|
* @return {Card[]}
|
||||||
*/
|
*/
|
||||||
function seekPairNoSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
function seekPairNoSpecial(pointMap: Map<number, Card[]>) {
|
||||||
let minCount = new GameEnv().selfEatCount
|
let minCount = new GameEnv().selfEatCount
|
||||||
let result: Card[] = []
|
let result: Card[] = []
|
||||||
for (let [point, arr] of pointMap) {
|
for (let [, arr] of pointMap) {
|
||||||
if (arr.length >= minCount ) {
|
if (arr.length >= minCount ) {
|
||||||
if (!!special && point !== special?.number) {
|
arr.cloneTo(result)
|
||||||
result = arr
|
break
|
||||||
break
|
|
||||||
} else if (!special) {
|
|
||||||
result = arr
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -69,11 +67,8 @@ function seekPairNoSpecial(pointMap: Map<number, Card[]>, special?: Card) {
|
|||||||
* @param pointMap
|
* @param pointMap
|
||||||
* @param {number[]} points 升序的distinct点数数组
|
* @param {number[]} points 升序的distinct点数数组
|
||||||
* @param {number} special 特殊点数
|
* @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 minLength = special? new GameEnv().otherEatCount : new GameEnv().selfEatCount
|
||||||
let tmp: number[] = []
|
let tmp: number[] = []
|
||||||
for (let i = 0, length = points.length; i < length; i++) {
|
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) {
|
if (tmp.length < minLength) {
|
||||||
tmp.length = 0
|
tmp.length = 0
|
||||||
} else {
|
} else {
|
||||||
if (hasSpecial && !!special && tmp.indexOf(special.number) == -1) {
|
if (!!special && tmp.indexOf(special.number) == -1) {
|
||||||
tmp.length = 0
|
tmp.length = 0
|
||||||
} else {
|
} else {
|
||||||
break
|
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)
|
tmp.push(cur)
|
||||||
}
|
}
|
||||||
// 将获取到的点数sequence转换为Card数组
|
// 将获取到的点数sequence转换为Card数组
|
||||||
let result: Card[] = []
|
let result: Card[] = []
|
||||||
if (tmp.length > minLength) {
|
if (tmp.length > minLength) {
|
||||||
for (let point of tmp) {
|
for (let point of tmp) {
|
||||||
if (special && point === special.number) {
|
if (!!special && point === special.number) {
|
||||||
result.push(special)
|
result.push(special)
|
||||||
} else {
|
} else {
|
||||||
result.push(pointMap.get(point)[0])
|
result.push(pointMap.get(point)[0])
|
||||||
@ -203,17 +195,21 @@ let assistantUtil = {
|
|||||||
pushMapVal(pointMap, c.number, c)
|
pushMapVal(pointMap, c.number, c)
|
||||||
cardPointSet.add(c.number)
|
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)) {
|
if (eatCard && (eatCard.type == CardType.general || eatCard.type == CardType.variable_unit)) {
|
||||||
pushMapVal(pointMap, eatCard.number, eatCard)
|
pushMapVal(pointMap, eatCard.number, eatCard)
|
||||||
cardPointSet.add(eatCard.number)
|
cardPointSet.add(eatCard.number)
|
||||||
}
|
}
|
||||||
let cardPoints = [...cardPointSet]
|
|
||||||
|
cardPoints = [...cardPointSet]
|
||||||
cardPoints.sort((a, b) => a - b)
|
cardPoints.sort((a, b) => a - b)
|
||||||
|
|
||||||
let eatPairs = seekPairWithSpecial(pointMap, eatCard)
|
let eatPairs = seekPairWithSpecial(pointMap, eatCard)
|
||||||
let normalPairs = seekPairNoSpecial(pointMap, eatCard)
|
let eatSecs = seekSeq(pointMap, cardPoints, eatCard)
|
||||||
let eatSecs = seekSeq(pointMap, cardPoints, true, eatCard)
|
|
||||||
let normalSecs = seekSeq(pointMap, cardPoints, false, eatCard)
|
|
||||||
const selfEat = normalPairs.length > 0 || normalSecs.length > 0
|
const selfEat = normalPairs.length > 0 || normalSecs.length > 0
|
||||||
const otherEat = eatPairs.length > 0 || eatSecs.length > 0
|
const otherEat = eatPairs.length > 0 || eatSecs.length > 0
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user