package ch.jp.robwar; import java.util.*; /** * Seeker is an extension of Sprinkler. It will seek out the other * robot and relentlessy shoot at it. * * @author JP Martin * @date 9.3.1998 */ public class Seeker implements RobotBrain { /** * The point we really, absolutely want to reach */ private Position targetPoint = new Position(2.0,2.0); /** * This internal variable is used to remember where the robot * wants to go. */ private double targetAngle = 270.0; private int state= 0; private int subState=0; /** * This internal variable, when !=0, forces the robot to back up. */ private int recule = 0; /** * This allows the robot brain to remember its past actions. */ private Instructions previousInstr; /** * This function is called by the simulation for each time step. * It returns the orders that the robot brain gives to the robot body. */ public Instructions nextMove(Feedback senses) { Vector robList = senses.map.getRobotList(); targetPoint=null; for (int i=0;i=360) targetAngle-=360; double rotation; rotation=targetAngle-senses.selfInfo.orientation; if (rotation>180) rotation-=360; if (rotation>180) rotation-=360; if (rotation<-180) rotation+=360; if (rotation<-5) rotation=-5; if (rotation>5) rotation=5; // if necessary, turn if (rotation!=0) return new Instructions(rotation,0.0,false); // otherwise, go forward double spd; spd= (senses.selfInfo.position.x-targetPoint.x)*(senses.selfInfo.position.x-targetPoint.x) +(senses.selfInfo.position.y-targetPoint.y)*(senses.selfInfo.position.y-targetPoint.y); spd = java.lang.Math.sqrt(spd); if (spd<0.8) spd=0.0; // close enough to the fiend if (spd>0.1) spd=0.1; // don't move too fast return new Instructions(0.0,spd,true); } // error case state=0; // don't try this at home // System.out.println("Seeker error"); return new Instructions(); } }