More on Robocode Home PageRobocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java or .NET. The robot battles are running in real-time and on-screen.
Instalation:
1) Load Java 6 .sfs or better (i've loaded jre-1.8.0.05.sfs on my Slacko 7.0)
2) Click on robocode-1.9.3.3-setup.jar (download)
3) Choose directory to install.
4) To run click on robocode.sh in /yourpath/robocode or in terminal:
Code: Select all
/yourpath/robocode/robocode.sh
1) Battle/New
2) Packages/Sample, Robots/Crazy and Robots/SpinBot
3) Start Battle
Picture 1
II. Now we make own bot:
1) Robot/Source Editor
2) File/New/Robot
3) Enter Name for your bot
4) Enter Package Name for your bot
You will see template code for your bot.
Picture 2
Code: Select all
package Puppy;
import robocode.*;
//import java.awt.Color;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
* Puppy_Apprentice - a robot by (your name here)
*/
public class Puppy_Apprentice extends Robot
{
/**
* run: Puppy_Apprentice's default behavior
*/
public void run() {
// Initialization of the robot should be put here
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
// setColors(Color.red,Color.blue,Color.green); // body,gun,radar
// Robot main loop
while(true) {
// Replace the next 4 lines with any behavior you would like
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
fire(1);
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
back(10);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
back(20);
}
}
Picture 3
Code: Select all
package Puppy;
import robocode.*;
import java.awt.Color;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
* Puppy_Apprentice - a robot by (your name here)
*/
public class Puppy_Apprentice extends Robot
{
/**
* run: Puppy_Apprentice's default behavior
*/
public void run() {
// Initialization of the robot should be put here
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
setColors(Color.black,Color.black,Color.gray); // body,gun,radar
// Robot main loop
while(true) {
// Replace the next 4 lines with any behavior you would like
ahead(200);
turnRight(90);
turnGunLeft(360);
ahead(200);
turnLeft(90);
turnGunRight(360);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
fire(1);
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
back(50);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
turnRight(90);
back(50);
}
}
So in Source Editor choose Compiler/Preferences and change -version in Compiler Options field into -showversion.
Picture 4
Now choose Compiler/Compile.
To assign your bot to battle look at point I.
Picture 5
After battle you will get some statistics.
Picture 6
Build the best, destroy the rest!