Sample Code: Making Robots in Java (JRobot)

By Angsuman Chakraborty, Gaea News Network
Thursday, April 20, 2006

JRobotsI talked about JRobots, an extremely addictive Java game where you develop robots in java to fight against other JRobots in a monthly battle royale. Today I will present you with a simple sample JRobot to encourage you to participate in this contest. It kicks the butt of all sample JRobots provided in the download bundle and even some veterans.

JRobots developers are hesitant to provide actual code because of two reasons;
1. It will lead to proliferation of copy-cat JRobots with a different name which are just a waste of time for all.
2. Nobody likes to reveal their secrets ;)

I have considered them over the years. I have come to the conclusion that the benefits of providing simple code for developers to begin with far outweighs other concerns. So here is a simple JRobot which despite its simplicity can really kick butt of many JRobots. It was initially released as CounterStrike. However now the CounterStrike code is slightly more sophisticated. So I am releasing this JRobot named Simple.


public class __Simple_ extends JJRobot {
    void main() {
        int distance, angle = 0;
        while (true) {
            while((distance = scan(angle, 1)) == 0) angle++;
            cannon(angle, distance);
            drive(angle, 100);
        }
    }
}

Download the source here.

You can see how easy it is to start coding JRobots. What are you waiting for?

See you in the arena. My JRobots are Bizarro, Janeway, Shrike and CounterStrike.

Discussion
June 10, 2010: 10:33 pm

thx for the tutorial


Nitin
August 10, 2009: 12:57 pm

hi,
Myself Nitin Harane.I just want to add data in two different databases of microsoft access at a time using java.Can u tell me what is the code for such procedure.


sandesh nawadkar
March 11, 2009: 9:00 pm

hi,in which package JJRobot class is???

May 5, 2006: 11:55 am

necesito el codigo fuente del juego del gato en java … por favor atuda

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :