Robo Code - The funny Java Programming Game
Well, Robocode is a game based on live combat between robots. It was developed by IBM to inspire upcoming Java programmers, and persuade them that Java can be fun. So I thought I'd have a look see what it's all about. I'll have a look later when i can get home, once I can if people are interested in this then there is the chance to program your own robots, and I will run the competitions and record all the results.
So who fancies joining in and programming some robots?
Robocode Home
Bit of fun :)
Chris
Re: Robo Code - The funny Java Programming Game
This looks cool! I've never seen this before!! Count me in :D
I'll take a better look when I'm at home too tonight.
A Java Programming Forums robot would be fun!! \:D/
Re: Robo Code - The funny Java Programming Game
I have just started installing everything for Eclipse using this tutorial:
Robocode/Developers Guide for building Robocode - RoboWiki
Gets the brain cells working! I'm going to set this up again when I get home. I'm looking forward to playing with it.
Re: Robo Code - The funny Java Programming Game
If we can get 4 people interested in this, then we could do a team battle where by 2v2 and then you create a team of robots between you? and limit the number of robots to the team to a max of 4, so it would be 4 robots vs 4 robots. But deleoped by 2v2 if that makes sense :)
Chris
Re: Robo Code - The funny Java Programming Game
ooh! i'd like to do that! I think one of our classes had us do stuff with robo code, but then the class ended and we never did anything.
Re: Robo Code - The funny Java Programming Game
Well thats 3 if JavaPF is still up for it :) give him something to do when he's board at work lol!
Chris
Re: Robo Code - The funny Java Programming Game
Seems promising. Will check this out
Re: Robo Code - The funny Java Programming Game
Glad you are interested :) Hopefully it will get somewhere. I have an idea for a team, just need someone to help me put it together muhahaha :P I have a few ideas actually lol!
Chris
Re: Robo Code - The funny Java Programming Game
hehe, now to set it up... dang, that's a long process :P
edit:
So, Robocode let's you set up a team of robots for competition, not just one. I think if we got a few more people together, we could have our own little tourney :)
Re: Robo Code - The funny Java Programming Game
lol by that do you mean setting it up to run with Eclipse? cause if not then its really simple hehe xD
But yes you can do team robots, I haven't attempted as my robots are still pathetic lol! So team is just out of the window for now.
Chris
Re: Robo Code - The funny Java Programming Game
I'm in! I well want to get this going guys. Hopefully get Eclipse setup properly asap
Re: Robo Code - The funny Java Programming Game
Awsome! Then i think we have 4!!! Which could make this fun, Eclipse doesn't take long to setup took me about 3 mins :)
I vote team picking hehe
Chris
Re: Robo Code - The funny Java Programming Game
Hehe, I might have a look at this later, looks cool :D
// Json
Re: Robo Code - The funny Java Programming Game
oooh more people :D :D
This could turn out quite nicely. Now I just need to learn Java and how to make my bot good and I can be a contender!
Chris
Re: Robo Code - The funny Java Programming Game
LOL @ now I just need to learn Java
Re: Robo Code - The funny Java Programming Game
Hehe. There are a few notes that may be helpful to you guys when setting up eclipse:
Java SDK 6 seems to work perfectly fine (they say you must use Java SDK 5). I did get a bunch of errors in the other projects, but I don't think they're used cause I can run the program no problem. (All the errors were library missing errors)
You can create a new project in Eclipse and use that to program your robots (the Robocode Editor is quite poor). It will ask you if you want to link different projects into the build path, say yes (or, manually add robocode.api).
I haven't figured out how Robocode packages the JAR files yet, but for now you can code in Eclipse, then copy/paste into the Robocode Editor.
Re: Robo Code - The funny Java Programming Game
if you go to the robocode wiki, it tells you how to set it all up. So you can fully code and compile in Eclipse. Then click run to lunch robo code, and you set the extra location for the robots you make in Eclipse, then you can just add them into battles easily.
Chris
Re: Robo Code - The funny Java Programming Game
Well just to get the ball rolling, here is a random robot lol! Normally loses, but its different and shows a few things that you can do I guess.
Code :
package cjsmith;
import robocode.AdvancedRobot;
import robocode.HitRobotEvent;
import robocode.ScannedRobotEvent;
public class RandomJoe extends AdvancedRobot {
public void run(){
turnRight(90-getHeading());
ahead(getBattleFieldWidth()/2 - (getX()-50));
turnLeft(90);
ahead(getBattleFieldHeight()/2 - (getY()-50));
while(true){
setAhead(50);
setTurnLeft(50);
setTurnGunRight(180);
execute();
}
}
public void onScannedRobot(ScannedRobotEvent sre){
stop();
if(sre.getDistance() < 100) fire(3);
if(sre.getDistance() < 200) fire(2);
else fire(1);
resume();
}
public void onHitRobot(HitRobotEvent hre){
turnRight(90-getHeading());
ahead(getBattleFieldWidth()/2 - (getX()-50));
turnLeft(90);
ahead(getBattleFieldHeight()/2 - (getY()-50));
}
}
Re: Robo Code - The funny Java Programming Game
Ok, here's what i did to install:
1. Install Java JDK (5 or newer)
2. Go here and download the latest robocode installer
3. Run the .jar file you downloaded and choose a place to install (ex: C:/Program Files/Robocode)
4. Start-up Eclipse. Follow these instructions for setting up Eclipse (i find this order works the best): *Note: This is a little different than the order they have on their website!
4a. Robocode/Eclipse/Create a Project - RoboWiki
4b. Robocode/Eclipse/Create a Robot - RoboWiki
4c. Robocode/Eclipse/Debugging Robot - RoboWiki
4c. Robocode/Add a Robot Project - RoboWiki
Have fun!
Re: Robo Code - The funny Java Programming Game
Here's my second attempt at a robot. (my first was a test bot) Still working on making the targeting account for movement :)
Code :
public class Captain extends TeamRobot
{
boolean targeting;
double trackingX;
double trackingY;
public void run ()
{
// initialize
this.setAdjustGunForRobotTurn(true);
this.setAdjustRadarForGunTurn(true);
this.setAdjustRadarForRobotTurn(true);
this.turnTo(0);
double direction = Math.PI;
targeting = false;
int count = 0;
while (true)
{
// scan for a robot
count++;
if (!targeting)
{
this.turnRadarLeft(Rules.RADAR_TURN_RATE);
}
else
{
if (count > 10)
{
count = 0;
targeting = false;
continue;
}
this.scanRegion(trackingX, trackingY, Rules.RADAR_TURN_RATE_RADIANS);
}
}
}
/**
* Track a robot and broadcast it's location to allies
*
* @param e
*/
public void trackRobot (ScannedRobotEvent e)
{
// calculate x,y coord of robot being tracked
// broadcast name, heading, (x,y), and velocity of robot
// update radar
targeting = true;
System.out.println("Tracking " + e.getName());
// calculate their x,y
double ourHeading = Math.PI / 2 - this.getHeadingRadians();
double theirHeading = Math.PI / 2 - this.getHeadingRadians() - e.getBearingRadians();
trackingX = this.getX() + e.getDistance() * Math.cos(theirHeading);
trackingY = this.getY() + e.getDistance() * Math.sin(theirHeading);
System.out.println("They are at (" + trackingX + " , " + trackingY + ")");
System.out.println("Our bearing is " + 180 * ourHeading / Math.PI);
System.out.println("Their bearing rel. is " + e.getBearing());
System.out.println("Their bearing is " + 180 * theirHeading / Math.PI);
System.out.println("Turning gun to fire...");
this.turnGunToRadians(-theirHeading + Math.PI / 2);
this.fire(1);
}
public void onScannedRobot (ScannedRobotEvent e)
{
trackRobot(e);
}
/**
* Turns the robot to a specific global degree
*
* @param deg
*/
public void turnTo (double deg)
{
while (deg >= 360)
{
deg -= 360;
}
while (deg < 0)
{
deg += 360;
}
double heading = this.getHeading();
if (deg - heading > 180)
{
// need to turn CW
this.turnRight(360 - deg - heading);
}
else
{
// need to turn CCW
this.turnLeft(heading - deg);
}
}
/**
* Turns the robot to a specific global radian
*
* @param rad
*/
public void turnToRadians (double rad)
{
while (rad >= 2 * Math.PI)
{
rad -= 2 * Math.PI;
}
while (rad < 0)
{
rad += 2 * Math.PI;
}
double heading = this.getHeadingRadians();
if (rad - heading > Math.PI)
{
// need to turn CW
this.turnRightRadians(2 * Math.PI - rad - heading);
}
else
{
// need to turn CCW
this.turnLeftRadians(heading - rad);
}
}
/**
* Scans a region with point (x,y) at the center. Maximum region radius is PI, minimum is 0
*
* @param x
* @param y
* @param arcRad
*/
public void scanRegion (double x, double y, double arcRad)
{
if (arcRad > Math.PI)
{
arcRad = .95 * Math.PI;
}
if (arcRad < 0)
{
arcRad = 0;
}
double mid;
if (x * y > 0)
{
mid = Math.atan((this.getX() - x) / (this.getY() - y));
}
else
{
mid = Math.atan((x - this.getX()) / (y - this.getY()));
}
turnRadarToRadians(mid + Math.PI - arcRad / 2);
turnRadarToRadians(mid + +Math.PI + arcRad / 2);
}
/**
* Turns the radar to a specific global position
*
* @param rad
*/
public void turnRadarToRadians (double rad)
{
while (rad >= 2 * Math.PI)
{
rad -= (2 * Math.PI);
}
while (rad < 0)
{
rad += (2 * Math.PI);
}
double heading = this.getRadarHeadingRadians();
if (rad - heading > Math.PI)
{
// need to turn CW
this.turnRadarRightRadians(2 * Math.PI - rad - heading);
}
else
{
// need to turn CCW
this.turnRadarLeftRadians(heading - rad);
}
}
/**
* Turns the gun to a specific global position
*
* @param deg
*/
public void turnGunTo (double deg)
{
while (deg >= 360)
{
deg -= 360;
}
while (deg < 0)
{
deg += 360;
}
double heading = this.getGunHeading();
if (deg - heading > Math.PI)
{
// need to turn CW
this.turnGunRight(360 - deg - heading);
}
else
{
// need to turn CCW
this.turnGunLeft(heading - deg);
}
}
/**
* Turns the gun to a specific global position
*
* @param rad
*/
public void turnGunToRadians (double rad)
{
while (rad >= 2 * Math.PI)
{
rad -= (2 * Math.PI);
}
while (rad < 0)
{
rad += (2 * Math.PI);
}
double heading = this.getGunHeadingRadians();
if (rad - heading > Math.PI)
{
// need to turn CW
this.turnGunRightRadians(2 * Math.PI - rad - heading);
}
else
{
// need to turn CCW
this.turnGunLeftRadians(heading - rad);
}
}
}
Re: Robo Code - The funny Java Programming Game
Sounds cool, I was actually looking for such games.
But now... I don`t know if I know enough Java...
I`ll try it anyway ...
At last ! A cool game, which is not time-wasting ! :)