package ch.jp.robwar; import java.util.*; /** * This class shows a sample robot brain that goes bounces off * walls and stops moving when the other robots cannot shoot him. * * @author JP Martin * @date 9.4.1998 */ public class Wimp implements RobotBrain { /** * This internal variable is used to remember where the robot * wants to go. It is incremented by 90 each time a wall is hit. */ private double targetAngle = 270.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) { double rotation; boolean safe=true; Vector robList = senses.map.getRobotList(); for (int i=0;i0) { recule--; previousInstr=new Instructions(0,-0.03,false); return (previousInstr); } // keeping the angles in [0..360[ makes the job easier if (targetAngle>=360) targetAngle-=360; if (targetAngle<0) targetAngle+=360; // rotation represents how much I want to turn to face // the target angle rotation=360-senses.selfInfo.orientation+targetAngle; // we want to turn the fastest way // (i.e. rather turn -10 than 350) if (rotation>180) rotation=rotation-360.0; if (rotation>180) rotation=rotation-360.0; if (rotation<-180) rotation=rotation+360.0; if (java.lang.Math.abs(rotation)>0.1) { // turn to reach targetAngle if (rotation>5) rotation=5; else if (rotation<-5) rotation=-5; previousInstr=new Instructions(rotation,0,false); return previousInstr; } else { // We have the right orientation, go forward (ev. shoot) previousInstr=new Instructions(-0.01,0.1,java.lang.Math.random()>0.9); return previousInstr; } } }