package ecse321.fall2014.group3.bomberman.physics.ai;

import java.util.Random;
import java.util.Set;

import com.flowpowered.math.vector.Vector2f;

import ecse321.fall2014.group3.bomberman.physics.entity.mob.Mob;
import ecse321.fall2014.group3.bomberman.physics.entity.mob.Player;
import ecse321.fall2014.group3.bomberman.world.Map;
import ecse321.fall2014.group3.bomberman.world.tile.Tile;

/**
 *
 */
public class DumbAI extends AI {
   public DumbAI(Mob target) {
      super(target);
   }

   @Override
   public Vector2f nextPosition(long dt, Map map, Player player) {
      float timeSec = dt / TO_SECS;
      Set<Tile> colTiles = target.getTileCollisionList();

      if ((target.getVelocity()).length() == 0) {
         return target.getPosition();
      } else if (colTiles.isEmpty()) {
         Random random = new Random();
         switch (random.nextInt(4)) {
            case 0:
               return (target.getPosition()).sub((target.getVelocity()).getX() * timeSec, 0f);
            case 1:
               return (target.getPosition()).sub(0f, (target.getVelocity()).getY() * timeSec);
            case 2:
               return (target.getPosition()).add(0f, (target.getVelocity()).getY() * timeSec);
            case 3:
               return (target.getPosition()).add((target.getVelocity()).getX() * timeSec, 0f);
         }
      } else {
         boolean frontCollide = false;

         for (Tile tile : colTiles) {
            if ((tile.getPosition()).dot(target.getPosition()) > 0) {
               frontCollide = true;
            }
         }

         if (frontCollide) {
            Random random = new Random();
            switch (random.nextInt(3)) {
               case 0:
                  return (target.getPosition()).add(0f, (target.getVelocity()).getY() * timeSec);
               case 1:
                  return (target.getPosition()).sub(0f, (target.getVelocity()).getY() * timeSec);
               case 2:
                  return (target.getPosition()).sub((target.getVelocity()).getX() * timeSec, 0f);
            }
         }
      }
      return target.getPosition();
   }
}

@@ -604,16 +604,113 @@
 O_SECS;%0A
+      Vector2f enemyPos = target.getPosition();%0A      Vector2f eVelocity = target.getVelocity();%0A
       Se
@@ -770,35 +770,25 @@
     if (
-(target.get
+e
 Velocity
 ()).leng
@@ -779,19 +779,16 @@
 Velocity
-())
 .length(
@@ -813,36 +813,24 @@
  return 
-target.getPosition()
+enemyPos
 ;%0A      
@@ -985,54 +985,30 @@
 urn 
-(target.getPosition()).sub((target.get
+enemyPos.sub(e
 Velocity
 ()).
@@ -995,35 +995,32 @@
 os.sub(eVelocity
-())
 .getX() * timeSe
@@ -1073,58 +1073,34 @@
 urn 
-(target.getPosition()).sub(0f, (target.get
+enemyPos.sub(0f, e
 Velocity
 ()).
@@ -1087,35 +1087,32 @@
 ub(0f, eVelocity
-())
 .getY() * timeSe
@@ -1161,58 +1161,34 @@
 urn 
-(target.getPosition()).add(0f, (target.get
+enemyPos.add(0f, e
 Velocity
 ()).
@@ -1175,35 +1175,32 @@
 dd(0f, eVelocity
-())
 .getY() * timeSe
@@ -1249,54 +1249,30 @@
 urn 
-(target.getPosition()).add((target.get
+enemyPos.add(e
 Velocity
 ()).
@@ -1259,35 +1259,32 @@
 os.add(eVelocity
-())
 .getX() * timeSe
@@ -1436,36 +1436,24 @@
 ()).dot(
-target.getPosition()
+enemyPos
 ) %3E 0) %7B
@@ -1679,58 +1679,34 @@
 urn 
-(target.getPosition()).add(0f, (target.get
+enemyPos.add(0f, e
 Velocity
 ()).
@@ -1693,35 +1693,32 @@
 dd(0f, eVelocity
-())
 .getY() * timeSe
@@ -1773,58 +1773,34 @@
 urn 
-(target.getPosition()).sub(0f, (target.get
+enemyPos.sub(0f, e
 Velocity
 ()).
@@ -1791,27 +1791,24 @@
 f, eVelocity
-())
 .getY() * ti
@@ -1867,54 +1867,30 @@
 urn 
-(target.getPosition()).sub((target.get
+enemyPos.sub(e
 Velocity
 ()).
@@ -1885,19 +1885,16 @@
 Velocity
-())
 .getX() 

Put target.getPosition() & target.getVelocity into vars for easier reading