mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
Source access computation
This commit is contained in:
parent
e7f66d8918
commit
a91ac17be1
27
Empire.js
27
Empire.js
@ -82,6 +82,31 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
sellEnergy: function(roomname){
|
sellEnergy: function(roomname){
|
||||||
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_SELL)
|
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_SELL)
|
||||||
|
},
|
||||||
|
computeSourceAccess: function(){
|
||||||
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
let minablepositions = 0
|
||||||
|
let srcs = Game.rooms[name].find(FIND_SOURCES);
|
||||||
|
for(let i = 0;i<srcs.length;i++)
|
||||||
|
{
|
||||||
|
minablepositions = minablepositions + this.computeSourceAccessPoints(Game.rooms[name],srcs[i])
|
||||||
|
//minablepositions = minablepositions + this.checkminablepositions(srcs[i])
|
||||||
|
}
|
||||||
|
Game.rooms[name].memory.minablepositions = minablepositions
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computeSourceAccessPoints: function(room, source){
|
||||||
|
const roomTerrain = room.getTerrain();
|
||||||
|
var accessPoints = 0;
|
||||||
|
for(var x = -1;x<=1;x++)
|
||||||
|
{
|
||||||
|
for(var y = -1;y<=1;y++)
|
||||||
|
{
|
||||||
|
if(x==0 && y==0){continue;}
|
||||||
|
if(roomTerrain.get(source.pos.x+x,source.pos.y+y)!=1){accessPoints++;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return accessPoints;
|
||||||
}
|
}
|
||||||
};
|
};
|
46
RoomInit.js
46
RoomInit.js
@ -10,22 +10,40 @@ let initroom = {
|
|||||||
Game.rooms[name].memory.tickssofar=0
|
Game.rooms[name].memory.tickssofar=0
|
||||||
Game.rooms[name].memory.maphits={}
|
Game.rooms[name].memory.maphits={}
|
||||||
//Game.rooms[name].memory.minablepositions= this.checkminablepositions(name)
|
//Game.rooms[name].memory.minablepositions= this.checkminablepositions(name)
|
||||||
|
let minablepositions = 0
|
||||||
|
let srcs = Game.rooms[name].find(FIND_SOURCES);
|
||||||
|
for(let i = 0;i<srcs.length;i++)
|
||||||
|
{
|
||||||
|
minablepositions = minablepositions + this.computeSourceAccessPoints(Game.rooms[name],srcs[i])
|
||||||
|
//minablepositions = minablepositions + this.checkminablepositions(srcs[i])
|
||||||
|
}
|
||||||
|
Game.rooms[name].memory.minablepositions = minablepositions
|
||||||
},
|
},
|
||||||
|
computeSourceAccessPoints: function(room, source){
|
||||||
|
const roomTerrain = room.getTerrain();
|
||||||
|
var accessPoints = 0;
|
||||||
|
for(var x = -1;x<=1;x++)
|
||||||
|
{
|
||||||
|
for(var y = -1;y<=1;y++)
|
||||||
|
{
|
||||||
|
if(x==0 && y==0){continue;}
|
||||||
|
if(roomTerrain.get(source.pos.x+x,source.pos.y+y)!=1){accessPoints++;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return accessPoints;
|
||||||
|
},
|
||||||
checkminablepositions: function(name){
|
checkminablepositions: function(name){
|
||||||
Source.prototype.analyzeFreeSpaces = function() {
|
let x = this.pos.x;
|
||||||
let x = this.pos.x;
|
let y = this.pos.y;
|
||||||
let y = this.pos.y;
|
let walkable = this.room.lookForAtArea(
|
||||||
let walkable = this.room.lookForAtArea(
|
LOOK_TERRAIN,
|
||||||
LOOK_TERRAIN,
|
y - 1, // top
|
||||||
y - 1, // top
|
x - 1, // left
|
||||||
x - 1, // left
|
y + 1, // bottom
|
||||||
y + 1, // bottom
|
x + 1, // right
|
||||||
x + 1, // right
|
true // asArray
|
||||||
true // asArray
|
).filter(o => o[LOOK_TERRAIN] !== 'wall');
|
||||||
).filter(o => o[LOOK_TERRAIN] !== 'wall');
|
return walkable.length;
|
||||||
return walkable.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = initroom
|
module.exports = initroom
|
2
main.js
2
main.js
@ -63,7 +63,7 @@ module.exports.loop = function () {
|
|||||||
require('role.' + creep.memory.role).run(creep)
|
require('role.' + creep.memory.role).run(creep)
|
||||||
//creep.say("TRYING")
|
//creep.say("TRYING")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("creep error")
|
console.log("creep error " + Game.creeps[name])
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user