Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1.  /**
  2.      * Method to calculate the enemies next move relative to the board state.
  3.      *
  4.      * @return enemies new position on the board.
  5.      */
  6.     @Override
  7.     public Point2D getNextMove() {
  8.  
  9.         int currentX = (int) position.getX();
  10.         int currentY = (int) position.getY();
  11.         Point2D nextMove = null;
  12.         numberOfChecks = 0;
  13.         System.out.println("has to redirect: " + hasToRedirect);
  14.  
  15.         switch(direction) {
  16.             case "U":
  17.                 if(currentMapState[currentY - 1][currentX].getClass() != Ground.class) {
  18.                     hasToRedirect = true;
  19.                     hasRedirected = false;
  20.                     if(currentMapState[currentY][currentX - 1].getClass() == Ground.class) {
  21.                         nextMove = new Point2D(-1,0);
  22.                     } else if(currentMapState[currentY][currentX + 1].getClass() == Ground.class) {
  23.                         nextMove = new Point2D(1,0);
  24.                     } else return new Point2D(0,1);
  25.                 }
  26.  
  27.                 if(nextMove == null) {
  28.  
  29.                     nextMove = checkUpLeft(currentX, currentY);
  30.                 }
  31.  
  32.             break;
  33.  
  34.             case "D":
  35.                 if(currentMapState[currentY + 1][currentX].getClass() != Ground.class) {
  36.                     hasToRedirect = true;
  37.                     hasRedirected = false;
  38.                     if(currentMapState[currentY][currentX + 1].getClass() == Ground.class) {
  39.                         nextMove = new Point2D(+1,0);
  40.                     } else if(currentMapState[currentY][currentX - 1].getClass() == Ground.class) {
  41.                         nextMove = new Point2D(-1,0);
  42.                     } else return new Point2D(0,-1);
  43.                 }
  44.  
  45.                 if(nextMove == null) {
  46.                     nextMove = checkDownRight(currentX, currentY);
  47.                 }
  48.             break;
  49.  
  50.  
  51.             case "R":
  52.                 if(currentMapState[currentY][currentX + 1].getClass() != Ground.class) {
  53.                     hasToRedirect = true;
  54.                     hasRedirected = false;
  55.                     if(currentMapState[currentY + 1][currentX].getClass() == Ground.class) {
  56.                         nextMove = new Point2D(0,1);
  57.                     } else if(currentMapState[currentY - 1][currentX].getClass() == Ground.class) {
  58.                         nextMove = new Point2D(0,-1);
  59.                     } else return new Point2D(-1,0);
  60.                 }
  61.  
  62.                 if(nextMove == null) {
  63.                     nextMove = checkUpRight(currentX, currentY);
  64.                 }
  65.  
  66.             break;
  67.  
  68.             case "L":
  69.                 if(currentMapState[currentY][currentX - 1].getClass() != Ground.class) {
  70.                     hasToRedirect = true;
  71.                     hasRedirected = false;
  72.                     if(currentMapState[currentY - 1][currentX].getClass() == Ground.class) {
  73.                         nextMove = new Point2D(0,-1);
  74.                     } else if(currentMapState[currentY + 1][currentX].getClass() == Ground.class) {
  75.                         nextMove = new Point2D(0,1);
  76.                     } else return new Point2D(1,0);
  77.                 }
  78.  
  79.                 if(nextMove == null) {
  80.                     nextMove = checkDownLeft(currentX, currentY);
  81.                 }
  82.             break;
  83.         }
  84.  
  85.         System.out.println(numberOfChecks);
  86.  
  87.         if(nextMove != null) {
  88.             return nextMove;
  89.         } else {
  90.  
  91.  
  92.  
  93.             switch(direction) {
  94.                 case "U": return new Point2D(0, -1);
  95.  
  96.                 case "D": return new Point2D(0, 1);
  97.  
  98.                 case "R": return new Point2D(1, 0);
  99.  
  100.                 case "L": return new Point2D(-1, 0);
  101.  
  102.             }
  103.             return new Point2D(0,0);
  104.         }
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement