package tango; import robocode.*; import java.util.ArrayList; import java.awt.geom.Point2D; /** * CircularBot - a test of a circular list */ public class CircularBot extends Robot { CircularList Route=new CircularList(new Point2D.Double(100,100), new Point2D.Double(150,100), new Point2D.Double(150,150), new Point2D.Double(100,150)); public void run() { while(true) { if (Math.random()>0.5) {Route.clockwise();} else {Route.anticlockwise();} goTo(Route.getCurrent()); } } public void goTo(Point2D Position) { double AngleToMove=Math.toDegrees(Math.atan2(Position.getX()-getX(),Position.getY()-getY())); AngleToMove-=getHeading(); while (AngleToMove>180) {AngleToMove-=360;} while (AngleToMove<-180) {AngleToMove+=360;} turnRight(AngleToMove); ahead(Position.distance(getX(),getY())); } } class CircularList { Point2D[] List=new Point2D[4]; int Pointer=0; CircularList(Point2D one, Point2D two, Point2D three, Point2D four) { List[0]=one; List[1]=two; List[2]=three; List[3]=four; } public Point2D getCurrent() {return this.List[Pointer];} public void clockwise() {Pointer++; if (Pointer>3) {Pointer=0;}} public void anticlockwise() {Pointer--; if (Pointer<0) {Pointer=3;}} }