Merge pull request #764 from PZ157/PR-Branch

重写曹宪的两个ai
This commit is contained in:
Spmario233 2024-01-05 23:49:19 +08:00 committed by GitHub
commit 352b619369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 18 deletions

View File

@ -1843,7 +1843,7 @@ game.import('card',function(lib,game,ui,get,ai,_status){
},0); },0);
}, },
target:(player,target,card)=>{ target:(player,target,card)=>{
let targets=get.copy(ui.selected.targets); let targets=[].concat(ui.selected.targets);
if(_status.event.preTarget) targets.add(_status.event.preTarget); if(_status.event.preTarget) targets.add(_status.event.preTarget);
if(targets.length){ if(targets.length){
let preTarget=targets.lastItem,pre=_status.event.getTempCache('jiedao_result',preTarget.playerid); let preTarget=targets.lastItem,pre=_status.event.getTempCache('jiedao_result',preTarget.playerid);

View File

@ -1814,7 +1814,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
} }
return 0; return 0;
}, },
selectTargetAi:function(event,player){ selectTargetAi:(event,player)=>{
let cache=_status.event.getTempCache('sblijian','targets'); let cache=_status.event.getTempCache('sblijian','targets');
if(Array.isArray(cache)) return cache.length; if(Array.isArray(cache)) return cache.length;
let targets=[],cards=[0],sbbiyue=player.hasSkill('sbbiyue')?Math.max(0,3-game.countPlayer2(current=>{ let targets=[],cards=[0],sbbiyue=player.hasSkill('sbbiyue')?Math.max(0,3-game.countPlayer2(current=>{
@ -1822,7 +1822,9 @@ game.import('character',function(lib,game,ui,get,ai,_status){
})):0,alter=[null,1,1],temp; })):0,alter=[null,1,1],temp;
for(let i of game.players){ for(let i of game.players){
if(player===i) continue; if(player===i) continue;
temp=get.effect(i,new lib.element.VCard({name:'juedou',isCard:true}),get.copy(i),i); let vplayer=new lib.element.Player(i);
temp=get.effect(i,new lib.element.VCard({name:'juedou',isCard:true}),vplayer,i);
vplayer.remove();
if(temp){ if(temp){
let att=get.attitude(event.player,i); let att=get.attitude(event.player,i);
if(!att&&sbbiyue||att*temp>0) targets.push([i,temp,att]); if(!att&&sbbiyue||att*temp>0) targets.push([i,temp,att]);

View File

@ -121,10 +121,48 @@ game.import('character',function(lib,game,ui,get,ai,_status){
content:function*(event,map){ content:function*(event,map){
var player=map.player,num=player.maxHp; var player=map.player,num=player.maxHp;
var result=yield player.chooseCard(get.prompt('dclingxi'),'将至多'+get.cnNumber(num)+'张牌称为“翼”置于武将牌上','he',[1,num]).set('ai',card=>{ var result=yield player.chooseCard(get.prompt('dclingxi'),'将至多'+get.cnNumber(num)+'张牌称为“翼”置于武将牌上','he',[1,num]).set('ai',card=>{
var player=_status.event.player; let player=_status.event.player,dis=player.needsToDiscard(0,(i,player)=>{
if(player.countCards('hs',card=>player.hasValueTarget(card))&&player.countCards('hs',card=>player.hasValueTarget(card)&&!ui.selected.cards.includes(card))<=2) return 0; return !player.canIgnoreHandcard(i)&&!ui.selected.cards.includes(i);
return 6-get.value(card)+(player.getExpansions('dclingxi').some(cardx=>get.suit(card,false)==get.suit(cardx,false))?1:3); }),
}).set('complexCard',true); cards=ui.selected.cards.concat(player.getExpansions('dclingxi')),
suit=get.suit(card,false);
if(_status.event.suits.length<4) _status.event.suits.add(get.suit(ui.selected.cards.at(-1),false));
if(_status.event.name==='phaseUseEnd'){
if(_status.event.suits.includes(suit)) return (dis?10:3)-get.useful(card);
return (dis?6:1)-get.useful(card);
}
_status.event.hvt.remove(ui.selected.cards.at(-1));
if(_status.event.hvt.length===1&&card===_status.event.hvt[0]) return 0;
let temp;
if(!cards.some(i=>{
temp=get.suit(i,false);
return cards.some(j=>{
return i!==j&&suit===get.suit(j,false);
});
})&&suit===temp) return 15-get.value(card);
if(!_status.event.hvt.length){
if(_status.event.suits.includes(suit)) return (dis?10:3)-get.useful(card);
return (dis?6:1)-get.useful(card);
}
if(_status.event.hvt.includes(card)){
if(_status.event.suits.length>=4){
if(cards.length>8) return 0;
return 4.5-get.value(card);
}
if(!_status.event.suits.includes(suit)) return 6-get.value(card);
if(card.name==='sha') return 3-get.value(card);
return 1-get.value(card);
}
return 15-get.value(card);
}).set('complexCard',true).set('hvt',player.getCards('hs',card=>{
return card.name==='zhuge'||player.hasValueTarget(card,null,true);
})).set('suits',(()=>{
let suits=[];
player.getExpansions('dclingxi').forEach(i=>{
suits.add(get.suit(i,false));
});
return suits;
})()).set('name',event.triggername);
if(result.bool){ if(result.bool){
player.logSkill('dclingxi'); player.logSkill('dclingxi');
player.addToExpansion(result.cards,player,'give').gaintag.add('dclingxi'); player.addToExpansion(result.cards,player,'give').gaintag.add('dclingxi');
@ -188,11 +226,35 @@ game.import('character',function(lib,game,ui,get,ai,_status){
var player=map.player,cards=player.getExpansions('dclingxi'); var player=map.player,cards=player.getExpansions('dclingxi');
var num=player.getHistory('useSkill',evt=>evt.skill=='dczhifou').length+1; var num=player.getHistory('useSkill',evt=>evt.skill=='dczhifou').length+1;
var result=yield player.chooseButton(['###'+get.prompt('dczhifou')+'###移去至少'+get.cnNumber(num)+'张武将牌上的“翼”',cards],[num,cards.length]).set('ai',button=>{ var result=yield player.chooseButton(['###'+get.prompt('dczhifou')+'###移去至少'+get.cnNumber(num)+'张武将牌上的“翼”',cards],[num,cards.length]).set('ai',button=>{
var player=_status.event.player; if(!_status.event.res.bool) return 0;
if(2*player.getExpansions('dclingxi').filter(card=>!ui.selected.buttons.some(but=>but.link==card)).reduce((list,card)=>list.add(get.suit(card,false)),[]).length-player.countCards('h')<=0) return 0; if(_status.event.res.cards.includes(button.link)) return 1;
if(player.getExpansions('dclingxi').filter(card=>!ui.selected.buttons.some(but=>get.suit(but.link,false)==get.suit(card,false)))) return 3; return 0;
return 1; }).set('num',num).set('res',(()=>{
}).set('num',num); if(player.isPhaseUsing()&&player.hasCard(i=>{
return player.hasValueTarget(i,null,true);
},'h')) return false;
let suits=[],cs=player.getExpansions('dclingxi'),cards=[],temp=num;
for(let i=0;i<cs.length;i++){
if(!temp) break;
let suit=get.suit(cs[i],false);
if(suits.includes(suit)){
cards.push(cs.splice(i--,1)[0]);
temp--;
}
else suits.push(suit);
}
while(temp>0){
cards.push(cs.pop());
temp--;
}
temp=suits.length*2-player.countCards('h');
if(temp>0||!temp&&num<Math.max(2,5-player.hp)) cs=true;
else cs=false;
return {
bool:cs,
cards:cards
};
})());
if(result.bool){ if(result.bool){
player.logSkill('dczhifou'); player.logSkill('dczhifou');
player.loseToDiscardpile(result.links); player.loseToDiscardpile(result.links);
@ -12604,14 +12666,28 @@ game.import('character',function(lib,game,ui,get,ai,_status){
if(cards[0].name.indexOf('pyzhuren_')==0&&!player.getCards('e').includes(cards[0])) player.draw(2); if(cards[0].name.indexOf('pyzhuren_')==0&&!player.getCards('e').includes(cards[0])) player.draw(2);
}, },
ai:{ ai:{
order:11, order:(item,player)=>{
if(player.hasCard(i=>get.subtype(i)==='equip1','h')) return 11;
return 1;
},
expose:0.2, expose:0.2,
result:{ result:{
target:function(player,target){ target:function(player,target){
if(ui.selected.cards.length){ if(ui.selected.cards.length){
var card=ui.selected.cards[0]; let card=ui.selected.cards[0],tv=get.value(card,target),sub=get.subtype(card);
if(target.getEquip(card)||target.countCards('h',{subtype:get.subtype(card)})) return 0; if(sub==='equip1'){
return get.effect(target,card,player,target); let ev=Infinity,te=target.getEquips(1);
if(!te.length) return tv;
te.forEach(i=>{
ev=Math.min(ev,get.value(i));
});
if(card.name.indexOf('pyzhuren_')==0) return 2+tv-ev;
return tv-ev;
}
if(target.hasCard(i=>get.subtype(i)===sub,'he')) return 0;
let pv=get.value(card,player);
if(pv>0&&Math.abs(tv)<=pv) return 0;
return tv;
} }
return 0; return 0;
}, },
@ -12683,6 +12759,15 @@ game.import('character',function(lib,game,ui,get,ai,_status){
if(result.color=='red') player.recover(); if(result.color=='red') player.recover();
else player.draw(2); else player.draw(2);
}, },
ai:{
equipValue:function(card,player){
if(player.isDamaged()) return 4.5;
return 6;
},
basic:{
equipValue:4.5
}
}
}, },
pyzhuren_diamond:{ pyzhuren_diamond:{
audio:true, audio:true,
@ -12734,7 +12819,13 @@ game.import('character',function(lib,game,ui,get,ai,_status){
}, },
ai:{ ai:{
expose:0.25, expose:0.25,
}, equipValue:function(card,player){
return Math.min(7,3.6+player.countCards('h')/2);
},
basic:{
equipValue:4.5
}
}
}, },
pyzhuren_club:{ pyzhuren_club:{
audio:true, audio:true,
@ -12781,6 +12872,18 @@ game.import('character',function(lib,game,ui,get,ai,_status){
trigger.targets.addArray(event.targets); trigger.targets.addArray(event.targets);
} }
}, },
ai:{
equipValue:function(card,player){
if(player.getEnemies().length<2){
if(player.isDamaged()) return 0;
return 1;
}
return 4.5;
},
basic:{
equipValue:4.5
}
}
}, },
pyzhuren_spade:{ pyzhuren_spade:{
audio:true, audio:true,
@ -12800,6 +12903,12 @@ game.import('character',function(lib,game,ui,get,ai,_status){
trigger.target.loseHp(Math.min(num,5));//.set('source',player); trigger.target.loseHp(Math.min(num,5));//.set('source',player);
}, },
ai:{ ai:{
equipValue:function(card,player){
return 1+4*Math.min(5,player.getCardUsable('sha'));
},
basic:{
equipValue:5
},
jueqing:true, jueqing:true,
unequip_ai:true, unequip_ai:true,
skillTagFilter:function(player,tag,arg){ skillTagFilter:function(player,tag,arg){
@ -12839,6 +12948,15 @@ game.import('character',function(lib,game,ui,get,ai,_status){
player.draw(); player.draw();
} }
}, },
ai:{
equipValue:function(card,player){
if(player.isDamaged()) return 6;
return 4.8;
},
basic:{
equipValue:5
}
}
}, },
//管辂和葛玄 //管辂和葛玄
gxlianhua:{ gxlianhua:{

View File

@ -7582,7 +7582,7 @@ export class Player extends HTMLDivElement {
} }
getFriends(func) { getFriends(func) {
var player = this; var player = this;
var targets; var targets = [];
var mode = get.mode(); var mode = get.mode();
var self = false; var self = false;
if (func === true) { if (func === true) {