修改机器人逻辑, 默认出点数最小的牌

This commit is contained in:
zhl 2020-12-14 16:24:02 +08:00
parent e2b42c1ad6
commit 54591b6de4

View File

@ -13,6 +13,7 @@ import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
import CfgMan from '../rooms/logic/CfgMan';
import {SkillTargetType} from "../rooms/logic/skill/SkillConst";
import {Player} from "../rooms/schema/Player";
import gameUtil from "../utils/game.util";
export class RobotClient implements Client {
id: string;
@ -143,72 +144,11 @@ export class RobotClient implements Client {
}
}
if (result.length < 3) {
return [result[0]];
return [cards[0]];
} else {
return result;
}
}
// >>>>>>>>>>>>>>>>>> begin
private discard() {
let self = this;
let next = function () {
let cardArr = [...self.cards.values()];
// cardArr.sort((a, b) => a.number - b.number);
let cards = self.checkTriple(cardArr);
if (!cards) {
return;
}
let cardIds = cards.map(o => o.id);
self.reply('discard_card_c2s', {
cards: cardIds
});
}
this.clock.setTimeout(next, 1500);
}
private eatOrGiveUp() {
let targetCard = [...this.svrstate.cards.values()][0];
let cardArr = [...this.cards.values()];
let tmpCards = this.checkTriple(cardArr, targetCard);
let next = this.giveup.bind(this);
if (tmpCards.length > 1) {
let cardIds: number[] = [];
for (let card of tmpCards) {
if (card.id !== targetCard.id) {
cardIds.push(card.id);
}
}
next = this.eatCard.bind(this, cardIds, targetCard.id);
}
this.clock.setTimeout(next, 1500);
}
private eatCard(cardIds: number[], target: number) {
log(`${this.sessionId} 吃牌 ${cardIds} -> ${target}`);
this.reply('eat_card_c2s', {
cards: cardIds,
target
});
}
private giveup () {
this.reply('give_up_eat_c2s', {});
}
private selectHero() {
this.cards = this.svrstate.players.get(this.sessionId).cards;
let heroMap: Map<number, HeroCfg> = global.$cfg.get(BaseConst.HERO);
let heroArr = [...heroMap.values()];
let hero = arrUtil.randomGet(heroArr, 1);
this.reply('select_hero_c2s', {
heroId: hero[0].id
});
}
private changeCard() {
let cardIds: number[] = [];
this.reply('change_card_c2s', {
cards: cardIds
});
}
/**
*
* @private
@ -232,7 +172,7 @@ export class RobotClient implements Client {
let pets = [];
for (let [, pet] of player.pets) {
if (pet.ap > 0 && pet.state == 1)
pets.push(pet);
pets.push(pet);
}
let result;
if (pets.length > 0) {
@ -240,6 +180,103 @@ export class RobotClient implements Client {
}
return result ? result.pos : -1;
}
// >>>>>>>>>>>>>>>>>> begin
/**
*
* @private
*/
private discard() {
let self = this;
let next = function () {
let cardArr = [...self.cards.values()];
// cardArr.sort((a, b) => a.number - b.number);
let cards = self.checkTriple(cardArr);
if (!cards) {
return;
}
let cardIds = cards.map(o => o.id);
self.reply('discard_card_c2s', {
cards: cardIds
});
}
this.clock.setTimeout(next, 1500);
}
/**
*
* @private
*/
private eatOrGiveUp() {
let targetCard = [...this.svrstate.cards.values()][0];
let cardArr = [...this.cards.values()];
let tmpCards = this.checkTriple(cardArr, targetCard);
let next = this.giveup.bind(this);
if (tmpCards.length > 1) {
let cardIds: number[] = [];
for (let card of tmpCards) {
if (card.id !== targetCard.id) {
cardIds.push(card.id);
}
}
next = this.eatCard.bind(this, cardIds, targetCard.id);
}
this.clock.setTimeout(next, 1500);
}
/**
*
* @param cardIds
* @param target
* @private
*/
private eatCard(cardIds: number[], target: number) {
log(`${this.sessionId} 吃牌 ${cardIds} -> ${target}`);
this.reply('eat_card_c2s', {
cards: cardIds,
target
});
}
/**
*
* @private
*/
private giveup () {
this.reply('give_up_eat_c2s', {});
}
/**
*
* @private
*/
private selectHero() {
this.cards = this.svrstate.players.get(this.sessionId).cards;
let heroMap: Map<number, HeroCfg> = global.$cfg.get(BaseConst.HERO);
let heroArr = [...heroMap.values()];
let hero = arrUtil.randomGet(heroArr, 1);
this.reply('select_hero_c2s', {
heroId: hero[0].id
});
}
/**
*
* @private
*/
private changeCard() {
let cardIds: number[] = [];
this.reply('change_card_c2s', {
cards: cardIds
});
}
/**
*
* @private
*/
private selectPet() {
let cards = [...this.svrstate.cards.values()];
let result;