Table of contents:
1. The basics of a Peril AI
In peril the AIs all fundementally function the same way. Each round they observe the state of the game and act based on that information. They do not remmeber previous states of the game. This allows each AI to play for multiple players simultaneously.
There are three distinct actions every AI must perform:
- Reinforce
- Attack
- Fortify
The following optional operations can be performed at any point during those three actions:
- Buying blockades
- Upgrading units
AIs query the
AIController
to gather information about the game. Any information obtained from
any other source is illegal.
2. Setting up your AI
Follow these steps to setting up your own AI class.
- Open the
Peril.jar
file in a achriver such as winrar. - Extract
peril/ai
folder to your computer. - Create a new
<ai name>.java
file insideperil.ai
(The file name is you AI's name). - The java class should look like this...
- Add the Logic for each operation. Details of each operation can be found here: Peril AI API. In specific the documentation for the methods your AI implements.
package peril.ai;
import peril.ai.api.*;
public final class <ai name> extends AI{
public <ai name>(AIController api){
super("<ai name>", MAX_SPEED, api);
}
@Override
protected AIOperation processReinforce(AIController api) {
final AIOperation operation = new AIOperation();
// Reinforce logic here
return operation;
}
@Override
protected AIOperation processAttack(AIController api) {
final AIOperation operation = new AIOperation();
// Attack logic here
return operation;
}
@Override
protected AIOperation processFortify(AIController api) {
final AIOperation operation = new AIOperation();
// Fortify logic here
return operation;
}
}
3. Importing your AI
Follow these steps to import your custom AI into Peril.
- Compile your
<ai name>.java
file to get the<ai name>.class
- Open the
Peril.jar
file in a achriver such as winrar. - Copy the
<ai name>.class
back into theperil/ai
inside thePeril.jar
file. - Close the
Peril.jar
file the open it again this time usingJava
. This should open Peril. - Set up a new game and set the players you want to be your
AI
to control with with the AI asNone
. - Load the game.
- At the earliest point possible, pause the game.
- Save the game into one of the save slots, remember which slot.
- Open the
assets/maps/<map name>/
folder. - Open the save
.txt
file. - Near the top of the file there should be this...
... Unit,Car,5,carIcon.png Unit,Tank,15,tankIcon.png Player,1,Hard,2,0,0,0,true,0 Player,3,Medium,0,0,0,0,true,0 Player,4,None,0,0,0,0,true,0 Player,2,Easy,0,0,0,0,true,0 State,Reinforce,1,0 Country,Ural,000200150,Soldier:1,-20,20,2 Country,India,050000050,Soldier:1,0,0,3 ...
- Replace the
None
with your<ai name>
and save the file. - Launch Peril.
- Load that modified game save and your AI should be in the game as the player(s) to set it to control.