@Test public void testMove() { final Position pos = new Position((byte) 50, (byte) 50, 1); final Position target = new Position((byte) 60, (byte) 60, 1); moveTest(pos, target, Heading.WEST, Heading.SOUTH); moveTestCharacter(pos, target, Heading.WEST, Heading.SOUTH); target.setY((byte) 20); moveTest(pos, target, Heading.WEST, Heading.NORTH); moveTestCharacter(pos, target, Heading.WEST, Heading.NORTH); target.setX((byte) 20); moveTest(pos, target, Heading.EAST, Heading.NORTH); moveTestCharacter(pos, target, Heading.EAST, Heading.NORTH); target.setY((byte) 60); moveTest(pos, target, Heading.EAST, Heading.SOUTH); moveTestCharacter(pos, target, Heading.EAST, Heading.SOUTH); }
@Override public Heading move(Position pos) { if (targetCharacter != null) { targetPosition = targetCharacter.getPosition(); } int x = (int) pos.getX() - targetPosition.getX(); int y = (int) pos.getY() - targetPosition.getY(); if (x < 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.EAST; } else if (x > 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.WEST; } else if (x > 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.WEST; } else if (x < 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.EAST; } else if (x == 0 && y < 0) { return Heading.NORTH; } else if (x == 0 && y > 0) { return Heading.SOUTH; } else if (x > 0 && y == 0) { return Heading.WEST; } else if (x < 0 && y == 0) { return Heading.EAST; } return null; }
GreedyMovementStrategy implements MovementStrategy { @Override public Heading move(Position pos) { if (targetCharacter != null) { targetPosition = targetCharacter.getPosition(); } int x = (int) pos.getX() - targetPosition.getX(); int y = (int) pos.getY() - targetPosition.getY(); if (x < 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.EAST; } else if (x > 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.WEST; } else if (x > 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.WEST; } else if (x < 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.EAST; } else if (x == 0 && y < 0) { return Heading.NORTH; } else if (x == 0 && y > 0) { return Heading.SOUTH; } else if (x > 0 && y == 0) { return Heading.WEST; } else if (x < 0 && y == 0) { return Heading.EAST; } return null; } }
GreedyMovementStrategy implements MovementStrategy { @Override public Heading move(Position pos) { if (targetCharacter != null) { targetPosition = targetCharacter.getPosition(); } int x = (int) pos.getX() - targetPosition.getX(); int y = (int) pos.getY() - targetPosition.getY(); if (x < 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.EAST; } else if (x > 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.WEST; } else if (x > 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.WEST; } else if (x < 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.EAST; } else if (x == 0 && y < 0) { return Heading.NORTH; } else if (x == 0 && y > 0) { return Heading.SOUTH; } else if (x > 0 && y == 0) { return Heading.WEST; } else if (x < 0 && y == 0) { return Heading.EAST; } return null; }  }
GreedyMovementStrategy implements MovementStrategy { @Override public Heading move(Position pos) { if (targetCharacter != null) { targetPosition = targetCharacter.getPosition(); } int x = (int) pos.getX() - targetPosition.getX(); int y = (int) pos.getY() - targetPosition.getY(); if (x < 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.EAST; } else if (x > 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.WEST; } else if (x > 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.WEST; } else if (x < 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.EAST; } else if (x == 0 && y < 0) { return Heading.NORTH; } else if (x == 0 && y > 0) { return Heading.SOUTH; } else if (x > 0 && y == 0) { return Heading.WEST; } else if (x < 0 && y == 0) { return Heading.EAST; } return null; }  @Override Heading move(Position pos); @Override void setTarget(Character target); @Override void setTarget(Position pos); }
GreedyMovementStrategy implements MovementStrategy { @Override public Heading move(Position pos) { if (targetCharacter != null) { targetPosition = targetCharacter.getPosition(); } int x = (int) pos.getX() - targetPosition.getX(); int y = (int) pos.getY() - targetPosition.getY(); if (x < 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.EAST; } else if (x > 0 && y < 0) { return randomGenerator.nextInt(2) == 0 ? Heading.NORTH : Heading.WEST; } else if (x > 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.WEST; } else if (x < 0 && y > 0) { return randomGenerator.nextInt(2) == 0 ? Heading.SOUTH : Heading.EAST; } else if (x == 0 && y < 0) { return Heading.NORTH; } else if (x == 0 && y > 0) { return Heading.SOUTH; } else if (x > 0 && y == 0) { return Heading.WEST; } else if (x < 0 && y == 0) { return Heading.EAST; } return null; }  @Override Heading move(Position pos); @Override void setTarget(Character target); @Override void setTarget(Position pos);  }