Code Wars
About Me
Site Stats

Kit Car

Geek Stuff
3D Scanning
Code Wars
R2 Vis
R4 Vis

Contact Me

  Rules and stuff you should know...
The code for the robots is written as if it were running on a very simple RISC (Reduced instruction set) computer. Every instruction in the code takes up one clock 'tick', even moving and firing (this may change later - seems a bit unfair). The Virtual Machine the program runs on uses just integer values, and has a 512 deep stack, as well as 512 different memory registers and enough memory to store 512 instructions. For a simple robot like these it should be more than enough.

Since the Robot's virtual machine runs very slowly, it does actually pay not to have it think too much. Its often a good idea to code in quick reactions, like to have the robot fire off a few missiles, then dodge.

You are able to choose what you put on each of the 4 sides of your robot. You can either put nothing, a shield, an eye or a gun. The shield helps protect from missile blasts, but it weighs more (this doesn't matter at the moment, but if may effect the speed the robot moves later on). The eye allows the robot to 'see' - when used, it looks in a straight line in the direction it is facing, and returns 2 values, the distance away of the nearest object (0=adjacent), and a number saying what it is.

When a robot fires a missile, it moves at one square a 'tick', the same speed as moving the robot. If a missile hits a Robot it causes a certain amount of damage. At the moment the default damage is 10 (the 'health' of the robot at the start is 100). However it depends on what it hits. On a side with nothing or a gun, damage 10 is caused, on a side with an eye, it is doubled, and on a side with a shield, it is halved.
  Making a robot...
The applet that shows the robots fighting actually displays some debug info and errors to the console, hence if you're developing a robot, you'll want the Java console open or something. While most of the time the assembler will assemble code with problems, it kindof bodges up values and things, which almost certainly isn't what you want.

For the next bit, its an idea to have a copy of the enemy bot that you can look at. This is just a simple bot that I used to test out the code... I may well write an addition to the site (or maybe some else wants to ;) that allows you to edit a bot online, click a button and have it fight against another bot. Until then however, you'll have to download the Java source and binaries, and run your robot from there.

First thing you'll notice is loads of comments, which start with '//' like Java. You'll find comments are very handy, since the assembler isn't exactly easily understandable... the top section contains a load of DEFINE statements. These allow you to create a constant with the given value. You have to use this to set up some aspects of your robot, and you can also create constants for your own use.

DEFINE RCOLORB and RCOLORF are pretty pointless really. They set the color of your robot. the first is the background color, the second is the color of the edges and the image foreground. To get the value you have to use the formula (Red*65536)+(Green*256)+Blue because I haven't put and hexadecimal or binary support in :( Again, if anyone feels like doing so...

DEFINE RIMG0..7 are again pointless. These make up the image, this time in binary. To work out what the image is, you'd do something like this :
128	64	32	16	8	4	2	1	RIMG#
1	1	1	1	1	1	1	1	255
1	0	0	0	0	0	0	1	129
1	1	1	1	1	1	1	1	255
1	0	0	0	0	0	0	1	129
1	0	0	0	0	0	0	1	129
1	1	1	1	1	1	1	1	255
1	0	0	0	0	0	0	1	129
1	1	1	1	1	1	1	1	255

DEFINE RSIDE1..4 is finally something useful. This allows you to select what you want on each side of your robot. 1 is the front, 2 is the right, 3 is back, and 4 left. you can either have SDNONE,SDSHIELD,SDEYE or SDGUN.

DEFINE OBJDIST,64 is something the program itself uses. This defines a constant called OBJDIST with the value 64. This is a bit of a pain, because the assembler is dumb as hell. Basically, OBJDIST is meant to be an index into memory register 64, not the number 64. It all depends how its used as to what the computer interprets it as, so be warned :)

Next we actually get onto the start of the code. The part before the colon is a label. This creates a constant (like by DEFINE) that has the position in the program in it. Be warned that this, again, can be used as a number or even an index to a memory register. In this case, Start contains the value 0, because it is right at the start of the program.

Next, there is the OpCode. This is the name of the instruction in the virtual machine. Each opcode consists of the name of the instruction, an underscore (even if there are no parameters), and a letter for each parameter that is required. R stands for register, and so if 5 were used as the parameter, the value in memory register number 5 would be accessed. This is what OBJDIST was meant to be used as. The second type of parameter, L stands for Literal, this means use the number for what it is. For instance, 5 will actually mean 5. This is what Start is Meant to be used as.

The MOV_RL command takes the value in the second parameter and moves it into the first. Now, the way in which the virtual machine in the Robot tells it to do stuff is by memory-mapping. Basically, the end few memory registers (511,510,509,508) are used to talk to the robot. Accessing the command register PCOMMAND and putting the value CMUSE2 in it tells the robot to use whatever is on its second side. In this case, an eye. The robot then puts the result in some other registers. For the eye, the distance of the object is put in register PPARAM1 and the type of object in PPARAM2.

The commands you can use are :
MOV_RL PCOMMAND,CMLEFT Turn left 90 degrees
MOV_RL PCOMMAND,CMRIGHT Turn right 90 degrees
MOV_RL PCOMMAND,CMMOVE Move Forward one step
MOV_RL PCOMMAND,CMUSE1..4 Use whatever is on that side. for guns, fire and put the free ammo in PPARAM1, for eyes, see the description above.
MOV_RL PCOMMAND,CMRANDOM Put a random number between 0 and PPARAM1 into PPARAM1 - useful for decision-making (no... really)
MOV_RL PCOMMAND,CMSTATUS PPARAM1=Health; PPARAM1=1 if hit, 0 otherwise; PPARAM3=Free Ammo

There's some extra info for using the eyes... PPARAM2 contains what the object found was. This is either LOPEN,LROCK,LAMMO,LHEALTH,LROBOT or LMISSILE.

What follows is a list of OpCodes and what they're used for. If anyone wants to provide any more data, feel free :) The number after each one is the opcode number. This isn't really much use, 'cept I ripped them out of the java code and it was in there. Also i've used Java notation for some things. It should be pretty self explanatory...

NOP_ = 0;
Do Nothing

END_ = 1;
End the program

GOTO_L = 2;
Goto program step (0)

CALL_L = 3;
Goto program step (0) and save current step on the stack

RETURN_ = 4;
Go to the program step that is on the stack

SE_RL = 5;
Skip next instruction if (0)=(1)

SNE_RL = 6;
Skip next instruction if (0)<>(1)

SLT_RL = 7;
Skip next instruction if (0)<(1)

SGT_RL = 8;
Skip next instruction if (0)>(1)

SE_RR = 9;
Skip next instruction if (0)=(1)

SNE_RR = 10;
Skip next instruction if (0)<>(1)

SLT_RR = 11;
Skip next instruction if (0)<(1)

SGT_RR = 12;
Skip next instruction if (0)>(1)

MOV_RL = 13;
(0) = (1)

MOV_RR = 14;
(0) = (1)

SWAP_RR = 15;
(0) <-> (1) - Swaps contents of first and second registers

CLR_R = 16;
(0) = 0

PUSH_R = 17;
Pushes (0) onto the stack

PUSH_L = 18;
Pushes (0) onto the stack

POP_R = 19;
Pops the top of the stack into (0)

ADD_RR = 20;
(0) += (1)

ADD_RL = 21;
(0) += (1)

SUB_RR = 22;
(0) -= (1)

NEG_R = 23;
(0) = -(0)

SHL_RL = 24;
(0) = (0) << (1)

SHR_RL = 25;
(0) = (0) >> (1)

MUL_RR = 26;
(0) *= (1)

MUL_RL = 27;
(0) *= (1)

DIV_RR = 28;
(0) /= (1)

DIV_RL = 29;
(0) /= (1)

Thats it, kindof. Have fun ;)
Created by and Copyright (c) Gordon Williams 2003