gpt4 book ai didi

javascript - 为什么我的守卫小兵不攻击敌人?

转载 作者:行者123 更新时间:2023-11-30 17:10:48 24 4
gpt4 key购买 nike

所以我创建了一个守卫小兵;

Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.TOUGH, Game.MOVE], "guard1", {role:"guard"});

然后我把这个作为我的主要内容:

var harvester = require('harvester');
var guard = require('guard');

for(var nam in Game.creeps) {
var creep = Game.creeps[nam];

if(creep.memory.role == 'guard') {
guard(creep);
}

if(creep.memory.role == 'harvester') {
harvester(creep);
}

if(creep.memory.role == 'builder') {

if(creep.energy === 0) {
creep.moveTo(Game.spawns.Spawn1);
Game.spawns.Spawn1.transferEnergy(creep);
}
else {
var targets = creep.room.find(Game.CONSTRUCTION_SITES);
if(targets.length) {
creep.moveTo(targets[0]);
creep.build(targets[0]);
}
}
}
}

然后是守卫脚本

module.exports = function (creep) {

var targets = creep.room.find(Game.HOSTILE_CREEPS);
if(targets.length) {
creep.moveTo(targets[0]);
creep.attack(targets[0]);
}else{
creep.moveTo(Game.spawns.Spawn1);
}
}

在教程中运行良好,但现在在实际模拟中,它不起作用。

最佳答案

我测试了您的脚本,它们实际上在生存模式下运行良好。具体问题是什么?您是否检查过您是否用完了 CPU 时间?

关于javascript - 为什么我的守卫小兵不攻击敌人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27062400/

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