Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily adding objects/structures to test world #6

Open
brisberg opened this issue Feb 12, 2020 · 6 comments
Open

Easily adding objects/structures to test world #6

brisberg opened this issue Feb 12, 2020 · 6 comments

Comments

@brisberg
Copy link
Contributor

First of all, thanks for taking over this project and moving it to the Screepers group. I was bummed that Integration testing didn't work out of the box a few months ago, so I am happy to have it back!

Anyways, my question is asking if there is an easy, out-of-the-box way to add Game Objects and Structures to the test world to set up realistic, repeatable scenarios.

From the samples, you can add a structure (a Spawn in this case) by directly executing a database update:

db['rooms.objects'].insert({
  room, type: 'spawn', x, y, user: user._id, name: spawnName,
  store : { energy: C.SPAWN_ENERGY_START },
  storeCapacityResource: { energy: C.SPAWN_ENERGY_CAPACITY },
  hits: C.SPAWN_HITS, hitsMax: C.SPAWN_HITS, spawning: null, notifyWhenAttacked: true
})

Not all of these fields are technically required (simply adding type, room, x,y, and user will add a Spawn Structure with no storage), but all of these fields are required to create a Spawn structure that behaves exactly like a Spawn Structure on live.


Is there a set of convenience methods on any of the Screeps projects to add structures/creeps as they exist on live?

If not, do you think this project would be a reasonable place to put such wrappers? That way they could be updated whenever the Screeps version is updated.

I am willing to put up a PR with these methods, if you guys think this would be a good place for them.

@Hiryus
Copy link
Collaborator

Hiryus commented Feb 12, 2020

When I wrote it, I was thinking about placing these kind of methods in src/world.js.

As a start, you have addRoomObject() which is quite generic but still more abstract than manipulating database directly. You can see some examples in world.tests.js but I don't think I ever used it for owned creeps or structures.

If needed, it should be fairly easy (but quite time consuming) to implement more specific methods on top of it. The file grew up quite fast though, it may be better to split these functions into another one.

I leave it to @pyrodogg for final decision.

@brisberg
Copy link
Contributor Author

Thanks for the reply, I agree addRoomObject() is the better base abstraction on which to start.

I don't mind implementing the specific methods. As it is I am already slated to write them for my own project because I feel it is necessary to write readable tests. Adding them to src/world.js or src/roomObjects.js etc sounds fine.

Just let me know your or @pyrodogg's preference.

@pyrodogg
Copy link
Member

Its been on my mind to add more convenience functions for mocking room scenarios. Also, documentation and examples for how to use them.

Putting it in something like src/roomObject.js sounds good to start. If needed later, it could be broken up in even more detail.

@brisberg
Copy link
Contributor Author

Sounds good! I'll give it a try this weekend and open a PR with a first attempt.

@eduter
Copy link

eduter commented Feb 13, 2020

I don't mind implementing the specific methods. As it is I am already slated to write them for my own project because I feel it is necessary to write readable tests.

@brisberg if you manage to write readable tests using the mock server, I think it would be great if you published some examples of that, like I did with unit tests, using Jest. I can't really picture how these tests would look like and what's the benefit of using them, instead of unit tests. I'd love to see some concrete examples.

@brisberg
Copy link
Contributor Author

brisberg commented Feb 14, 2020

@eduter Good idea, I'll definitely publish what I come up with. Just looked over your jest integration and it looks really good! I'll definitely make use of it for my unit testing.

I am hoping that these tests will be broad enough that they give confidence that your AI can accomplish a very broad task. I am imagining things like: "Given an operating RCL4 Colony, Harvest energy from a remote room", "Given a storage full of energy, a set of creeps, and a handful of construction sites, Build all of the sites", "Given a spawn/extension set, a Creep, and a Storage full of energy, Fill all of the Spawns/Extensions".

Hopefully these tests are mostly AI independent, so that you do not need to update them often, even with drastic changes to the AI. You can also set performance limits (CPU usage, Energy harvested / tick, number of ticks to distribute, etc) and ensure that your changes do not reduce efficiency in other aspects.

Also Combat Scenarios would be very useful. See if your squads of units can defeat other squads of units, base can defend a drain attack, etc. These kinds of multi-tick engagements would be very difficult to Unit test effectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants