Robo Home | Changes | Preferences | AllPages

package cx.sonnet;
import robocode.*;
import java.util.Vector;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
 * @author:iiley (iiley@hotmail.com)
 * http://www.robochina.org
 * Ash:When you are smoking by the window,you will see the ash flying...
 * ash is a microbot with the Cigaret's move scheme ... and a similar to Spark's gun.
 * SonAsh: a sonnet version of Ash,14 lines.Squeezed from FemtoAsh,so it performace same to FemtoAsh.
 *--------------------version 0.7 2003.9.14--------------
 * 0.7:first released version.With a mine version symbol PM.
 * Thanks kawigi for his open source nanobots,i learned much more from his bot FunkyFemto and FunkyMusic.
 *--------------------version 0.7 2003.9.15--------------
 * 0.8:Thanx Kawigi that told me how to make this runnalbe in JVM 1.3.
 *+++++++++++++++++++++++++++++++++Open Source+++++++++++++++++++++++++++
 * This bot is open source.
 * - Don't just copy-paste the code .
 * - Don't just copy-paste and then improve.(I don't want to fight modified versions of my own bot)
 * - Maybe some useful skill in this codes,if you use,Make your bot open source
 * - And preferably give credit.:)
 * If you want to know more or suggest,
 * email me or post messages on www.robochina.org or www.robocoderepository's forums.
 * every messages will be pleasent.
public class SonAsh extends AdvancedRobot
	private static Object e_energy=new double[1],pattern = new StringBuffer(),nextP,myP,enemyP;
	public void run( ) {
   	public void onScannedRobot( ScannedRobotEvent e ) {
		double absBearing,edistance,moveDistance,moveAngle,dist=0,index=0,searchlength = 80,power=Math.min(600d/e.getDistance()+0.5d,Math.min(getEnergy()/5d,Math.min(3d,e.getEnergy()/5d)));
        if((enemyP=nextPoint((Point2D.Double)(myP=new Point2D.Double(getX(),getY())),absBearing=e.getBearingRadians()+getHeadingRadians(),moveDistance=edistance=e.getDistance()))!=null && ((double[])e_energy)[0]!=(((double[])e_energy)[0]=e.getEnergy()) && Math.abs(getDistanceRemaining())<53d){  
			while(!new Rectangle2D.Double(23D, 23D, getBattleFieldWidth()-46D,  getBattleFieldHeight()-46D).contains((Point2D.Double)(nextP=nextPoint(((Point2D.Double)enemyP),absBearing+(moveAngle=Math.random()*1.6d-0.8d),-(moveDistance-=10d)/Math.cos(moveAngle)))));
			setAhead((( moveAngle = robocode.util.Utils.normalRelativeAngle(Math.atan2( ((Point2D.Double)nextP).x-((Point2D.Double)myP).x,((Point2D.Double)nextP).y-((Point2D.Double)myP).y) - getHeadingRadians() ) ) == ( moveDistance = Math.atan( Math.tan( moveAngle ) ) ) ? 1 : - 1 )	* ((Point2D.Double)myP).distance(((Point2D.Double)nextP)) );	//move towards point
			setTurnRightRadians( moveDistance );
		//-----------------pattern analyser--------------------
		        if(((StringBuffer)pattern).insert(0,new char[]{(char)(e.getHeadingRadians()/0.3927+8),(char)e.getVelocity()})!=null || true)
	            	while ((index = ((StringBuffer)pattern).indexOf(((StringBuffer)pattern).substring(0, (int)(searchlength-=2)), 1)+1) < 20);
                while((++dist)*(20d-power*3d) - ((Point2D.Double)myP).distance((Point2D.Double)(enemyP=nextPoint(((Point2D.Double)enemyP),((byte)(((StringBuffer)pattern).toString().charAt((int)(--index)))-8)*0.3927,((byte)((StringBuffer)pattern).toString().charAt((int)(--index))))))<0);
    		}catch(Exception ee){}
		if(getEnergy()>power+0.1) if(setFireBullet(power)==null || true) setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(Math.atan2(((Point2D.Double)enemyP).x-((Point2D.Double)myP).x,((Point2D.Double)enemyP).y-((Point2D.Double)myP).y) - getGunHeadingRadians()));
		setTurnRadarRightRadians(Math.sin(absBearing - getRadarHeadingRadians()));
	public static Point2D.Double nextPoint(Point2D.Double originPoint,double angle,double distance){
		return new Point2D.Double(originPoint.x+Math.sin(angle)*distance,originPoint.y+Math.cos(angle)*distance);

I suggest you make this bot compatible with Java 1.3 by adding a .toString() before the .charAt part. You should have noticed that in FunkyMusic? (which was my 5-line version of FunkyChicken). -- Kawigi

OK~~Thanx.~;] -- iiley

This sonnet development doesn't exactly help making our bot code more readable. =) -- PEZ

changed. Yes,you are right PEZ,i do not like to make sonnet,i like femto and haiku.~;]sonnet is worse than mini,so you can see there are only 2 or 3 sonnet this time but many femto. -- iiley

Sonnets are much more complex to write than a femto or haiku, that's for sure. Of course, David and I were agreeing that while the state of the art in nanos always gets simplified and shrunk, the state of the art in line-based bots will continually get more complex. -- Kawigi

That's partly because we now count semicolons I think. In any case, it's even more silly than minibot coding. But fun for a change. I like the immediate trade-off situations when producing haikus. -- PEZ

...or especially when making femtos. But you're right. It's self-code-obfuscation as an art. I suspect it will be almost comical to look at a Sonnet sometimes. -- Kawigi

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited September 15, 2003 16:21 EST by Kawigi (diff)