# Robo Duel Instructions

## Code a mighty dueling robot!

• Robots are programmed with a script that they execute again and again in a loop
• You can name and save your robots and fight them against your friends' robots

### Each robot understands the following commands

• move: moves the robot forward
• right: turns the robot clockwise by 1/3 of a degree
• left: turns the robot counter-clockwise by 1/3 of a degree
• idle: does nothing
• fire: fires a missile
• set: sets a variable to a value. The command `set num:5` will define a variable named num and store the value 5 for later use.
• locateSelf: loads its position and direction into memory as x, y and dir (see examples below)
• locateEnemy: loads enemy's position and direction into memory as ex, ey and edir (see examples below)

### Robocode has the following features:

check: checks some condition and then does one thing if it's true or another thing if it's not true.

``````locateSelf
check (dir > 180)
yes:fire
no:right
``````

The above block of code will do the following:

1. Run locate self, which sets x to the robot's current x position, y to its current y position and dir to its current direction (in degrees). Later commands can now use x, y and dir.
2. check to see if the direction it's pointing towards is > 180 degrees (i.e. downward)
3. If it's pointing downward, it will fire
4. Otherwise the robot will turn clockwise.

do: Do starts a loop of commands. It's useful with check.

``````check (something = someotherthing)
yes: do (fire fire fire fire)
no: do (left move)
``````

The above code will check some condition, and if it's true the robots next four actions will be to fire. If not, the robot will turn left and move.

### Logical conjuctions: "and", "or"

Some condition and some other condition will return true only if both conditions are true.
Some condition or some other condition will return true if either of them are true.

``````locateEnemy
check (edir > 170 and edir < 190)
yes: move
no: idle
``````

is the same as...

``````locateEnemy
check (edir > 170)
yes: check (edir < 190)
yes: move
no: idle
no: idle
``````

Both of the above snippets will load in the enemy's location and direction and then fire only if the enemy is pointing almost straight up. The execution is the same, but code with ands or ors is much more readable than nested check statements.

### Mathematical operators in RoboCode

The basic operations are available + - * / for addition, subtraction, multiplication and division. You can also use % for modulous (getting the remainder of a division answer). For example 10 % 3 will return 1 since one is the remainder of 10 / 3.

The order of operations is the same as in arithmetic (multiplication before addition, etc...) and you can use parenthesis to change the order.
`1 + 2 * 4 == 9`
However...
`(1 + 2) * 4 == 12`