The Challenge

The Robo Battle Pigs AI Challenge is based on the standard, two-player version of RBP. Each player provides an AI script that is evaluated each round, and the script must produce a legal set of moves for the pig. Specifically, the result of the script:

  1. must be a string containing five encoded commands, separated by spaces;
  2. must use the standard command encodings presented below;
  3. must issue one Damage(X) command for each wound suffered by the pig; and
  4. must ensure that the Repair(R) command is used correctly, which means that Repair(R) commands may only be given if all five commands are Repair(R).
The fourth rule is the only exception to the third rule; that is, if a pig has suffered n wounds and is attempting to repair itself, its command must be "R R R R R".

In order to keep the pace of the game moving, a turn limit is introduced to the game. Each challenge will have a specified turn limit.

Script Format

Your AI scripts must be written in the BeanShell language. The very last statement in your script must evaluate to a string, and this string must contain an encoding of commands that are valid for your pig. We use the standard encoding presented at the Robo Battle Pigs homepage.

There are eight variables that are set prior to your script's being executed:

x
Your pig's x-coordinate
y
Your pig's y-coordinate
health
Your pig's health
facing
The direction your pig is facing, encoded as an integer, where N=0, E=1, S=2, W=3
opponentX
Your opponent's x-coordinate
opponentY
Your opponent's y-coordinate
opponentHealth
Your opponent's health
opponentFacing
The direction your opponent is facing, encoded as above

Command Encodings

We use the standard commands and encodings presented on the Robo Battle Pigs web site, listed here for convenience. All commands are with respect to the direction the pig is facing.

"^": Forward
Move the pig one square forward.
"v": Backward
Move the pig one square backward.
"/": ForwardRight
Move the pig diagonally forward and right.
"\": ForwardLeft
Move the pig diagonally forward and left.
"TL": TurnLeft
Turn the pig to the left.
"TR": TurnRight
Turn the pig to the right.
"F": Fire
Fire a laser beam in a straight line in the direction the pig is facing.
"H": Hit
Swing the massive robo battle pig battle fist, striking the three squares in front of the pig.
"R": Repair
Repair one point of damage.
"X": Damage
Do nothing. One Damage(X) command must be issued for each point of damage suffered by the pig.

Sample Scripts

Below is a sample script for an articial intelligence that chooses random moves. (Download the script.) In fact, this is the same script that is executed if you select "Integrated AI: Random AI" in the RBP game.

String randomCommand() {
  // Math.random() returns a random double between 0 and 0.999...
  // Multiply by 8 and cast to an int, and we should have a num in [0,7].
  int n = (int)(Math.random() * 8);
  switch(n) {
    case 0: return "^ ";
    case 1: return "\\ ";
    case 2: return "/ ";
    case 3: return "TL ";
    case 4: return "TR ";
    case 5: return "v ";
    case 6: return "F ";
    case 7: return "H ";
    default: print("This should never happen.");
  }
}

// This will hold the result
String result = "";

// Make sure we have one Damage(X) command for each wound
int i;
for (i=0; i<5-health; i++)
  result += "X ";

// All other commands are random
for (; i<5; i++) 
  result += randomCommand();

// The last thing in the script must be the command string.
result;

Here is another sample script for a rather dim-witted AI that sits in one place and shoots. It turns out that this AI is rather effective against the random AI given above. Clearly, this is not a good technique in general: consider the excitement of a game where this AI is played against itself!

// This will hold the result
String result = "";

// Make sure we have one Damage(X) command for each wound
int i;
for (i=0; i<5-health; i++)
  result += "X ";

// All other commands are Fire(F)
for (; i<5; i++) 
  result += "F ";

// The last thing in the script must be the command string.
result;