Added README
This commit is contained in:
parent
89fe594e3b
commit
bbe71b4587
2 changed files with 125 additions and 51 deletions
120
README.md
120
README.md
|
|
@ -1,56 +1,74 @@
|
|||
# Creeps.
|
||||
# Creeps
|
||||
|
||||
## Brief
|
||||
> **Note** This is a school project, therefore it probably won't interest you if you are looking for something useful.
|
||||
|
||||
This document is a quick overview of the creeps given files.
|
||||
## Overview
|
||||
|
||||
## What's in the archive
|
||||
|
||||
In the provided archive you will find the following files:
|
||||
|
||||
* `README.md`: this file.
|
||||
* `pom.xml`: the sample maven project file that you must use for your project.
|
||||
* `creeps-server.jar`: the server, for you to train on.
|
||||
* `given.jar`: a compiled java library to help you in your endeavor.
|
||||
* `given-javadoc.jar`: given library documentation, can be extracted with `jar xf`.
|
||||
|
||||
## Installing the given jar to your local repository
|
||||
|
||||
* Make sure the folder `~/.m2/repository/` exists, if not create it
|
||||
(assuming you have built maven projects before, the folder should already
|
||||
exist).
|
||||
* Run the command `mvn install:install-file -Dfile=given.jar -DgroupId=com.epita -DartifactId=given -Dversion=4.0-SNAPSHOT -Dpackaging=jar`.
|
||||
* You should be good to use the provided pom.xml file.
|
||||
|
||||
In case the assistants publish a new version of the file, simply repeat the process again.
|
||||
|
||||
### First run:
|
||||
|
||||
`java -jar creeps-server.jar --printAchievements=true` will print
|
||||
the list of all achievements you can get.
|
||||
|
||||
### Tutorial:
|
||||
|
||||
`java -jar creeps-server.jar --trackAchievements=true --enableEnemies=false --enableGC=false --citizenFeedingRate=100000`
|
||||
starts the server without enemies, without Hector and without starvation.
|
||||
Ideal for early development.
|
||||
|
||||
### The game, standard configuration:
|
||||
|
||||
`java -jar creeps-server.jar --trackAchievements=true`
|
||||
starts the server with the setup that will be used on the live server.
|
||||
|
||||
## Web client
|
||||
|
||||
The web client is enabled by default when running the local server.
|
||||
To use it, you have to connect to `http://localhost:port` where port is
|
||||
either 1337 by default or the value of the -httpPort option given to the
|
||||
server.
|
||||
|
||||
## Documentation
|
||||
|
||||
The documentation is generated using Javadoc.
|
||||
To use it, you can extract `given-javadoc.jar` with `jar xf`.
|
||||
You can then open the `index.html` file using any web browser.
|
||||
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**.
|
||||
|
||||
|
||||
## Game rules
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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 !
|
||||
|
||||
## My approach
|
||||
|
||||
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)
|
||||
|
||||
// Create a new player
|
||||
String login = "Mr President"
|
||||
InitResponse initResponse = Basics.connectAccount(login);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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();
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
// 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) {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 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 !
|
||||
|
||||
```
|
||||
|
||||
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.
|
||||
|
|
|
|||
56
given-readme.md
Normal file
56
given-readme.md
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# Creeps.
|
||||
|
||||
## Brief
|
||||
|
||||
This document is a quick overview of the creeps given files.
|
||||
|
||||
## What's in the archive
|
||||
|
||||
In the provided archive you will find the following files:
|
||||
|
||||
* `README.md`: this file.
|
||||
* `pom.xml`: the sample maven project file that you must use for your project.
|
||||
* `creeps-server.jar`: the server, for you to train on.
|
||||
* `given.jar`: a compiled java library to help you in your endeavor.
|
||||
* `given-javadoc.jar`: given library documentation, can be extracted with `jar xf`.
|
||||
|
||||
## Installing the given jar to your local repository
|
||||
|
||||
* Make sure the folder `~/.m2/repository/` exists, if not create it
|
||||
(assuming you have built maven projects before, the folder should already
|
||||
exist).
|
||||
* Run the command `mvn install:install-file -Dfile=given.jar -DgroupId=com.epita -DartifactId=given -Dversion=4.0-SNAPSHOT -Dpackaging=jar`.
|
||||
* You should be good to use the provided pom.xml file.
|
||||
|
||||
In case the assistants publish a new version of the file, simply repeat the process again.
|
||||
|
||||
### First run:
|
||||
|
||||
`java -jar creeps-server.jar --printAchievements=true` will print
|
||||
the list of all achievements you can get.
|
||||
|
||||
### Tutorial:
|
||||
|
||||
`java -jar creeps-server.jar --trackAchievements=true --enableEnemies=false --enableGC=false --citizenFeedingRate=100000`
|
||||
starts the server without enemies, without Hector and without starvation.
|
||||
Ideal for early development.
|
||||
|
||||
### The game, standard configuration:
|
||||
|
||||
`java -jar creeps-server.jar --trackAchievements=true`
|
||||
starts the server with the setup that will be used on the live server.
|
||||
|
||||
## Web client
|
||||
|
||||
The web client is enabled by default when running the local server.
|
||||
To use it, you have to connect to `http://localhost:port` where port is
|
||||
either 1337 by default or the value of the -httpPort option given to the
|
||||
server.
|
||||
|
||||
## Documentation
|
||||
|
||||
The documentation is generated using Javadoc.
|
||||
To use it, you can extract `given-javadoc.jar` with `jar xf`.
|
||||
You can then open the `index.html` file using any web browser.
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue