Esempio n. 1
0
 public void ask(float inOne, float inTwo) {
   brain.setInput(0, inOne);
   brain.setInput(1, inTwo);
   brain.feedForward();
   // p.println(id + ": " + "output 0   " + brain.getOutput(0));
   // p.println(id + ": " + "output 1   " + brain.getOutput(1));
 }
Esempio n. 2
0
 /**
  * Creates the brain and launches if it is an agent. The brain class is given as a String. The
  * name argument is used to instantiate the name of the corresponding agent. If the gui flag is
  * true, a bean is created and associated to this agent.
  */
 public void makeBrain(String className, String name, boolean gui, String behaviorFileName) {
   try {
     Class c;
     c = Utils.loadClass(className);
     myBrain = (Brain) c.newInstance();
     myBrain.setBody(this);
     if (myBrain instanceof AbstractAgent) {
       String n = name;
       if (n == null) {
         n = getLabel();
       }
       if (n == null) {
         n = getID();
       }
       if (behaviorFileName != null) setBehaviorFileName(behaviorFileName);
       myBrain.init();
       getStructure().getAgent().doLaunchAgent((AbstractAgent) myBrain, n, gui);
     }
   } catch (ClassNotFoundException ev) {
     System.err.println("Class not found :" + className + " " + ev);
     ev.printStackTrace();
   } catch (InstantiationException e) {
     System.err.println("Can't instanciate ! " + className + " " + e);
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     System.err.println("illegal access! " + className + " " + e);
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 /* Initialization of a mobile entity.
  *	 Takes its brain class and tries to instantiate an
  *	 agent with this brain class if it is not null.
  *	 Sets its speed = speedMax.
  */
 public void init() {
   // setSpeed(getMaxSpeed());
   super.init();
   String s = getBrainClass();
   if (s != null) {
     makeBrain(s, null, false, getBehaviorFileName());
     myBrain.requestRole(this.getTeam(), this.getName(), null);
     int r = myBrain.requestRole(simulationGroup, "brain", WarbotIdentifier.password);
   }
 }
Esempio n. 4
0
 public int waves_over(double x, double y) {
   int current_waves = 0;
   for (WaveModel wave : surf_bum) {
     // System.out.println("Evaluating distance");
     double distance_early = Brain.distance(wave.early_origin_x, wave.early_origin_y, x, y);
     double distance_late = Brain.distance(wave.late_origin_x, wave.late_origin_y, x, y);
     // System.out.println("early distance "+distance_early+" <= "+wave.early_radius);
     // System.out.println("late distance  "+distance_late+" >= "+wave.late_radius);
     if (distance_early >= wave.early_radius && distance_late <= wave.late_radius) {
       current_waves++;
       // System.out.println("waves overlap "+current_waves);
     }
   }
   return current_waves;
 }
 /**
  * The generic activators of entities. If there is brain, this brain is activated via the doIt
  * method.
  */
 public void doIt() {
   beforeDoIt();
   if (myBrain != null) {
     myBrain.doIt();
   } else bodyDoIt();
   afterDoIt();
 }
 /** Delete an entity, and its brain if there is one. Do not ask directly this method. */
 public void delete() {
   // System.out.println("Actually deleting " + this);
   if (deleted) return;
   deleted = true;
   if (myBrain != null) {
     if (myBrain instanceof AbstractAgent)
       getStructure().getAgent().doKillAgent((AbstractAgent) myBrain);
     else myBrain.delete();
   }
   super.delete();
 }
 private Piece getWorstPiece(boolean hurt_player) {
   Brain.Move wMove = null;
   Brain.Move tMove;
   int index = 0;
   for (int i = 0; i < pieces.length; i++) {
     tMove = mBrain.bestMove(board, pieces[i], board.getHeight() - TOP_SPACE, null);
     if (i == 0) wMove = tMove;
     if (tMove == null) { // this piece loses the game now
       return pieces[i];
     }
     if ((hurt_player && tMove.score >= wMove.score)
         || (!hurt_player && tMove.score <= wMove.score)) {
       wMove = tMove;
       index = i;
     }
   }
   return pieces[index];
 }
  public void tick(int verb) {
    if (brainPlay.isSelected()) {
      board.undo();
      if (verb == DOWN) {
        if (cur_count != super.count) {
          mMove = mBrain.bestMove(board, currentPiece, board.getHeight() - TOP_SPACE, mMove);
          cur_count = super.count;
        }
        if (mMove == null || mMove.piece == null || currentPiece == null) {
          stopGame();
          return; // game over
        }
        if (!currentPiece.equals(mMove.piece)) super.tick(ROTATE);

        if (currentX < mMove.x) super.tick(RIGHT);
        if (currentX > mMove.x) super.tick(LEFT);
      }
    }
    super.tick(verb);
  }
Esempio n. 9
0
 //////////////////////////////////////  SYSTEM METHODS
 public final void delete() {
   System.out.println("I'm dead !!! ");
   if (myBrain != null) myBrain.delete();
   super.delete();
 }
Esempio n. 10
0
 /*
  * void teach(float getIn, float getOut, int i) { for (int i = 0;
  * i<repeat_teaching; i++) { brain.setInput(i, getIn); //recebe input
  * brain.setOutput(i.getOut);// e output brain.feedForward();
  * brain.backPropagate(); // e "ensina" } }
  */
 public void teach(float in, int i) {
   brain.setDesiredOutput(i, in);
   brain.feedForward();
   brain.backPropagate();
 }
Esempio n. 11
0
 // /////////////////////////////////////////////////////////////////////////////////////////
 // BRAIN FUNCTIONS
 // TODO: implementar esses métodos em brainActions().
 public void train() {
   for (int i = 0; i < repeat_teaching; i++) {
     float r = p.random(1);
     if (r < 0.25f) {
       brain.setInput(0, p.random(0.5f, 1f));
       brain.setInput(1, p.random(0.5f, 1f));
       brain.setDesiredOutput(0, 1f);
       brain.setDesiredOutput(1, 0f);
       brain.feedForward();
       brain.backPropagate();
     } else if (r >= 0.25f && r < 0.5f) {
       brain.setInput(0, p.random(0f, 0.5f));
       brain.setInput(1, p.random(0f, 0.5f));
       brain.setDesiredOutput(0, 0.5f);
       brain.setDesiredOutput(1, 0.5f);
       brain.feedForward();
       brain.backPropagate();
     } else if (r >= 0.5f && r < 0.75f) {
       brain.setInput(0, p.random(0.5f, 1f));
       brain.setInput(1, p.random(0f, 0.5f));
       brain.setDesiredOutput(0, 0.5f);
       brain.setDesiredOutput(1, 0.5f);
       brain.feedForward();
       brain.backPropagate();
     } else {
       brain.setInput(0, p.random(0f, 0.5f));
       brain.setInput(1, p.random(0f, 0.5f));
       brain.setDesiredOutput(0, 0f);
       brain.setDesiredOutput(1, 0f);
       brain.feedForward();
       brain.backPropagate();
     }
   }
 }
Esempio n. 12
0
 // TODO: acções baseadas nos outputs da rede neural.
 void brainAction() {
   if (brain.getOutput(0) > 0.5) {
     // walkTogheter();
   }
 }
Esempio n. 13
0
 public void process() {
   // super.process();
   // run the default process first, so that it will always generate some movement
   // then update all of the waves to the most up to date time and location
   check_surf();
   // System.out.println(" tracking "+surf_bum.size()+" waves");
   long current_time = robot.getTime();
   for (int i = 0; i < surf_bum.size(); i++) {
     update(surf_bum.get(i), current_time);
   }
   if (robot.getTurnRemainingRadians() <= .01) {
     double[] output = inner_points_test(long_points_test());
     double desired_math_heading = Math.atan2(robot.getY() - output[1], robot.getX() - output[0]);
     System.out.println("desired math = " + desired_math_heading);
     double desired_heading = (-desired_math_heading + Math.PI / 2);
     double current_heading = robot.getHeadingRadians();
     moveEndTheta = (desired_heading - current_heading) % (2 * Math.PI);
     System.out.println("move End Theta = " + moveEndTheta);
     moveEndDistance = Brain.distance(output[0], output[1], robot.getX(), robot.getY());
   }
   // TODO IDEAPAD
   /*
    * The robot should test 32 points at radius of 50 around itself, and evaluate
    * 	based on the waves washing over that point.
    * 	This uses a similar function to below, with distance from current heading being good
    * 	divided by the number of waves washing over
    *  	f: (1-cos(delta angle)/2*(waves+1)
    *
    * The bearing to that point is stored.
    * Then randomly generate 8 points at random that are at less than 50 units away
    *  , and rate them based on how close they are in bearing to the first point
    *  (cos of delta bearing) and wave crossings (sum of waves washing over) for a
    *  	f: cos(bearing_50-bearing_8)/(num of waves+1).
    *
    * 	Use a move to point function to move to the interior point
    * 	with the highest rating
    *
    * 	TODO implement this first. It shouldn't be to hard,
    *  //DONE create a function that takes a point and counts wave overlap
    *  //DONE Then create a function that generates outer points, tests and returns the
    *  	optimal outer point bearing
    *  //DONE From there, use a different function to generate random inner points (8<=d<50),
    *  	choose the best one, and then output the point to move to.
    *  //DONE displaying all wave data, appears to be functioning
    *  TODO display movement data
    */
   // TODO Improvements
   /*
    * Filter our waves that are not from shootings (recharge time, etc)
    * Other sources:
    * 		Walls
    * 		Self-bullet contacts
    * 		Other bullet contacts
    * 		Ramming
    *
    * Stay away from other robots
    * 		robot size ~= 40, move speed 8
    * 		needs 5++ turns to get out of it's own way
    * 		bullets travel at max 20
    * 		have the robot try to avoid being closer than 140-160 from other robots
    * 		This gives "reaction time" to wave of 7-8 turns
    */
 }