[Home]Bob

Robo Home | Changes | Preferences | AllPages

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

Changed: 95c95,97
Okay, I misread the API. I thought the setTurnXradians? meathods weren't called until execute was, instead of "executes immediatly" Is the only reason the execute meathod is there is so that you can continue saving data? What other things would you be doing after you die that you would need to execute()? --dosnlinux
Okay, I misread the API. I thought the setTurnXradians? meathods weren't called until execute was, instead of "executes immediatly" Is the only reason the execute meathod is there is so that you can continue saving data? What other things would you be doing after you die that you would need to execute()? --dosnlinux

Your original understanding sounds correct. execute() makes everything happen that you called a setXXX method for, and also does any movement of the rest of the battle field - bots, bullets, etc., advancing to the next turn. In all of those updates, you could die (which could also happen during any blocking call). If you die, a DeathException? is thrown, which immediately exits the function and every other function you're in (including run) until the method that called run to begin with, at which point your bot stops executing. You never are supposed to get a chance to call execute after you die, continue saving data or continue getting events. The main thing you have to understand is when you die, your run method abruptly stops. -- Kawigi

This will be my first attempt at a bot. For the most part I will just scrap the sample bots for parts, modify the gun and movement a little, and play around with the scanner a little.

What's next?
I have to get it built first!

How's it target?
It will use LinearTargeting

How's it move?
In an arch around the target.


Hey, just like I made my first bot, just Spinbot (on full speed) with the gun of TrackFire. Success !! -- GrubbmGait

I was considering using trackfire's gun using LinearTargeting, and simularly using spinbot to creat a back and forth semicircle around the target:) I was reading your profile and noticed you did J2ME stuff. How hard do you think It would be to port robocode to that platform? Probably wouldn't happen because of the RAM constraints, but until minidevices get more advance it would be cool to dream about:D --dosnlinux

How to you fire while moving? Is there a way to do it using already availiable threads? --dosnlinux

Not only the RAM constraints, but also the graphical possibilities are (very) limited. Frankly, the only thing I have done with Java since that course is Robocode. Check my code, and you'll see what I mean (still writing C with a Java-coating). As for firing while moving, you need to extend AdvancedRobot. Very simplified it would show something like this:

public void run() {
	setTurnRadarRight( Double.POSITIVE_INFINITY);
	direction = 180;
	// mainloop
	while( true ) {
		// Check if nearly at end of movement
		if (Math.abs(getDistanceRemaining()) < 1) {
			setAhead( direction);
			direction = -direction;
		}
		execute();
	}
}

	/**
	 * onScannedRobot: What to do when you see another robot
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		// Stay perpendicular to the opponent 
		setTurnRightRadians( robocode.utils.Utils.normalRelativeAngle(e.getBearingRadians() + Math.PI/));
		// Turn radar towards opponent and 'lock'
		setTurnRadarRightRadians( robocode.utils.Utils.normalRelativeAngle( getHeadingRadians() + e.getBearingRadians() - getRadarHeadingRadians()));
		// Fire gun if it is cool
		if (getGunHeat() == 0.0) {
			setFire( power);
		}
	}
Ofcourse there is a lot missing here, but I hope you get the general idea. In the beginning the easiest way (in OneOnOne) to control your gun and (partly) your movement is from the onScannedRobot eventhandler. Further check out Robohome -> Beginners -> Tutorial -> Snippetbot. It has been a start for a lot of (top)Robocoders. -- GrubbmGait

Let's see if I understand what is going on in the code(I'm still new to Java and programming, so if I misunderstand please correct me:) )

public void run() {
	<font color="green">//turn radar around and around forever</font>
	setTurnRadarRight( Double.POSITIVE_INFINITY);
	direction = 180;
	// mainloop
	while( true ) {
		// Check if nearly at end of movement
		//if you still have some movement left keep going
		
if (Math.abs(getDistanceRemaining()) < 1) {
			setAhead( direction);
			direction = -direction;
		}
		execute();
//perform all schedualed actions
	}
}

	/**
	 * onScannedRobot: What to do when you see another robot
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		
//get ready to turn
		// Stay perpendicular to the opponent 
		setTurnRightRadians( robocode.utils.Utils.normalRelativeAngle(e.getBearingRadians() + Math.PI/));
//get ready to turn radar
		// Turn radar towards opponent and 'lock'
		setTurnRadarRightRadians( robocode.utils.Utils.normalRelativeAngle( getHeadingRadians() + e.getBearingRadians() - getRadarHeadingRadians()));
		// Fire gun if it is cool
		if (getGunHeat() == 0.0) {
			setFire( power);
		}
	}

I'm a little confused about the execute meathod. How does the code break out of the infinite while loop?

If you die, your execute() method throws an exception that prematurely exits your run method. -- Kawigi

Okay, I misread the API. I thought the setTurnXradians? meathods weren't called until execute was, instead of "executes immediatly" Is the only reason the execute meathod is there is so that you can continue saving data? What other things would you be doing after you die that you would need to execute()? --dosnlinux

Your original understanding sounds correct. execute() makes everything happen that you called a setXXX method for, and also does any movement of the rest of the battle field - bots, bullets, etc., advancing to the next turn. In all of those updates, you could die (which could also happen during any blocking call). If you die, a DeathException? is thrown, which immediately exits the function and every other function you're in (including run) until the method that called run to begin with, at which point your bot stops executing. You never are supposed to get a chance to call execute after you die, continue saving data or continue getting events. The main thing you have to understand is when you die, your run method abruptly stops. -- Kawigi


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited June 14, 2005 21:00 EST by Kawigi (diff)
Search: