[Home]Robot

Robo Home | Changes | Preferences | AllPages

Difference (from prior major revision) (no other diffs)

Added: 90a91,92

But why it can process on first time? Ar first, it go ahead and turn left (like setAhead(100); setTurnLeft?(360); execute();). But when turn finish (ahead finished before turn) at turn 30, my robocode program freeze for 5 seconds and then, my robot disabled by exception I've post above. -- Nat

A robot is an computer controled machine. In Robocode a robot is a tank that is programmed by the player in Java.

Simple robots extend Robot. They don't take damage when they hit walls, and can't use non-BlockingCall?s, CustomEvents or access files. They can use FiringAssistance (due to a bug, so can AdvancedRobots).

More complex robots extend AdvancedRobot.

-- JohnDoe


I would argue that a simpler robot extends AdvancedRobot. It's much easier to get the job done with AdvancedRobot's. Should you need a blocking call for some reason you have them there too. -- PEZ
Are there any competitive bots that extend Robot?

Yes, but they are few. There is an ExtendsRobot competition somewhere on this wiki, kawigi.robot.Girl, for example, also competes in the roborumble and meleerumble. I don't recommend starting out learning Robocode by trying to make a competitive Robot. -- Martin

Typically the source of such a question is competitions that don't allow AdvancedRobots (usually with the purpose of making it less likely that people will steal code from existing bots on the Repository). -- Kawigi

Ah, so you are suggesting that the anonymous poster is trying to cheat in a class competition. Lame. -- Martin

I'm not saying that's necessarily the case, just that it's quite possible :-) Also, I have been contacted before by a person asking if they could use some part of Girl in that kind of competition (although it was someone that I knew from another programming community). Girl is good partly because it is a robot designed without the limitations of an ExtendsRobot in consideration, and then adjusting things to allow for those limitations. -- Kawigi

Can I split movement into a Thread and use these Thread to create a non-blocking call? -- Nat

EDIT: I've try that, using following code:

public class RobotTest extends Robot 
{
	protected Thread move1;
	protected Thread move2;
	public void run()
	{
		move1 = new Thread(new Move1(this));
		move2 = new Thread(new Move2(this));
		move1.start();
		move2.start();
		while (true);
	}
}

class Move1 implements Runnable
{
	Robot robot;
	public Move1(Robot r)
	{
		robot = r;
	}
	public void run()
	{
		while (true)
		{
			robot.ahead(100);
		}
	}
}

class Move2 implements Runnable
{
	Robot robot;
	public Move2(Robot r)
	{
		robot = r;
	}
	public void run()
	{
		while (true)
		{
			robot.turnLeft(360);
		}
	}
}
But when it being call for the second time, I've got this exception:
Exception in thread "Thread-57" robocode.exception.RobotException: You cannot take action in this thread!
	at robocode.peer.RobotPeer.execute(Unknown Source)
	at robocode.peer.RobotPeer.move(Unknown Source)
	at robocode.peer.proxies.BasicRobotProxy.move(Unknown Source)
	at robocode.Robot.ahead(Unknown Source)
	at nat.robot.Move1.run(RobotTest.java:30)
	at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-58" robocode.exception.RobotException: You cannot take action in this thread!
	at robocode.peer.RobotPeer.execute(Unknown Source)
	at robocode.peer.RobotPeer.turnBody(Unknown Source)
	at robocode.peer.proxies.BasicRobotProxy.turnBody(Unknown Source)
	at robocode.Robot.turnLeft(Unknown Source)
	at nat.robot.Move2.run(RobotTest.java:46)
	at java.lang.Thread.run(Unknown Source)
Do you know why? -- Nat

You're only allowed to have calls like robot.ahead(100) from inside of the robot's "run()" method and only in the normal thread. It's an intended limit that the "Robot" class can't turn and move at once, and it's really just for learning the basics (or just-for-fun challenges). You're not meant to be able to do non-blocking movement in "Robot", only "AdvancedRobot". The correct way to do things like turn and move at once is to extend AdvancedRobot and use setAhead(), setTurnLeft?(), and execute(). Also as a general tip, don't use threads in Robocode. While you could technically use a thread to process data, that could potentailly steal time from the other robot's turn, and it's in some conversation there has been some consensus that such unfair behavior shouldn't be allowed by bots in the Rumble. -- Rednaxela

But why it can process on first time? Ar first, it go ahead and turn left (like setAhead(100); setTurnLeft?(360); execute();). But when turn finish (ahead finished before turn) at turn 30, my robocode program freeze for 5 seconds and then, my robot disabled by exception I've post above. -- Nat


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited November 24, 2008 11:01 EST by proxy1.chula.ac.th (diff)
Search: