private List<Point> fillAvailablePointsToMoveNearAttackedUnit(List<Point> availablePointsToMove) { Point testPoint; testPoint = attackedUnit.getPos().getCopy(); testPoint.setY(testPoint.getY() + 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setX(testPoint.getX() + 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setY(testPoint.getY() - 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setX(testPoint.getX() - 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } Collections.shuffle(availablePointsToMove); return availablePointsToMove; }
private Point getClosestOpenPointToAttackedUnit() { List<Point> availablePointsToMove = new ArrayList<Point>(); fillAvailablePointsToMoveNearAttackedUnit(availablePointsToMove); Point openPoint = null; for (Point point : availablePointsToMove) { if (openPoint == null || Point.getManhattanDistance(openPoint, unit.getPos()) > Point.getManhattanDistance(point, unit.getPos())) { openPoint = point; } } return openPoint; }