Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Method to calculate the enemies next move relative to the board state.
- *
- * @return enemies new position on the board.
- */
- @Override
- public Point2D getNextMove() {
- int currentX = (int) position.getX();
- int currentY = (int) position.getY();
- Point2D nextMove = null;
- numberOfChecks = 0;
- System.out.println("has to redirect: " + hasToRedirect);
- switch(direction) {
- case "U":
- if(currentMapState[currentY - 1][currentX].getClass() != Ground.class) {
- hasToRedirect = true;
- hasRedirected = false;
- if(currentMapState[currentY][currentX - 1].getClass() == Ground.class) {
- nextMove = new Point2D(-1,0);
- } else if(currentMapState[currentY][currentX + 1].getClass() == Ground.class) {
- nextMove = new Point2D(1,0);
- } else return new Point2D(0,1);
- }
- if(nextMove == null) {
- nextMove = checkUpLeft(currentX, currentY);
- }
- break;
- case "D":
- if(currentMapState[currentY + 1][currentX].getClass() != Ground.class) {
- hasToRedirect = true;
- hasRedirected = false;
- if(currentMapState[currentY][currentX + 1].getClass() == Ground.class) {
- nextMove = new Point2D(+1,0);
- } else if(currentMapState[currentY][currentX - 1].getClass() == Ground.class) {
- nextMove = new Point2D(-1,0);
- } else return new Point2D(0,-1);
- }
- if(nextMove == null) {
- nextMove = checkDownRight(currentX, currentY);
- }
- break;
- case "R":
- if(currentMapState[currentY][currentX + 1].getClass() != Ground.class) {
- hasToRedirect = true;
- hasRedirected = false;
- if(currentMapState[currentY + 1][currentX].getClass() == Ground.class) {
- nextMove = new Point2D(0,1);
- } else if(currentMapState[currentY - 1][currentX].getClass() == Ground.class) {
- nextMove = new Point2D(0,-1);
- } else return new Point2D(-1,0);
- }
- if(nextMove == null) {
- nextMove = checkUpRight(currentX, currentY);
- }
- break;
- case "L":
- if(currentMapState[currentY][currentX - 1].getClass() != Ground.class) {
- hasToRedirect = true;
- hasRedirected = false;
- if(currentMapState[currentY - 1][currentX].getClass() == Ground.class) {
- nextMove = new Point2D(0,-1);
- } else if(currentMapState[currentY + 1][currentX].getClass() == Ground.class) {
- nextMove = new Point2D(0,1);
- } else return new Point2D(1,0);
- }
- if(nextMove == null) {
- nextMove = checkDownLeft(currentX, currentY);
- }
- break;
- }
- System.out.println(numberOfChecks);
- if(nextMove != null) {
- return nextMove;
- } else {
- switch(direction) {
- case "U": return new Point2D(0, -1);
- case "D": return new Point2D(0, 1);
- case "R": return new Point2D(1, 0);
- case "L": return new Point2D(-1, 0);
- }
- return new Point2D(0,0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement