JRoboWar Help
What is jRoboWar?
jRoboWar is the Java implementation of the classic game RoboWar, a computer game where you match you brains in a robot bashing contest envolving simple programing. jRoboWar is written by lucas : lucasd@dai.ed.ac.uk
Quick start...
1. Load the applet, click on "add Robot", then add to the location "robots/autosam.xml"
2. click on the robots "load" button.
3. click on "add Robot", then add to the location "robots/autofred.xml"
4. click on the second robots "load" button.
5. click on quick "battle"
How do I write a robot?
Robots currently have to be written using a plain text editor (emacs, simpletext, notepad, vi...). You must first create a robot definition file for example:
This robot can be found in the robots (autosam.xml) directory.
<?xml version="1.0" encoding='us-ascii'?> <robot> <control> <name>RoboTalkInterpretter</name> <data> <codeloc>autosam.rwcode</codeloc> <speed>15</speed> </data> </control> <name>autosam</name> <damage>1000</damage> <energy>1500</energy> <shield>500</shield> <faces> <name>_autosam</name> <url>bot4.gif</url> <x>2</x> <y>1</y> </faces> </robot>the damage energy and shield specify the robots hardware characteristics. The control section specifies how the robots is controlled. In the file specified by the codeloc section is the source code for this robot:
y recall 200 > goup godown ife x recall 200 > goleft goright ife main: random recall aim store range recall 0 > shoot ifg x recall 310 > goleft if x recall 90 < goright if random recall aim store range recall 0 > shoot ifg y recall 310 > goup if y recall 90 < godown if main jump shoot: 30 fire store main jump goup: -4 speedy store jump godown: 4 speedy store jump goleft: -4 speedx store jump goright: 4 speedx store jumpthis gives an understanding of the language, which uses the concept of a stack, each tag (text string) is either an operator, a register, a literal or a non-code element. non-code element's are the location definitions which are all strings followed by a ':' chracter. These are places the robot can jump to. literals are the numbers and the places to jump to when refered to in the code and not declared (ie when they don't have the ':' character at5 the end).
The RoboTalk Language implemented
Operators:
- "+" - adds the top two numbers on the stack, leaving the result at the top of the stack. So: "4 5 + " leaves 9 on the stack.
- "-" - subtracts the top number on the stack from the second, leaving the result at the top of the stack. So: "4 5 - " leaves -1 on the stack.
- "*" - multiplies the top two numbers on the stack, leaving the result at the top of the stack. So: "4 5 * " leaves 20 on the stack.
- "/" - divides the top number on the stack by the second, leaving the result at the top of the stack. So: "10 2 / " leaves 5 on the stack.
- "recall" - recalls the value of the register on the top of the stack. for example "range recall" returns the value of teh range register
- "jump" - jumps to the location on the top of the stack, for example "2 jump" jumps to the second instruction
- "store" - stores the second value in the stack into the top thing in the stack (should be a register), "4 aim store" sets the aim of the robot to 4 degrees.
- ">" - takes the top two things off the stack and returns 1 if the second thing is bigger than the first else 0. for example: "4 8 >" leaves 0 on the stack.
- "<" - takes the top two things off the stack and returns 1 if the second thing is smaller than the first else 0. for example: "4 8 >" leaves 1 on the stack.
- "=" - takes the top two things off the stack and returns 1 if the second thing is equal to the first else 0. for example: "4 8 >" leaves 0 on the stack.
- "not" - takes the top thing off the stack and returns 1 if it was 0 else 1. for example: "0 not" leaves 1 on the stack, and "72 not" leave 0 on the stack.
- "ifg" - takes the top two things off the stack and jumps to the location of the top thing on the stack if the second thing is not 0. For example: "1 kill ifg" jumps to the location defined by "kill:". Similarly: "0 kill ifg", doesn't and simply continues.
- "if" - takes the top two things off the stack and jumps to the location of the top thing on the stack if the second thing is not 0. For example: "1 kill ifg" jumps to the location defined by "kill:". Similarly: "0 kill ifg", doesn't and simply continues. What makes this different from ifg is that it leaves the location just after the if on the the stack, so that it can be jumped back to.
- "and" - takes the top two things off the stack and returns 1 if they are both not 0 else puts 0 on the stack. for example: "4 0 and" leaves 0 on the stack.
- "or" - takes the top two things off the stack and returns 1 if any one of them is not 0 else puts 0 on the stack. for example: "4 0 or" leaves 1 on the stack.
- "ife" - takes the top 3 things off the stack and jumps to the location of the second thing on the stack if the third thing is not 0, else it jumps to the location of the top thing. For example: "1 smile kill ife" jumps to the location defined by "smile:". Similarly: "0 smile kill ife", jumps to the location define by "kill:". like "if" it leaves the location just after the "ife" on the the stack, so that it can be jumped back to.
- "ifeg" - like ife but doesn't leave the location on the stack.
- "dup" - duplicate the top thing on the stack. so: if you had a stack of, [1,2] then you would be left with [1,1,2].
Registers:
- "aim" - is the register for the direction the robot is aiming it's gun and sensors.
- "range" - the distance to the next robot in the line of sight. 0 if can't see any robot.
- "radar" - the distance to the next bullet in the line with an angle of 40- degrees of sight. 0 if can't see any bullets.
- "fire" - used to store to to fire a bullet. for example: "10 fire store" shoots a bullet with 10 energy in it, doing 10 damage.
- "shield" can be stored to or recalled from, used to check the robots shield level and set it to a different value. Shields use energy to set.
- "x" - can only be recalled, this gets the x location (horizontal position) in the world, between 0 (left) and 400 (right).
- "y" - can only be recalled, this gets the x location (vertical position) in the world, between 0 (top) and 400(bottom).
- "random" - can only be recalled, on recall produces a random number between 0 and 364
- "speedx" - can be recalled or stored to, used to set and check the horizontal speed of the robot. Uses 2x the speed diffreence in energy.
- "speedy" - can be recalled or stored to, used to set and check the vertical speed of the robot. Uses 2x the speed diffreence in energy.
Trouble Shooting/notes/FAQ
loading a robot from the local file system can be done by specifying the file in the URL form:
file:// (path)
Note that the (path) must be absolute, and thus be in the form: "/root_level/.../robot";
If you have any questions you canemail me at: lucasd@dai.ed.ac.uk