[Home]Bob

Robo Home | Changes | Preferences | AllPages

Showing revision 15
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


Robo Home | Changes | Preferences | AllPages
Edit revision 15 of this page | View other revisions | View current revision
Edited June 14, 2005 20:52 EST by Dosnlinux (diff)
Search: