Binary Search for critical

This commit is contained in:
oc 2018-12-22 23:01:39 +08:00
parent 84afb2c76e
commit bf6c143ea0
4 changed files with 47 additions and 25 deletions

View File

@ -555,13 +555,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_leaf": true, "_leaf": true,
"_type": "checkbox", "_type": "checkbox",
"_bool": "bool", "_bool": "bool",
"_data": "是否循环计算临界如果此项为true则使用循环法而不是回合数计算法来算临界" "_data": "是否循环计算临界如果此项为true则使用循环法而不是回合数计算法来算临界\n从V2.5.3开始,对于大数据的循环法将改为使用二分法进行计算"
},
"loopStep": {
"_leaf": true,
"_type": "textbox",
"_range": "thiseval==null || thiseval>0",
"_data": "循环计算临界时,每次攻击增加量为原始攻击的多少分之一。\n例如5000就代表循环中每次攻击增加量是原始攻击的1/5000向上取整。\n默认值5000。"
}, },
"startUsingCanvas": { "startUsingCanvas": {
"_leaf": true, "_leaf": true,

View File

@ -210,16 +210,45 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
} }
} }
else { // 暴力for循环法 else { // 暴力for循环法
// V2.5.3以后,大数据改为二分法进行计算
var LOOP_MAX_VALUE = 1;
pre = info.damage; pre = info.damage;
var per_add = Math.ceil(hero_atk / (core.flags.loopStep||5000)); if (hero_atk <= LOOP_MAX_VALUE) { // 循环法
if (per_add<0) per_add = 1; for (var atk=hero_atk+1;atk<=mon_hp+mon_def;atk++) {
for (var atk=hero_atk+per_add;atk<=mon_hp+mon_def;atk+=per_add) { var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, atk, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, atk, core.status.hero.def, core.status.hero.mdef, x, y, floorId); if (nextInfo==null) break;
if (nextInfo==null) break; if (pre>nextInfo.damage) {
if (pre>nextInfo.damage) { pre = nextInfo.damage;
pre = nextInfo.damage; list.push([atk-hero_atk, info.damage-nextInfo.damage]);
list.push([atk-hero_atk, Math.floor(info.damage-nextInfo.damage)]); if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break;
if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break; if (list.length>=number) break;
}
}
}
else { // 二分法算临界
var calNext = function (currAtk, maxAtk) {
var start = Math.floor(currAtk), end = Math.floor(maxAtk);
if (start>end) return null;
while (start<end) {
var mid = Math.floor((start+end)/2);
var nextInfo = core.enemys.getDamageInfo(enemy, core.status.hero.hp, mid, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
if (nextInfo == null) return null;
if (pre>nextInfo.damage) end = mid;
else start = mid+1;
}
var nextInfo = core.enemys.getDamageInfo(enemy, core.status.hero.hp, start, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
return nextInfo==null||nextInfo.damage>=pre?null:[start,nextInfo.damage];
}
var currAtk = hero_atk;
while (true) {
var next = calNext(currAtk+1, mon_hp+mon_def, pre);
if (next == null) break;
currAtk = next[0];
pre = next[1];
list.push([currAtk-hero_atk, info.damage-pre]);
if (pre<=0 && !core.flags.enableNegativeDamage) break;
if (list.length>=number) break; if (list.length>=number) break;
} }
} }

View File

@ -382,7 +382,6 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"hatredDecrease": true, "hatredDecrease": true,
"betweenAttackCeil": false, "betweenAttackCeil": false,
"useLoop": false, "useLoop": false,
"loopStep": 5000,
"startUsingCanvas": false, "startUsingCanvas": false,
"startDirectly": false, "startDirectly": false,
"statusCanvas": false, "statusCanvas": false,

View File

@ -632,14 +632,14 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
damage=Math.max(0, damage); damage=Math.max(0, damage);
return { return {
"mon_hp": mon_hp, "mon_hp": Math.floor(mon_hp),
"mon_atk": mon_atk, "mon_atk": Math.floor(mon_atk),
"mon_def": mon_def, "mon_def": Math.floor(mon_def),
"init_damage": init_damage, "init_damage": Math.floor(init_damage),
"per_damage": per_damage, "per_damage": Math.floor(per_damage),
"hero_per_damage": hero_per_damage, "hero_per_damage": Math.floor(hero_per_damage),
"turn": turn, "turn": Math.floor(turn),
"damage": damage "damage": Math.floor(damage)
}; };
}, },
"updateEnemys": function () { "updateEnemys": function () {