gpt4 book ai didi

javascript - Screeps-如何使路径计算一致?

转载 作者:行者123 更新时间:2023-12-02 23:48:09 24 4
gpt4 key购买 nike

我有一个用于创建房间布局的原型(prototype)。我正在尝试计算放置容器的位置:

the closest point between the spawn and the controller that is one unit away from the controller

出于某种原因,它似乎给了我多个值(可能是由于路径算法),即跳转点 according to the API 。我怎样才能每次得到相同的结果,而不是三个不同的点?

Room.prototype.layoutRoom=function(){
var s:Spawn=this.spawns()[0]
var c:Controller=this.controller;

//get path from spawn to controller
var path = this.findPath(s.pos, c.pos, {ignoreDestructibleStructures: true});

//place container on last part of path -3 to stay 1 away from controller, and closest to spawn
//length-1= on endpoint, -2 is one step away, -3 is two steps away
var loc=path[path.length-3]
console.log('layout room, put container: '+loc.x+' '+loc.y)
this.createConstructionSite(loc.x, loc.y, STRUCTURE_CONTAINER);
}

多次运行上面的代码(这是必需的)会产生多个构建站点:

enter image description here

最佳答案

默认情况下,路径查找会将小兵视为不可通行的方 block 。要解决此问题,请将其添加到选项中:

ignoreCreeps: true

关于javascript - Screeps-如何使路径计算一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com