Merge pull request #737 from PZ157/PR-Branch

函数优化
This commit is contained in:
Spmario233 2023-12-22 00:27:11 +08:00 committed by GitHub
commit 6b9e5ec23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 52 deletions

View File

@ -162,11 +162,11 @@ game.import('card',function(lib,game,ui,get,ai,_status){
ai:{ ai:{
order:9, order:9,
value:function(card,player){ value:function(card,player){
if(player.getEquips(1).contains(card)) return 0; if(player.getEquips(1).contains(card)) return 0.4;
return 4; return 4;
}, },
equipValue:function(card,player){ equipValue:function(card,player){
if(player.getCards('e').contains(card)) return 0; if(player.getCards('e').contains(card)) return 0.4;
return -get.value(player.getCards('e')); return -get.value(player.getCards('e'));
}, },
basic:{ basic:{
@ -226,11 +226,17 @@ game.import('card',function(lib,game,ui,get,ai,_status){
ai:{ ai:{
order:9, order:9,
equipValue:function(card,player){ equipValue:function(card,player){
if(get.position(card)=='e') return -2; if(get.position(card)=='e'){
if(player.hasSex('male')) return -7;
return 0;
}
return 2; return 2;
}, },
value:function(card,player){ value:function(card,player){
if(player.getEquips(2).contains(card)) return -3; if(player.getEquips(2).contains(card)){
if(player.hasSex('male')) return -8;
return 0;
}
return 3; return 3;
}, },
basic:{ basic:{
@ -260,11 +266,11 @@ game.import('card',function(lib,game,ui,get,ai,_status){
ai:{ ai:{
order:9, order:9,
equipValue:function(card,player){ equipValue:function(card,player){
if(get.position(card)=='e') return -1; if(get.position(card)=='e') return -8;
return 1; return 1;
}, },
value:function(card,player){ value:function(card,player){
if(player.getEquips(2).contains(card)) return -2.5; if(player.getEquips(2).contains(card)) return -10;
return 2.5; return 2.5;
}, },
basic:{ basic:{

View File

@ -397,7 +397,10 @@ game.import('card',function(lib,game,ui,get,ai,_status){
return 2; return 2;
}, },
value:function(card,player){ value:function(card,player){
if(player.getEquips(1).contains(card)) return -1.5; if(player.getEquips(1).contains(card)){
if(player.hasSkillTag('noh')) return 0;
return -3.5;
}
return 1.5; return 1.5;
}, },
basic:{ basic:{
@ -436,7 +439,7 @@ game.import('card',function(lib,game,ui,get,ai,_status){
return 2; return 2;
}, },
value:function(card,player){ value:function(card,player){
if(player.getEquips(1).contains(card)) return -3; if(player.getEquips(1).contains(card)) return -3.5;
return 3; return 3;
}, },
basic:{ basic:{
@ -471,11 +474,11 @@ game.import('card',function(lib,game,ui,get,ai,_status){
ai:{ ai:{
order:9, order:9,
equipValue:function(card,player){ equipValue:function(card,player){
if(get.position(card)=='e') return -1; if(get.position(card)=='e') return -7;
return 1; return 1;
}, },
value:function(card,player){ value:function(card,player){
if(player.getEquips(2).contains(card)) return -2.5; if(player.getEquips(2).contains(card)) return -9;
return 2.5; return 2.5;
}, },
basic:{ basic:{

View File

@ -24429,20 +24429,20 @@ export class Library extends Uninstantable {
var player = _status.event.player; var player = _status.event.player;
var event = _status.event.getParent(); var event = _status.event.getParent();
var getn = function (card) { var getn = function (card) {
if (player.hasSkill('tianbian') && get.suit(card) == 'heart') return 13 * (event.small ? -1 : 1); if (player.hasSkill('tianbian') && get.suit(card) == 'heart') return 13 * (Boolean(event.small) ? -1 : 1);
return get.number(card) * (event.small ? -1 : 1); return get.number(card) * (Boolean(event.small) ? -1 : 1);
} }
if (source && source != player) { if (source && source != player) {
if (get.attitude(player, source) > 1) { if (get.attitude(player, source) > 1) {
if (event.small) return getn(card) - get.value(card) / 2 + addi; if (Boolean(event.small)) return getn(card) - get.value(card) / 3 + addi;
return -getn(card) - get.value(card) / 2 + addi; return -getn(card) - get.value(card) / 3 + addi;
} }
if (event.small) return -getn(card) - get.value(card) / 2 + addi; if (Boolean(event.small)) return -getn(card) - get.value(card) / 5 + addi;
return getn(card) - get.value(card) / 2 + addi; return getn(card) - get.value(card) / 5 + addi;
} }
else { else {
if (event.small) return -getn(card) - get.value(card) / 2 + addi; if (Boolean(event.small)) return -getn(card) - get.value(card) / 5 + addi;
return getn(card) - get.value(card) / 2 + addi; return getn(card) - get.value(card) / 5 + addi;
} }
} }
next.setContent('chooseToCompareMultiple'); next.setContent('chooseToCompareMultiple');
@ -24463,18 +24463,15 @@ export class Library extends Uninstantable {
var event = _status.event.getParent(); var event = _status.event.getParent();
var to = (player == event.player ? event.target : event.player); var to = (player == event.player ? event.target : event.player);
var addi = (get.value(card) >= 8 && get.type(card) != 'equip') ? -6 : 0; var addi = (get.value(card) >= 8 && get.type(card) != 'equip') ? -6 : 0;
var friend = get.attitude(player, to) > 0;
if (card.name == 'du') addi -= 5; if (card.name == 'du') addi -= 5;
if (player == event.player) { if (player == event.player) {
if (event.small) { if (Boolean(event.small)) return -getn(card) - get.value(card) / (friend ? 4 : 5) + addi;
return -getn(card) - get.value(card) / 2 + addi; return getn(card) - get.value(card) / (friend ? 4 : 5) + addi;
}
return getn(card) - get.value(card) / 2 + addi;
} }
else { else {
if ((get.attitude(player, to) <= 0) == Boolean(event.small)) { if (friend == Boolean(event.small)) return getn(card) - get.value(card) / (friend ? 3 : 5) + addi;
return -getn(card) - get.value(card) / 2 + addi; return -getn(card) - get.value(card) / (friend ? 3 : 5) + addi;
}
return getn(card) - get.value(card) / 2 + addi;
} }
} }
next.setContent('chooseToCompare'); next.setContent('chooseToCompare');
@ -28814,20 +28811,20 @@ export class Library extends Uninstantable {
if (this.hasSkillTag('respondShan', true, null, true)) return true; if (this.hasSkillTag('respondShan', true, null, true)) return true;
return this.hasUsableCard('shan'); return this.hasUsableCard('shan');
} }
mayHaveSha(viewer, type, ignore) { mayHaveSha(viewer, type, ignore, rvt) {
if ((this.hp > 2 || !this.isZhu && this.hp > 1) && this.hasSkillTag('respondSha', true, type, true)) return true; //rvt: return value type 'count', 'odds', 'bool'(default)
let count = 0;
if ((this.hp > 2 || !this.isZhu && this.hp > 1) && this.hasSkillTag('respondSha', true, type, true)) {
if (rvt === 'count') count++;
else return true;
}
if (get.itemtype(viewer) !== 'player') viewer = _status.event.player; if (get.itemtype(viewer) !== 'player') viewer = _status.event.player;
let cards, selected = get.copy(ui.selected.cards); let cards, selected = get.copy(ui.selected.cards);
if (get.itemtype(ignore) === 'cards') selected.addArray(ignore); if (get.itemtype(ignore) === 'cards') selected.addArray(ignore);
else if (get.itemtype(ignore) === 'card') selected.add(ignore); else if (get.itemtype(ignore) === 'card') selected.add(ignore);
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h'); if (this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
else cards=this.getShownCards();*/ else cards = this.getShownCards();
if (this === viewer || get.itemtype(viewer) == 'player') { count += cards.filter(card => {
cards = this.getKnownCards(viewer);
} else {
cards = this.getShownCards();
}
if (cards.some(card => {
if (selected.includes(card)) return false; if (selected.includes(card)) return false;
let name = get.name(card, this); let name = get.name(card, this);
if (name == 'sha' || name == 'hufu' || name == 'yuchanqian') { if (name == 'sha' || name == 'hufu' || name == 'yuchanqian') {
@ -28836,25 +28833,36 @@ export class Library extends Uninstantable {
return true; return true;
} }
return false; return false;
})) return true; }).length;
if (count && rvt !== 'count') return true;
let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length; let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length;
if (hs === 0) return false; if (!hs) {
return Math.pow(hs + (this.isPhaseUsing() ? 6 : 4), 2) > 100 * _status.event.getRand('mayHaveSha'); if (rvt === 'count') return count;
return false;
}
if (rvt === 'count') {
if (this.isPhaseUsing()) return count + hs / 4;
return count + hs / 4.8;
}
if (this.isPhaseUsing()) count += Math.pow(2 + hs, 2) / 40;
else count += -1.5 * Math.log(1 - hs / 10);
if (rvt === 'odds') return Math.min(1, count);
return count > _status.event.getRand('mayHaveSha' + hs + this.playerid);
}
mayHaveShan(viewer, type, ignore, rvt) {
//rvt: return value type 'count', 'odds', 'bool'(default)
let count = 0;
if ((this.hp > 2 || !this.isZhu && this.hp > 1) && this.hasSkillTag('respondShan', true, type, true)) {
if (rvt === 'count') count++;
else return true;
} }
mayHaveShan(viewer, type, ignore) {
if ((this.hp > 2 || !this.isZhu && this.hp > 1) && this.hasSkillTag('respondShan', true, type, true)) return true;
if (get.itemtype(viewer) !== 'player') viewer = _status.event.player; if (get.itemtype(viewer) !== 'player') viewer = _status.event.player;
let cards, selected = get.copy(ui.selected.cards); let cards, selected = get.copy(ui.selected.cards);
if (get.itemtype(ignore) === 'cards') selected.addArray(ignore); if (get.itemtype(ignore) === 'cards') selected.addArray(ignore);
else if (get.itemtype(ignore) === 'card') selected.add(ignore); else if (get.itemtype(ignore) === 'card') selected.add(ignore);
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h'); if (this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
else cards=this.getShownCards();*/ else cards = this.getShownCards();
if (this === viewer || get.itemtype(viewer) == 'player') { count += cards.filter(card => {
cards = this.getKnownCards(viewer);
} else {
cards = this.getShownCards();
}
if (cards.some(card => {
if (selected.includes(card)) return false; if (selected.includes(card)) return false;
let name = get.name(card, this); let name = get.name(card, this);
if (name === 'shan' || name === 'hufu') { if (name === 'shan' || name === 'hufu') {
@ -28863,10 +28871,21 @@ export class Library extends Uninstantable {
return true; return true;
} }
return false; return false;
})) return true; }).length;
if (count && rvt !== 'count') return true;
let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length; let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length;
if (hs === 0) return false; if (!hs) {
return Math.pow(hs + (this.isPhaseUsing() ? 3 : 5), 2) > 100 * _status.event.getRand('mayHaveShan'); if (rvt === 'count') return count;
return false;
}
if (rvt === 'count') {
if (this.isPhaseUsing()) return count + hs / 6;
return count + hs / 3.5;
}
if (this.isPhaseUsing()) count += -1.5 * Math.log(1 - hs / 10);
else count += 2 * hs / (5 + hs);
if (rvt === 'odds') return Math.min(1, count);
return count > _status.event.getRand('mayHaveShan' + hs + this.playerid);
} }
hasCard(name, position) { hasCard(name, position) {
if (typeof name == 'function') { if (typeof name == 'function') {