View source for Talk:Talon/source
It's 242 bytes, removing the colors nets it another 7 to 235 bytes (javac). I need to find a way to give this little guy some center avoidance, but I am at a loss. I am not to good at writing nanos. If anyone can squeeze anything in there, might be OK for the melee nano rumble. — Chase-san 11:57, 30 January 2011 (UTC)
Now down to 230 with colors or 223 without them. — Chase-san 16:02, 30 January 2011 (UTC)
Down to 220/213 (javac). — Chase-san 17:11, 30 January 2011 (UTC)
Going back over this code, I found some errors I am going to fix. Mostly with the direction choosing. — Chase-san 16:05, 2 July 2011 (UTC)
EJC 229 bytes, needs work to avoid the walls and it should be pretty good, maybe if I have room add in something to get that missed scan back. — Chase-san 16:32, 2 July 2011 (UTC)
I'll check it out as well to see if there's anything else to be squeezed. Never thought about using try catch blocks... --Miked0801 17:20, 2 July 2011 (UTC)
- I wish I could get rid of some of those variables, but the v[] I think actually gives me codesize. Can't think of any other way to do t, but might be able to initialize that to 0 and just use ++ with my try there, but might get some empty/ancient scans with that. Biggest issue is wall avoidance, not sure how to squeeze that in there. — Chase-san 18:57, 2 July 2011 (UTC)
- [View source↑]
- [History↑]
Contents
Thread title | Replies | Last modified |
---|---|---|
Wall avoidance | 9 | 19:29, 22 February 2013 |
While that would minimize the codesize, it would make the wall avoidance much more pronounce (and much worse).
I come back time to time to see if I can make a better wall avoidance for this robot. But so far I have failed terribly.
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page.
Return to Thread:Talk:Talon/source/Wall avoidance/reply (5).
It still seems to hang up on walls fairly easily. Sometimes it looks very nice and avoids them. But sometimes ti drives straight into them and hangs up on them.
But the idea isn't a bad one at all.
package cs;
import java.awt.geom.Point2D;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;
/**
* Talon - a Nano Melee robot by Chase
*
* The idea is to avoid driving toward enemy robots, nearer ones are more
* dangerous to drive towards.
*
* Codesize: 248
*/
public class Talon extends AdvancedRobot {
private static Point2D.Double[] map = new Point2D.Double[10];
private static int n;
public void run() {
//setAdjustGunForRobotTurn(true); //Sheldor: In melee this doesn't really matter.
//setAllColors(Color.RED); //Sheldor: I'm very sorry. :(
double angle, bestDanger, danger;
while(true) {
setAhead((bestDanger = angle = 360) - (5 * getTurnRemaining())); //Sheldor: Slowing down before making big turns makes the wall avoidance much better.
while(angle-- > 0) {
int t;
setFire(t = getOthers()); //Sheldor: From Graviton.
//Sheldor: Drive toward the center of the field when the bot gets near a wall.
//This will only work properly on a 1000/1000 pixel field.
danger = -Math.abs(Utils.normalRelativeAngleDegrees(angle - Math.toDegrees(Math.atan2(getX() - 500, getY() - 500)))) *
(table.charAt((int)getX()) + table.charAt((int)getY()));
try {
while(true) {
// our most recent scans, unfortunately not enough room
// to project them
Point2D.Double v;
// set our gun to face this nearest enemy
setTurnGunRight(Utils.normalRelativeAngleDegrees((v = map[--t]).y - getGunHeading()));
// the difference between current angle we are
// considering and the enemy
// multiply it by how close they are, closer is more
// dangerous to move towards
danger += 1 / (Math.abs(Utils.normalRelativeAngleDegrees(angle - v.y))) / v.x; //Sheldor: "X / Y" has exactly the same effect as "X * (1 / Y)" but is ~3 bytes smaller.
}
} catch(Exception e) {
// We don't have room for any kind of sanity checks, also
// the only way to get out of the loop without
// having to have a comparison, saves us some code size
}
if(danger < bestDanger) {
bestDanger = danger;
setTurnRight(Utils.normalRelativeAngleDegrees(angle - getHeading()));
}
}
// Turning it by only 1 saves us some code size but in radians this
// value > PI/4 the maximum
// turn the radar can turn, meaning it will cover the full arc as
// long as we call it every turn.
turnRadarRightRadians(1);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
try {
// Set the most recent scan into our map of enemies
map[--n] = new Point2D.Double(e.getDistance(), getHeading() + e.getBearing());
}
catch(Exception ex) {
// attempted to scan but it failed, set the number of enemies again
// we miss an enemy scan but we gain some code size here
n = getOthers();
}
}
static final String table = "\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064" +
"\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0001" +
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001" +
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\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0\0\0\0\0\0\u0001\u0001\u0001\u0001\u0001" +
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001" +
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064" +
"\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064" +
"\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064\u0064";
}
Well it still knocks into walls a good bit, but less then my prototype. But it doesn't hang up on them either. Which is nice. If you are okay, we can brand it wiki or a cs.sheldor and enter it. See how a nano Minimum Risk Movement does.
The table could use a bit of tweaking, and I have a weird feeling that there's something better right under my nose, but let's go ahead and release it.
I'd be happy with just a mention in the comments, but I like the sound of cs.sheldor.Talon. Or, since we are both from the USA, we could emulate Nemo and name it usa.Talon. Whichever you prefer.