ProgrammierMethodik 2002 - RoboCup

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

RCGoalieBrain.java

Go to the documentation of this file.
00001 /*
00002  * $Id: RCGoalieBrain_8java-source.html,v 1.1 2002/07/09 21:33:17 stork Exp $
00003  *
00004  * $Log: RCGoalieBrain_8java-source.html,v $
00004  * Revision 1.1  2002/07/09 21:33:17  stork
00004  * add new class
00004  *
00005  * Revision 1.7  2002/07/07 22:42:39  transier
00006  * minimal final changes
00007  *
00008  * Revision 1.6  2002/07/07 19:31:44  ritter
00009  * final version of goalie
00010  *
00011  * Revision 1.5  2002/07/07 19:11:39  ritter
00012  * second versinon of goalie
00013  *
00014  * Revision 1.4  2002/07/07 15:06:32  transier
00015  * debugging
00016  *
00017  * Revision 1.3  2002/07/07 14:10:39  ritter
00018  * first version of goalie
00019  *
00020  * Revision 1.2  2002/07/07 11:24:47  transier
00021  * import call removed
00022  *
00023  * Revision 1.1  2002/07/06 13:20:50  transier
00024  * empty Brain for Goalie
00025  *
00026  *
00027  */
00028 
00032 public class RCGoalieBrain extends RCBrain {
00033 
00035   private final double MAX_DIST =1.;
00036   protected final double HAS_BALL = .5;      // defines threshold for "a player has the ball"
00037   protected final int MAX_TIME = 3;     // defines threshold in which position information of objects are valid
00038   protected final double MIN_POWER_DASH = 1;    // defines threshold for the minimum power a dash command is submitted
00039   protected final double MAX_ANGLE = .5;        // defines threshold for the maximunm angle differece between the player and his target point
00040   protected final double POWER_COEFF_DASH = 20.;        // defines relation between distance and power for dash command
00041   protected final double NEAR_BALL = .6;        // defines threshold for "the ball is near"
00042   
00047   public int update(){
00048         
00049         RCObject me = World.getOurself ();
00050     myX = me.X (0);
00051     myY = me.Y (0);
00052 
00053     double ballX = World.Ball.X (0);
00054     double ballY = World.Ball.Y (0);
00055     double ballDist = calcDist (myX, myY, ballX, ballY);
00056     double angle;
00057     
00058     // found ball
00059         if (searchBall()){
00060                 
00061             // goalie has ball
00062                 if (ballDist <= HAS_BALL){
00063                   angle = getAngleToPoint(0, 0);
00064                   Communicator.kick(100, angle);
00065                   return 0;
00066                 }
00067                 
00068                 // ball is in goalie's field and he hasn't got it yet
00069                 else if (inField (ballX, ballY)){                       
00070                   // turn to ball
00071           angle = getAngleToPoint(ballX, ballY);
00072           if (Math.abs (angle) >= MAX_ANGLE && !World.NewData){
00073             Communicator.turn (angle);
00074                     return 0;
00075           }
00076           // run to ball
00077               if (Math.abs (ballDist) >= NEAR_BALL){
00078                 Communicator.dash (dashPower(ballDist));
00079                     return 0;
00080           }
00081           // goalie is NEAR_BALL => catch
00082           else {
00083             angle = getAngleToPoint(ballX, ballY);
00084             Communicator.catchit(angle);       
00085             return 0;
00086           }       
00087       }  
00088       
00089       
00090       // ball isn't in goalie's field
00091       else if (inField (myX, myY)){
00092 
00093                 // get destination point
00094                 double x = -GOAL_X + 1.5;
00095                 double y = 0; //ballX*(14/68);
00096                 // turn to destination point
00097                 double dist = calcDist(x, y, myX, myY);
00098                 angle = getAngleToPoint(x, y);
00099         if ((Math.abs (angle) >= MAX_ANGLE && !World.NewData) && (Math.abs (dist) >= MAX_DIST)){
00100           
00101           Communicator.turn (angle);
00102                   return 0;
00103         }
00104         // go to destination point
00105             if (Math.abs (dist) >= MAX_DIST){
00106                 
00107               Communicator.dash (dashPower(dist)*0.5);
00108                   return 0;
00109         }
00110         // turn to ball
00111         angle = getAngleToPoint(ballX, ballY);
00112         if (Math.abs (angle) >= MAX_ANGLE && !World.NewData){
00113           Communicator.turn (angle);      
00114                   return 0;
00115         }
00116         return 0;  
00117       }  
00118       
00119       // ball and goalie aren't in goalie's field  
00120           else{    
00121             // turn to middel of goal
00122             angle = getAngleToPoint(-GOAL_X + 1.5, -GOAL_Y);
00123         if (Math.abs (angle) >= MAX_ANGLE && !World.NewData){
00124           Communicator.turn (angle);
00125                   return 0;
00126         }
00127         // go to the middle of the goal
00128         double dist = calcDist(-GOAL_X + 1.5, -GOAL_Y, myX, myY);
00129             if (Math.abs (dist) >= MAX_DIST){
00130               Communicator.dash (dashPower(dist));
00131                   return 0;
00132         }
00133         return 0; 
00134           }
00135         }
00136         // Don't know where the ball is         
00137         else{
00138         if (inField (myX, myY)){
00139               // get destination point
00140                   double x = -GOAL_X + 1.5;
00141                   double y = 0; //ballX*(14/68);
00142                   // turn to destination point
00143                   double dist = calcDist(x, y, myX, myY);
00144                   angle = getAngleToPoint(x, y);
00145           if ((Math.abs (angle) >= MAX_ANGLE && !World.NewData) && (Math.abs (dist) >= MAX_DIST)){        
00146             Communicator.turn (angle);
00147                     return 0;
00148           }
00149           // go to destination point
00150               if (Math.abs (dist) >= MAX_DIST){         
00151                 Communicator.dash (dashPower(dist)*0.5);
00152                     return 0;
00153           }
00154        }  
00155         else{
00156           angle = getAngleToPoint(-GOAL_X + 1.5, -GOAL_Y);
00157           if (Math.abs (angle) >= MAX_ANGLE && !World.NewData){
00158             Communicator.turn (angle);
00159                     return 0;
00160           }
00161           // go to the middle of the goal
00162           double dist = calcDist(-GOAL_X + 1.5, -GOAL_Y, myX, myY);
00163               if (Math.abs (dist) >= MAX_DIST){
00164                 Communicator.dash (dashPower(dist));
00165                     return 0;
00166           }
00167         }                       
00168       // turn to see the ball
00169           if (!World.NewData){
00170             Communicator.turn (SEARCH_ANGLE);
00171                 return 0;
00172           }
00173           else
00174           return 0;     
00175     } 
00176   }
00177 
00184   public RCGoalieBrain (RCWorld World, RCCommunicator Communicator)
00185   {
00186         super(World, Communicator);
00187   }
00188         
00189 }

(c) Copyright by Gruppe 1 :
  • Frederik Transier
  • Motitz Ritter
  • Oliver Strassburger
  • Sven Stork