User:AW/guideToRobocode
Contents
The rules of the game
In robocode 1v1, there are two robots fighting on a 600 by 800 pixel battlefield. Pixels are measured from the bottom left, as in a Cartesian coordinate system. Each robot starts with a certain amount of energy (usually 100 energy). When the energy runs out, the robot dies. The objective is to destroy the enemy by as large a margin as possible.
To do this, robots have certain:
Abilities
- Move forwards or backwards at up to 8 pixels per turn (a turn in robocode is also called a tick)
- Accelerate at up to 1 pixel per turn squared
- Deccelerate at up to 2 pixels per turn squared
- Turn their body at up to (10 - 0.75 * abs(velocity)) degrees peer turn and get their orientation (relative to "north" on the battle field, going clockwise like a compass.)
- Turn their gun at up to 15 degrees per turn and get their gun's orientation relative to the body of the tank
- Turn their radar at up to 45 degrees per turn and get the radar's orientation
- Fire bullets ranging with powers ranging from 0.1 to 3.0
- Firing bullets creates gun heat of 1 + firePower / 5.0; if gunHeat > 0, the robot cannot fire.
- A robot's hit box is a non-rotating square. Each side is 36 pixels in length.
Bullets
- Firing a bullet costs energy equal to the power of the bullet;
- A bullet has a velocity of 20 - 3 * bulletPower;
- When a bullet hits, it does 4 * firePower damage to an enemy robot if firePower < 1;
- if firePower >= 1 the bullet does 4 * firepower + 2 * (firePower - 1). You cannot be hit by your own bullets.
- When a bullet hits an enemy, the firing robot receives a bonus in energy of 3 * bulletPower.
- When two bullets collide, both of them are destroyed.
- When a bullet hits the wall, it is destroyed.
Radar
A robot can receive the following information about his enemy via radar:
- Enemy's heading (the heading is the direction the robot is facing, this is measured from );
- Enemy's distance;
- Enemy's bearing (the angle from our heading to the enemy);
- Enemy's speed;
- Enemy's energy;
Robot collisions
- If a robot hits a wall, the robot stops instantly and takes damage equal to abs(velocity) * 0.5 - 1 if abs(velocity) > 2.0
- If a robot hits another robot, it takes 0.6 damage and instantly stops if it is moving towards the other robot.
And one final bit of details:
Robocode Processing Loop
The order that Robocode runs is as follows:
- Battle view is (re)painted.
- All robots execute their code until they take action (and then paused).
- Time is updated (time = time + 1).
- All bullets move and check for collisions. This includes firing bullets.
- All robots move (gun, radar, heading, acceleration, velocity, distance, in that order).
- All robots perform scans (and collect team messages).
- All robots are resumed to take new action.
- Each robot processes its event queue.
That's it. You now know how robocode works. If you ever need to refresh your memory, you can go to the Physics page.
Strategy
Given the above abilities, how do you destroy the other robot? Over the years, several techniques have developed.
Here are the key concepts:
Waves
You may have noticed above that the list of things your radar can detect does not include bullets. This is part of what makes robocode so interesting. Because firing costs energy and you can detect the enemy's energy, you can tell when they fired and what power bullet they shot. With the power, you can find the velocity of the bullet, and because you can find the location of the enemy robot, you know where the bullet was fired from. Therefore you have three pieces of information: 1) Where the bullet was fired from. 2) How fast it is going. 3) How long it has been moving.
From these, you can find a circle that contains the set of possible positions of a bullet. The radius of this circle increases each turn (tick). This "object" (the circle of increasing radius that contains all possible points where a bullet can be) is called a wave. Whenever you fire, you too create a wave of possible points your bullet could be. Of course you know what angle you used so you know where the bullet is, but the wave shows all points where the bullet could have been.
For a detailed article, see Waves.
Guess Factors
Give information from GF
Waves and guess factors are at the core of top robots.