RoboCode Tutorial
Cholwich Nattee
School of ICT, SIIT, TU
What is RoboCode?
RoboCode is a programming game. Goal: to create a robot to compete in a battle eld.
A Robot
A Robot (3636 pixels) = Body + Gun + Radar Body for moving itself Gun for ring energy bullets Radar for detecting other robots
Game Physics: Battle Field
Cartesian coordinate system: (0,0) at the bottom left Clockwise direction: 0 degree towards North
(0,h)
0 deg
(w,h)
270 deg
90 deg
(0,0)
180 deg
(w,0)
Creating Your First Robot
A Robot = A Java Class extending Robot Robot
MyRobot
Creating Your First Robot
import robocode.*; public class MyRobot extends Robot { public void run() { while(true) { ahead(100); turnGunRight(360); } } public void onScannedRobot(ScannedRobotEvent e) { fire(1); } }
Game Physics: Time/Dist.
Time: 1 turn = 1 tick, 1 tick depends on TPS Acceleration: 1 pixel/turn for accelerating, 2 pixel/turn for decelerating Velocity: velocity = accelerationtime Distance: distance = velocitytime; measured in pixels
Robot Movement
ahead(double distance) move forward for a specied distance back(double distance) move backward for a specied distance
Rotation
Body Rotation turnLeft(double deg) / turnRight(double deg) Gun Rotation turnGunLeft(double deg) / turnGunRight(double deg) Radar Rotation turnRadarLeft(double deg) / turnRadarRight(double deg)
Game Physics: Rotation
Body rotation: 10 - 0.75abs(velocity) deg/turn Gun rotation: 20 + body_rotation deg/turn Radar rotation: 45 + gun_rotation deg/turn
Bullet
re(double power) re a bullet with a specied power reBullet(double power) re a bullet with a specied power return an object of class Bullet
Game Physics: Bullets
Damage: 4repower+[2(repower-1) if repower>1] Velocity: 20-3repower GunHeat: 1+repower/5 The gun does not work if GunHeat > 0 GunHeat is decreased by GunCoolingRate per turn Power returned on hit: 3repower
Game Physics: Collisions
With Another Robot: Each robot takes 0.6 damage With Wall 0 for Robot max(abs(velocity)*0.5-1,0) for AdvancedRobot
AdvancedRobot
More methods to control your robot AdvancedRobot
MyRobot
Detectable Events
onBulletHit onBulletHitBullet onBulletMissed onDeath onHitByBullet onHitRobot onHitWall onRobotDeath onStatus onWin
Our Rule
Initial Energy = 100 Battle Field = 800600 Gun Cooling Rate = 0.1
Our Tournament
Qualiying Round - Round-robin with all teams Win = 2, Draw=1, Loss=0 3 games per match Final Round Knock-out 7 games per match