Difference between revisions of "Yatagan/Source"
< Yatagan
Jump to navigation
Jump to search
Skilgannon (talk | contribs) (1.0..2 - fix the char based energy detection, it seems 1 doesn't work) |
(Added a developmental version.) |
||
Line 1: | Line 1: | ||
+ | == Development Version == | ||
+ | <syntaxhighlight> | ||
+ | /* | ||
+ | Yatagan 1.0.3 by Sheldor & Skilgannon; Release date: 3-21-2013 | ||
+ | The yatagan is a short sabre which was used extensively in the Ottoman Empire. | ||
+ | Codesize: 247 bytes; Code size class: NanoBot | ||
+ | |||
+ | Credits: | ||
+ | Pattern Matching code from simonton.WeekendObsession_S and mld.Moebius, heavily modified. | ||
+ | And a general thanks to all open source bot authors and contributors to the RoboWiki. | ||
+ | |||
+ | Yatagan is open source and released under the terms of the RoboWiki Public Code License (RWPCL) - Version 1.1 | ||
+ | see license here: http://robowiki.net/wiki/RWPCL | ||
+ | */ | ||
+ | |||
+ | package sheldor.jk; | ||
+ | |||
+ | import robocode.*; | ||
+ | import robocode.util.Utils; | ||
+ | |||
+ | public class Yatagan extends AdvancedRobot | ||
+ | { | ||
+ | //Global variables. | ||
+ | static double direction; | ||
+ | static double enemyEnergy; | ||
+ | |||
+ | static int deathCount; | ||
+ | |||
+ | public void run() | ||
+ | { | ||
+ | //setAdjustGunForRobotTurn(true); | ||
+ | |||
+ | //Start spinning radar and initialize direction to infinity. | ||
+ | setTurnRadarRightRadians(direction = Double.POSITIVE_INFINITY); | ||
+ | } | ||
+ | |||
+ | public void onScannedRobot(ScannedRobotEvent e) | ||
+ | { | ||
+ | //Local variables. | ||
+ | int integer = 30; | ||
+ | double absoluteBearing; | ||
+ | double distance; | ||
+ | int matchPosition; | ||
+ | |||
+ | //Watch for a drop in the enemy's energy between 0 and 3. Thanks to Miked0801 for his awesome char trick. | ||
+ | if( (char) ((enemyEnergy - 1.09999 - (enemyEnergy = e.getEnergy()))) <= 1) | ||
+ | { | ||
+ | //One-way/Oscillating/Random movement. | ||
+ | direction *= (chancesOfReversing.charAt(deathCount) - 2*Math.random()); | ||
+ | } | ||
+ | setAhead(direction); | ||
+ | |||
+ | //Stay mostly perpendicular to the enemy, but try to maintain a distance of 160 pixels. | ||
+ | setTurnRightRadians(Math.cos(absoluteBearing = e.getBearingRadians()) + ((160.0 - (distance = e.getDistance())) * (getVelocity() *4e-4))); | ||
+ | |||
+ | //Pattern Matching. | ||
+ | enemyHistory = String.valueOf((char) (e.getVelocity() * (Math.sin(e.getHeadingRadians() - (absoluteBearing += getHeadingRadians()))))).concat(enemyHistory); | ||
+ | |||
+ | // search for a match | ||
+ | while((matchPosition = enemyHistory.indexOf(enemyHistory.substring(0, integer--), 64)) < 0); | ||
+ | |||
+ | integer = (int)(distance); | ||
+ | // calculate aim offset | ||
+ | |||
+ | do { | ||
+ | absoluteBearing += ((short) enemyHistory.charAt(--matchPosition)) / distance; | ||
+ | } while ((integer -= 12) > 0); | ||
+ | |||
+ | //Aim at the predicted target. | ||
+ | setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians())); | ||
+ | |||
+ | //Fire! | ||
+ | //The bullet power must be a multiple of .3333333333333333333333... | ||
+ | setFire(2.666666666666666666666666666666666666666666666666666666); | ||
+ | |||
+ | //Infinite radar lock. | ||
+ | setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); | ||
+ | } | ||
+ | |||
+ | public void onDeath(DeathEvent e) | ||
+ | { | ||
+ | //Move to the next cell in the table every time the bot dies. | ||
+ | deathCount++; | ||
+ | } | ||
+ | |||
+ | public void onHitWall(HitWallEvent e) | ||
+ | { | ||
+ | //Reverse direction when the bot hits a wall. | ||
+ | direction = -direction; | ||
+ | } | ||
+ | |||
+ | //The chance that the bot will reverse orbit direction when the enemy fires. | ||
+ | //Since this is an unchanging table, we can save a few bytes by using "final." | ||
+ | private static final String chancesOfReversing = "" | ||
+ | + (char) 2 + (char) 0 + (char) 2 + (char) 0 | ||
+ | + (char) 2 + (char) 0 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1; | ||
+ | |||
+ | //Preloaded log of enemy movements for pattern matcher so it doesn't need error checking | ||
+ | static String enemyHistory = "" | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 2 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char) 1 + (char) 1 + (char) 1 | ||
+ | + (char) 1 + (char)-2 + (char)-4 + (char)-6 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-8 + (char)-8 + (char)-8 + (char)-8 | ||
+ | + (char)-7 + (char)-6 + (char)-5 + (char)-4 | ||
+ | + (char)-3 + (char)-2 + (char)-1 + (char)1 | ||
+ | + (char) 2 + (char) 4 + (char) 6 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 8 + (char) 8 + (char) 8 + (char) 8 | ||
+ | + (char) 7 + (char) 6 + (char) 5 + (char) 4 | ||
+ | + (char) 3 + (char) 2 + (char) 1 + (char) 1; | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
== Version 1.0.2 == | == Version 1.0.2 == |
Revision as of 13:41, 21 March 2013
Development Version
/*
Yatagan 1.0.3 by Sheldor & Skilgannon; Release date: 3-21-2013
The yatagan is a short sabre which was used extensively in the Ottoman Empire.
Codesize: 247 bytes; Code size class: NanoBot
Credits:
Pattern Matching code from simonton.WeekendObsession_S and mld.Moebius, heavily modified.
And a general thanks to all open source bot authors and contributors to the RoboWiki.
Yatagan is open source and released under the terms of the RoboWiki Public Code License (RWPCL) - Version 1.1
see license here: http://robowiki.net/wiki/RWPCL
*/
package sheldor.jk;
import robocode.*;
import robocode.util.Utils;
public class Yatagan extends AdvancedRobot
{
//Global variables.
static double direction;
static double enemyEnergy;
static int deathCount;
public void run()
{
//setAdjustGunForRobotTurn(true);
//Start spinning radar and initialize direction to infinity.
setTurnRadarRightRadians(direction = Double.POSITIVE_INFINITY);
}
public void onScannedRobot(ScannedRobotEvent e)
{
//Local variables.
int integer = 30;
double absoluteBearing;
double distance;
int matchPosition;
//Watch for a drop in the enemy's energy between 0 and 3. Thanks to Miked0801 for his awesome char trick.
if( (char) ((enemyEnergy - 1.09999 - (enemyEnergy = e.getEnergy()))) <= 1)
{
//One-way/Oscillating/Random movement.
direction *= (chancesOfReversing.charAt(deathCount) - 2*Math.random());
}
setAhead(direction);
//Stay mostly perpendicular to the enemy, but try to maintain a distance of 160 pixels.
setTurnRightRadians(Math.cos(absoluteBearing = e.getBearingRadians()) + ((160.0 - (distance = e.getDistance())) * (getVelocity() *4e-4)));
//Pattern Matching.
enemyHistory = String.valueOf((char) (e.getVelocity() * (Math.sin(e.getHeadingRadians() - (absoluteBearing += getHeadingRadians()))))).concat(enemyHistory);
// search for a match
while((matchPosition = enemyHistory.indexOf(enemyHistory.substring(0, integer--), 64)) < 0);
integer = (int)(distance);
// calculate aim offset
do {
absoluteBearing += ((short) enemyHistory.charAt(--matchPosition)) / distance;
} while ((integer -= 12) > 0);
//Aim at the predicted target.
setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
//Fire!
//The bullet power must be a multiple of .3333333333333333333333...
setFire(2.666666666666666666666666666666666666666666666666666666);
//Infinite radar lock.
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
public void onDeath(DeathEvent e)
{
//Move to the next cell in the table every time the bot dies.
deathCount++;
}
public void onHitWall(HitWallEvent e)
{
//Reverse direction when the bot hits a wall.
direction = -direction;
}
//The chance that the bot will reverse orbit direction when the enemy fires.
//Since this is an unchanging table, we can save a few bytes by using "final."
private static final String chancesOfReversing = ""
+ (char) 2 + (char) 0 + (char) 2 + (char) 0
+ (char) 2 + (char) 0 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1;
//Preloaded log of enemy movements for pattern matcher so it doesn't need error checking
static String enemyHistory = ""
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 2
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char)-2 + (char)-4 + (char)-6
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-7 + (char)-6 + (char)-5 + (char)-4
+ (char)-3 + (char)-2 + (char)-1 + (char)1
+ (char) 2 + (char) 4 + (char) 6 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 7 + (char) 6 + (char) 5 + (char) 4
+ (char) 3 + (char) 2 + (char) 1 + (char) 1;
}
Version 1.0.2
/*
Yatagan 1.0.2 by Sheldor & Skilgannon
The yatagan is a short sabre which was used extensively in the Ottoman Empire.
Credits:
Pattern Matching code from simonton.WeekendObsession_S and mld.Moebius, heavily modified,
and a general thanks to all open source bot authors and contributors to the RoboWiki.
Yatagan is open source and released under the terms of the RoboWiki Public Code License (RWPCL) - Version 1.1
see license here: http://robowiki.net/wiki/RWPCL
*/
package sheldor.jk;
import robocode.*;
import robocode.util.Utils;
public class Yatagan extends AdvancedRobot
{
//Global variables.
static double direction;
static double enemyEnergy;
static int deathCount;
//En garde!
public void run()
{
//setAdjustGunForRobotTurn(true);
//Start spinning radar and initialize direction to infinity.
setTurnRadarRightRadians(direction = Double.POSITIVE_INFINITY);
}
public void onScannedRobot(ScannedRobotEvent e)
{
//Local variables.
int integer = 30;
double absoluteBearing;
double distance;
int matchPosition;
//Oscillating/Random movement.
if( (char) ((enemyEnergy - 1.09999 - (enemyEnergy = e.getEnergy()))) <= 1)
{
direction *= (chancesOfReversing.charAt(deathCount) - 2*Math.random());
}
setAhead(direction);
//Stay perpendicular to the enemy.
setTurnRightRadians(Math.cos(absoluteBearing = e.getBearingRadians()) + ((160.0 - (distance = e.getDistance())) * (getVelocity() *4e-4)));
//Pattern Matching.
enemyHistory = String.valueOf((char) (e.getVelocity() * (Math.sin(e.getHeadingRadians() - (absoluteBearing += getHeadingRadians()))))).concat(enemyHistory);
// search for a match
while((matchPosition = enemyHistory.indexOf(enemyHistory.substring(0, integer--), 64)) < 0);
integer = (int)(distance);
// calculate aim offset
do {
absoluteBearing += ((short) enemyHistory.charAt(--matchPosition)) / distance;
} while ((integer -= 12) > 0);
//Aim at the predicted target.
setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
//Fire!
setFire(2.6666666666666);
//Infinite radar lock.
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
public void onDeath(DeathEvent e)
{
deathCount++;
}
public void onHitWall(HitWallEvent e)
{
//Reverse direction when the bot hits a wall.
direction = -direction;
}
//chance out of 3 for given number of deaths, 'final' saves a few bytes
private static final String chancesOfReversing = ""
+ (char) 2 + (char) 0 + (char) 2 + (char) 0
+ (char) 2 + (char) 0 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1;
//Preloaded log of enemy movements for pattern matcher so it doesn't need error checking
static String enemyHistory = ""
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 2
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char)-2 + (char)-4 + (char)-6
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-7 + (char)-6 + (char)-5 + (char)-4
+ (char)-3 + (char)-2 + (char)-1 + (char)1
+ (char) 2 + (char) 4 + (char) 6 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 7 + (char) 6 + (char) 5 + (char) 4
+ (char) 3 + (char) 2 + (char) 1 + (char) 1;
}
Version 1.0.1
/*
Yatagan 1.0.1 by Sheldor & Skilgannon
The yatagan is a short sabre which was used extensively in the Ottoman Empire.
Credits:
Pattern Matching code from simonton.WeekendObsession_S and mld.Moebius, heavily modified,
and a general thanks to all open source bot authors and contributors to the RoboWiki.
Yatagan is open source and released under the terms of the RoboWiki Public Code License (RWPCL) - Version 1.1
see license here: http://robowiki.net/wiki/RWPCL
*/
package sheldor.jk;
import robocode.*;
import robocode.util.Utils;
public class Yatagan extends AdvancedRobot
{
//Global variables.
static double direction;
static double enemyEnergy;
static int deathCount;
//En garde!
public void run()
{
//setAdjustGunForRobotTurn(true);
//Start spinning radar and initialize direction to infinity.
setTurnRadarRightRadians(direction = Double.POSITIVE_INFINITY);
}
public void onScannedRobot(ScannedRobotEvent e)
{
//Local variables.
int integer = 30;
double absoluteBearing;
double distance;
int matchPosition;
//Oscillating/Random movement.
if( (char) ((enemyEnergy - 1 - (enemyEnergy = e.getEnergy()))) <= 1)
{
direction *= (chancesOfReversing.charAt(deathCount) - 2*Math.random());
}
setAhead(direction);
//Stay perpendicular to the enemy.
setTurnRightRadians(Math.cos(absoluteBearing = e.getBearingRadians()) + ((160.0 - (distance = e.getDistance())) * (getVelocity() *4e-4)));
//Pattern Matching.
enemyHistory = String.valueOf((char) (e.getVelocity() * (Math.sin(e.getHeadingRadians() - (absoluteBearing += getHeadingRadians()))))).concat(enemyHistory);
// search for a match
while((matchPosition = enemyHistory.indexOf(enemyHistory.substring(0, integer--), 64)) < 0);
integer = (int)(distance);
// calculate aim offset
do {
absoluteBearing += ((short) enemyHistory.charAt(--matchPosition)) / distance;
} while ((integer -= 12) > 0);
//Aim at the predicted target.
setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
//Fire!
setFire(2.6666666666666);
//Infinite radar lock.
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
public void onDeath(DeathEvent e)
{
deathCount++;
}
public void onHitWall(HitWallEvent e)
{
//Reverse direction when the bot hits a wall.
direction = -direction;
}
//chance out of 3 for given number of deaths, 'final' saves a few bytes
private static final String chancesOfReversing = ""
+ (char) 2 + (char) 0 + (char) 2 + (char) 0
+ (char) 2 + (char) 0 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1;
//Preloaded log of enemy movements for pattern matcher so it doesn't need error checking
static String enemyHistory = ""
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 2
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char)-2 + (char)-4 + (char)-6
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-7 + (char)-6 + (char)-5 + (char)-4
+ (char)-3 + (char)-2 + (char)-1 + (char)1
+ (char) 2 + (char) 4 + (char) 6 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 7 + (char) 6 + (char) 5 + (char) 4
+ (char) 3 + (char) 2 + (char) 1 + (char) 1;
}
Version 1.0.0
/*
Yatagan 1.0.0 by Sheldor & Skilgannon
The yatagan is a short sabre which was used extensively in the Ottoman Empire.
Credits:
Pattern Matching code from simonton.WeekendObsession_S and mld.Moebius, heavily modified,
and a general thanks to all open source bot authors and contributors to the RoboWiki.
Yatagan is open source and released under the terms of the RoboWiki Public Code License (RWPCL) - Version 1.1
see license here: http://robowiki.net/wiki/RWPCL
*/
package sheldor.jk;
import robocode.*;
import robocode.util.Utils;
public class Yatagan extends AdvancedRobot
{
//Global variables.
static double direction;
static double enemyEnergy;
static int deathCount;
//En garde!
public void run()
{
// setAdjustGunForRobotTurn(true);
//Start spinning radar and initialize direction to infinity.
setTurnRadarRightRadians(direction = Double.POSITIVE_INFINITY);
}
public void onScannedRobot(ScannedRobotEvent e)
{
//Local variables.
int integer = 30;
double absoluteBearing;
double distance;
int matchPosition;
//Oscillating/Random movement.
if( (char) ((enemyEnergy - 1.0999 - (enemyEnergy = e.getEnergy()))) < 2)
{
direction *= (chancesOfReversing.charAt(deathCount) - 3*Math.random());
}
setAhead(direction);
//Stay perpendicular to the enemy.
setTurnRightRadians(Math.cos(absoluteBearing = e.getBearingRadians()) + ((160.0 - (distance = e.getDistance())) * (getVelocity() *4e-4)));
//Pattern Matching.
enemyHistory = String.valueOf((char) (e.getVelocity() * (Math.sin(e.getHeadingRadians() - (absoluteBearing += getHeadingRadians()))))).concat(enemyHistory);
// search for a match
while((matchPosition = enemyHistory.indexOf(enemyHistory.substring(0, integer--), 64)) < 0);
integer = (int)(distance);
// calculate aim offset
do {
absoluteBearing += ((short) enemyHistory.charAt(--matchPosition)) / distance;
} while ((integer -= 12) > 0);
//Aim at the predicted target.
setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
//Fire!
setFire(2.6666666666666666666666666666);
//Infinite radar lock.
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
public void onDeath(DeathEvent e)
{
deathCount++;
}
public void onHitWall(HitWallEvent e)
{
//Reverse direction when the bot hits a wall.
direction = -direction;
}
//chance out of 3 for given number of deaths, 'final' saves a few bytes
private static final String chancesOfReversing = ""
+ (char) 3 + (char) 0 + (char) 3 + (char) 0
+ (char) 3 + (char) 0 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1;
//Preloaded log of enemy movements for pattern matcher so it doesn't need error checking
static String enemyHistory = ""
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 2
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char) 1 + (char) 1 + (char) 1
+ (char) 1 + (char)-2 + (char)-4 + (char)-6
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-8 + (char)-8 + (char)-8 + (char)-8
+ (char)-7 + (char)-6 + (char)-5 + (char)-4
+ (char)-3 + (char)-2 + (char)-1 + (char)1
+ (char) 2 + (char) 4 + (char) 6 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 8 + (char) 8 + (char) 8 + (char) 8
+ (char) 7 + (char) 6 + (char) 5 + (char) 4
+ (char) 3 + (char) 2 + (char) 1 + (char) 1;
}