Optimize automaticRoute_bfs

This commit is contained in:
ckcz123 2020-06-25 12:01:35 +08:00
parent cd41c90c60
commit 80ae48250b
2 changed files with 6 additions and 5 deletions

View File

@ -228,7 +228,7 @@ core.prototype.init = function (coreData, callback) {
this._init_flags();
this._init_platform();
this._init_others();
this._initPlugins();
this._init_plugins();
// 初始化画布
for (var name in core.canvas) {
@ -410,7 +410,7 @@ core.prototype._afterLoadResources = function (callback) {
if (callback) callback();
}
core.prototype._initPlugins = function () {
core.prototype._init_plugins = function () {
core.plugin = new function () {};
for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) {

View File

@ -704,6 +704,7 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
var queue = new PriorityQueue({comparator: function (a,b) { return a.depth - b.depth; }});
route[startX + "," + startY] = '';
queue.queue({depth: 0, x: startX, y: startY});
var blocks = core.getMapBlocksObj();
while (queue.length!=0) {
var curr = queue.dequeue(), deep = curr.depth, nowX = curr.x, nowY = curr.y;
for (var direction in core.utils.scan) {
@ -719,17 +720,17 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
// 不可通行
if (core.noPass(nx, ny)) continue;
route[nx+","+ny] = direction;
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny), x: nx, y: ny});
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny, blocks), x: nx, y: ny});
}
if (route[destX+","+destY] != null) break;
}
return route;
}
maps.prototype._automaticRoute_deepAdd = function (x, y) {
maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
// 判定每个可通行点的损耗值,越高越应该绕路
var deepAdd = 1;
var block = core.getBlock(x,y);
var block = blocks[x+","+y];
if (block != null){
var id = block.block.event.id;
// 绕过亮灯