creeps/README.md

75 lines
4.3 KiB
Markdown
Raw Normal View History

2026-05-13 22:37:42 +02:00
# Creeps
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
> **Note** This is a school project, therefore it probably won't interest you if you are looking for something useful.
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
## Overview
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
The goal of the creeps rush was to create an autonomous bot that could play the strategy/sandbox game of the same name without player interaction.
It was written in Java in approxiamtely **one day**.
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
## Game rules
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
The games is accessible as a server via a REST API.
The particularity is that the API has some cooldown between each interaction you do with it. Also you have multiple citizens to control, therefore I had to implement it smartly using Java's CompletableFutures to control them asynchronously.
**All the async logic is hidden** behind a layer so you can control them seamlessly without worrying about these limitations.
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
When you first appear on the map, the goal is to gather a maxiumum of resources, to do so the Cartographer module is quite helpful to retrieve their locations.
As you collect them, you have to place paths behind you to not be killed by Hector, which is the name given to the ClearLag like routine that kills every entity too far from home orany path.
After some time, enemies will appear and target you, you must then use your resources to build defenses: walls, turrets and attack units... but without forgetting to grow your town by building more structures to keep the pace.
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
The notation was about achievements: basically you could push your code on the official server and watch it play by itself. The more achievements you won in total, the more points you have !
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
## My approach
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
I spent most of my time making classes that would abstract all the hard work from the main algorithm.
So the main program could look something like this without even having to worry about anything related to the game interface:
```java
// Everything is done asynchronously whenever possible (like moving multiple citizens)
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// Create a new player
String login = "Mr President"
InitResponse initResponse = Basics.connectAccount(login);
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// Add the first two citizens to our units
Citizen citizen1 = new Citizen(login, initResponse.citizen1Id, initResponse.householdCoordinates);
Citizen citizen2 = new Citizen(login, initResponse.citizen2Id, initResponse.householdCoordinates);
Unit.getUnits().add(citizen1);
Unit.getUnits().add(citizen2);
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// Make our citizens move, build structures and collect resources
citizen1.move(Direction.UP);
citizen2.move(Direction.DOWN); // Done at the same time as the previous line
citizen1.build(Building.ROAD); // Will be done after the previous citizen1 action ends and the API timer cools down
citizen1.build(Building.ROAD);
citizen1.gather(); // Attempts to gather a resource on the actual tile
citizen2.gather();
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// Spawn a Bomber Bot
citizen1.spawn("bomber-bot").waitFinished(); // Waits for this action to finish before doing anything else
List<Unit> bombers = BomberBot.getBomberBotUnits(); // List bomber units
BomberBot bomberbot1 = (BomberBot) bombers.getFirst(); // Get the first bomber
// Increase the bomber bot level
bomberbot1.upgrade();
// Make it explode (will actually explode the village and the other citizens but nevermind)
bomberbot1.fire();
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// You can even message other players (still asynchronously !!)
citizen1.fetchMessages(); // Retrieves messages from other players
StatisticsResponse statistics = Basics.getStatistics(); // Retrives player list (among other statistics)
for (var player : statistics.players) {
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
if ((player.name.contains("Maduro") )) {
citizen2.sendMessage(player.name, "Hey Nicolas, give back my oil !"); // Sends a message to any player containing "Maduro" in its name
}
}
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
// And many more: turrets, buildings, map integration...
// You can use all of that to plan any strategy you want without ever having to move a player yourself !
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
```
2026-02-06 11:50:00 +01:00
2026-05-13 22:37:42 +02:00
You can find the units objects inside `src/main/java/com/epita/creeps/units`, and global commands under `src/main/java/com/epita/creeps/commands`. The main algorithm is itself located at `src/main/java/com/epita/creeps/Program.java` with some other utilities like the asynchronous execution module (`AsyncExec.java`) and the ServerResponseException class.
Most given files are not included in this repo as some of them are quite heavy or not really relevant. But I plan to find a way to easily access them from here, it's just not a priority for now.