public void testMoveRoverFromBottomLeftCornerToTopRightCorner() throws Exception { // Create a Finder with a large search distance (will never be reached) this.finder = new AStarPathFinder(map, 500, true); this.selectedx = 0; this.selectedy = 0; this.map.clearVisited(); this.path = finder.findPath(new RoverMover(map.getUnit(selectedx, selectedy)), selectedx, selectedy, 2, 6); if (this.path != null) { for (int i = 0; i < this.path.getLength(); i++) { Log.i("test", "Current step " + this.path.getStep(i).getX() + ", " + this.path.getStep(i).getY()); } } else { throw new AStarSearchTestCaseFailureException("Null path."); } }
public Map(String ref) throws SlickException { super(ref); // Start the Rectangles Array List tiles = new ArrayList<Tile>(); // Setup blocked tiles blocked = new boolean[this.getWidth()][this.getHeight()]; for(int i = 0; i < this.getWidth(); i++) { for(int j = 0; j < this.getHeight(); j++) { int tileID = getTileId(i, j, 1); String value = getTileProperty(tileID, "blocked", "false"); if(value.equals("true")) { blocked[i][j] = true; tiles.add(new Tile((float)i * 16f, (float)j * 16f, 16f, 16f)); } } } // PathFinding pathFinder = new AStarPathFinder(this, super.getWidth() * super.getHeight(), false); }
private void initWorld(int w, int h) { floor = new boolean[w][h]; walls = new boolean[w][h]; item = new boolean[w][h]; saw = new boolean[w][h]; tiles = new Image[w][h]; clear(); Generator g = new Generator(w, h); g.generate(this); // set world limit setWidth(w * G.TILE_SIZE * 10); setHeight(h * G.TILE_SIZE * 10); // init gui gui = new Gui(this); // set camera camera = new Camera(this, G.playerEntity, container.getWidth(), container.getHeight(), 400, 400, new Vector2f(32, 32)); camera.setFollow(G.playerEntity); G.world = this; pathFinder = new AStarPathFinder(this, 100, false); if (G.currentLevel == 1) { gui.addMessage("Welcome to CryptoRl 2 !"); } alphaMap = ResourceManager.getImage("light"); }
public Maze(int width, int height) throws SlickException { this.width = width; this.height = height; startingX = 1; startingY = 0; endingX = width - 3; endingY = height - 2; // Start the Rectangles Array List tiles = new ArrayList<Tile>(); tileImage = new Image("/res/1x1.png"); tileImage.setFilter(Image.FILTER_NEAREST); // Setup the Map blocked = new boolean[width][height]; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { blocked[i][j] = true; } } // Starting and ending positions are not blocked! blocked[startingX][startingY] = false; blocked[endingX][endingY] = false; // PathFinding pathFinder = new AStarPathFinder(this, width * height, false); // Create the maze createMaze(); // Create the Tiles refreshTiles(); }
/** * Create a new npc controller. * * @param gameController * The GameController to be used. * @param model * The model that this controller should control. * @param map * The tile based map to be used. */ AbstractNpcController(GameController gameController, AbstractNpcModel model, TileBasedMap map) { super(gameController); this.setPathFinder(new AStarPathFinder(map, 500, true)); this.setModel(model); this.setView(new CharacterView(model)); this.setDefaultTiles(model.getMinTileX(), model.getMaxTileX(), model.getMinTileY(), model.getMaxTileY()); this.pauseTime = 0; }
public Pathfinder(Person p) { this.p = p; pmap = new BooleanPathfindingMap(p, 10);//perception of 10, the person can see 10 positions ahead to detect mobile obstacles pathfinder = new AStarPathFinder(pmap, 10000, true);//plan with no more than 1000 steps,diagonal movement allowed Logger.getLogger(Pathfinder.class.getName()).setLevel(Level.WARNING);//change to info for more details about pathfinding }
/** * Creates the map. Reads from Tiled and sets an offset according to the camera * @param ref * @param tileSetsLocation * @param xOffset * @param yOffset * @throws SlickException */ public Map(String ref, String tileSetsLocation, int xOffset, int yOffset) throws SlickException { // Starts the base Map super(ref, tileSetsLocation); // Defines the X and Y render positions this.xOffset = xOffset; this.yOffset = yOffset; // Creates the Blocked and Playable Tiles blocked = new boolean[getWidth()][getHeight()]; playable = new boolean[getWidth()][getHeight()]; walls = new ArrayList<Wall>(); floors = new ArrayList<Floor>(); // Creates the Game Tiles gameTiles = new GameTile[getWidth()][getHeight()]; // Spawn point spawnPoint = new Tile(13, 13); // These attributes store the tiles the user is pointing at xTileAtMouse = 0; yTileAtMouse = 0; // PathFinding pathFinder = new AStarPathFinder(this, super.getWidth() * super.getHeight(), false); // This will create the map, unblock/block the Tiles and set the polygon Shapes for every Tile for (int xTile = 0; xTile < getWidth(); xTile++) { for(int yTile = 0; yTile < getHeight(); yTile++) { // Read the Tilemap File for Playable Tiles String playableValue = getTileProperty(getTileId(xTile, yTile, FLOOR), "playable", "false"); playable[xTile][yTile] = playableValue.equals("true"); // Blocked? blocked[xTile][yTile] = !playable[xTile][yTile]; // Defines the xi and yi relative positions of each polygon float tileXPos = (tileWidth / 2 * xTile) - (tileWidth / 2 * yTile); float tileYPos = (tileHeight / 2 * xTile) + (tileHeight / 2 * yTile); // Math to form the polygon gameTiles[xTile][yTile] = new GameTile( // Isometric rendering tileXPos, tileYPos + tileHeight / 2, // x0, y0 tileXPos + tileWidth / 2, tileYPos, // x1, y1 tileXPos + tileWidth, tileYPos + tileHeight / 2, // x2, y2 tileXPos + tileWidth / 2, tileYPos + tileHeight); // x3, y3 } } // Generate the Map walls and floor updateMapLimits(); }
public VehiclePathfinder(World world) { this.pathfinder = new AStarPathFinder(world, MAX_SEARCH_DISTANCE, true, new ClosestHeuristic()); }
public InfantryPathfinder(World world) { this.pathfinder = new AStarPathFinder(world, MAX_SEARCH_DISTANCE, true, new ClosestHeuristic()); }
public AStarPathFinder getPathFinder() { return pathFinder; }
public void setPathFinder(AStarPathFinder pathFinder) { this.pathFinder = pathFinder; }
public static void main(String[] args) { SimpleMap map = new SimpleMap(); /** documentation at: http://slick.ninjacave.com/javadoc/org/newdawn/slick/util/pathfinding/AStarPathFinder.html */ AStarPathFinder pathFinder = new AStarPathFinder(map, MAX_PATH_LENGTH, false); Path path = pathFinder.findPath(null, START_X, START_Y, GOAL_X, GOAL_Y); int length = path.getLength(); System.out.println("Found path of length: " + length + "."); for(int i = 0; i < length; i++) { System.out.println("Move to: " + path.getX(i) + "," + path.getY(i) + "."); } }
public PathfinderChecker(String pathScenario) { Ubik u= new Ubik(1); u.setPathScenario(pathScenario); u.init(); String s= "Scenario checked: " + pathScenario + "\n"; int np= (u.getBuilding().getFloor(0).getPersonHandler().getPersons()).size(); if(np==0) { s+="Add some person for a thorough inform \n"; return; } s+= "Persons included: " + np + "\n"; Person p=(u.getBuilding().getFloor(0).getPersonHandler().getPersons()).get(0); List<Room> lr= PositionTools.getRooms(p); s+= "List of Rooms included: \n"; for(Room r: lr){ s+="\t" + r.getName()+ "\n"; } BooleanPathfindingMap pmap = new BooleanPathfindingMap(p, 10);//perception of 10, the person can see 10 positions ahead to detect mobile obstacles AStarPathFinder pathfinder = new AStarPathFinder(pmap, maxSteps, true);//plan with no more than 1000 steps,diagonal movement allowed List<String> nrr=new ArrayList<String>(); //non reachable rooms for(Room r1: lr){ for(Room r2:lr){ if(lr.indexOf(r1)<lr.indexOf(r2)){//if r1 reaches r2, r2 also reaches r1 //check reachability Path path = pathfinder.findPath(null, r1.getCenter().x, r1.getCenter().y, r2.getCenter().x, r2.getCenter().y); //get path LOG.info("Reachability " + r1.getName() + " to " + r2.getName() + " checked"); if(path==null) nrr.add(r1.getName() + " <-> " + r2.getName()); } } } if(nrr.isEmpty()) s+="All rooms are reachable!"; else{ s+= "Not reachable rooms with " + maxSteps + " steps: \n"; for(String nonreachable: nrr){ s+="\t" + nonreachable + "\n"; } } inform=s; }
/** * Set path finder * * @param pathFinder * the pathfinder to use */ void setPathFinder(AStarPathFinder pathFinder) { this.myPathFinder = pathFinder; }
/** * get current pathfinder * * @return the active pathfinder */ AStarPathFinder getPathFinder() { return myPathFinder; }
public AStarPathFinder getPathFinder() {return pathFinder;}