New and a bit swamped
-
I'm a C++ programmer by profession, so the switch to JavaScript has been difficult, and I am unfamiliar with just the basics of how to run an AI, much less in JavaScript, so I'm having trouble getting started. I've been reading the API documentation, but that and the tutorial haven't helped in getting creep creation and assignment automated (not that I've found at least), so I'd appreciate all the help I can get. I've spent all day today and into the evening just trying to automate creep worker creation in the tutorial and haven't been successful.
Suggestions?
I still haven't figured out what should be in charge of creep creation and assignment. I'm tentatively settling on having the individual spawners be the "brains" of a room, if you will, for creating worker creeps and assigning them to specific tasks (harvest this resource, upgrade spawner, etc.), and during creation give each creep an "update" method that can be called from the main loop and that contains the stuff that a particular creeper should be interested in.
Problems:
- To optimize resource gathering, the spawners will need to be quite aware of
- All their room's resources
- The paths to said resources (I don't know how to extend an existing spawner object to keep this info around)
- Info on how fast a custom worker creep can travel and harvest (maybe a prototype sitting as a private const member)
- The travel time for a worker creep to travel to that resource, harvest, and travel back to drop it off (I've been stumped by this calculation for hours)
- Limited CPU
- Limited energy
I don't know how to work these into my logic. I haven't even figured out pseudocode yet that takes all these things into account, much less pseudocode that makes sense.
So many things to consider and now I'm tired. I'd appreciate feedback on how to begin automating creep construction and assignment.
- To optimize resource gathering, the spawners will need to be quite aware of
-
You should come join us on the slack channel chat.screeps.com
-
Take things a step at a time. If you try to solve every problem at once, you'll get swamped. Even those of us who have players for more than a year still have problems to solve, but we take it step-by-incremental-step.
Making spawns the brain of a room is risky - what if it gets destroyed? When you hit higher levels, each room has 3 spawners - which is the overall controller?
I would recommend you look at creating a method that runs rooms, which in turns iterates over the relevant creeps and makes them run.
wrt your problems:
- Look into the method room.find(); - this can do things like room.find(FIND_SOURCES) to gain understanding of resources.
- Pathfinding is easy to do decently. Simply call creep.moveTo(target) - this wil serve you well for a long time.
- Don't worry about calculating too many things, as some buildings will obselete your calculations. For example, a link can send energy between two points. Once you build these, how long it takes a harvester to travel is irrelevant.
- If your calculations are complex, split tasks up. Instead of one creep doing everything, have one creep do the mining, and one creep do the transporting. You will find this simplifies many matters,
- CPU is generally not an issue for early game. You start with 30CPU for one room - this is a lot!
- Energy... In the early game you shouldn't worry about this. Even a bad solution will make progress, and you can watch nearby players or bigger players to see what they do to optimize.
Automation can be started easily - one method is to use unique descriptive names, where the creep can work out its job based on its name, and the spawn logic is simply controlled by checking for existence:
if (!Game.creeps[creepName]) { // spawn creep } else { // run creep }
I have creeps with this structure - for example "E29N42_harvester_0" is a creep that harvests, is controlled by room E29N42, and works on the first source in the room.
Hope this helps! You can always try #help on the slack or poke any of us bigmouths directly.