### Complete Game Integration Example Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt A comprehensive example showing grid setup, terrain costs, dynamic obstacle avoidance, and a game loop integration for EasyStar.js. ```javascript var EasyStar = require('easystarjs'); var pathfinder = new EasyStar.js(); var gameMap = [[0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 1, 2, 1, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [3, 3, 3, 2, 3, 3, 3, 3], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]; pathfinder.setGrid(gameMap); pathfinder.setAcceptableTiles([0, 2]); pathfinder.enableDiagonals(); pathfinder.disableCornerCutting(); pathfinder.setTileCost(0, 1.0); pathfinder.setTileCost(2, 0.5); var enemies = [{x: 2, y: 2}, {x: 5, y: 5}]; enemies.forEach(function(enemy) { pathfinder.avoidAdditionalPoint(enemy.x, enemy.y); }); pathfinder.setIterationsPerCalculation(200); var currentPathId = pathfinder.findPath(0, 0, 7, 7, function(path) { if (path) { console.log("Path found! Steps:", path.length); } }); function gameLoop() { pathfinder.calculate(); requestAnimationFrame(gameLoop); } gameLoop(); ``` -------------------------------- ### Install EasyStar.js via Package Managers Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Commands to install the EasyStar.js library using npm or bower package managers. ```bash npm install easystarjs bower install easystarjs ``` -------------------------------- ### Complete Game Integration Example Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt A comprehensive example demonstrating how to integrate EasyStar.js into a game, including setting up the grid, defining costs, avoiding points, and handling path requests within a game loop. ```APIDOC ## Complete Game Integration Example ### Description This example shows a full integration of EasyStar.js into a game scenario, covering map setup, terrain costs, dynamic obstacles, performance tuning, and path request management. ### Method N/A (This is an example demonstrating multiple methods) ### Endpoint N/A ### Request Example ```javascript var EasyStar = require('easystarjs'); // Initialize pathfinder var pathfinder = new EasyStar.js(); // Game map: 0=grass, 1=wall, 2=road, 3=water var gameMap = [ [0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 1, 2, 1, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [3, 3, 3, 2, 3, 3, 3, 3], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0] ]; // Configure pathfinder pathfinder.setGrid(gameMap); pathfinder.setAcceptableTiles([0, 2]); // Can walk on grass and road pathfinder.enableDiagonals(); pathfinder.disableCornerCutting(); // Set terrain costs pathfinder.setTileCost(0, 1.0); // Grass: normal pathfinder.setTileCost(2, 0.5); // Road: faster // Dynamic enemy positions to avoid var enemies = [ {x: 2, y: 2}, {x: 5, y: 5} ]; enemies.forEach(function(enemy) { pathfinder.avoidAdditionalPoint(enemy.x, enemy.y); }); // Set iterations for smooth gameplay pathfinder.setIterationsPerCalculation(200); // Request a path for the player var currentPathId = pathfinder.findPath(0, 0, 7, 7, function(path) { if (path) { console.log("Path found! Steps:", path.length); path.forEach(function(step, i) { console.log(" " + i + ": (" + step.x + ", " + step.y + ")"); }); } else { console.log("No path available!"); } }); // Game loop function gameLoop() { pathfinder.calculate(); requestAnimationFrame(gameLoop); } gameLoop(); // Later: enemy moved, update avoided points function updateEnemyPosition(oldX, oldY, newX, newY) { pathfinder.stopAvoidingAdditionalPoint(oldX, oldY); pathfinder.avoidAdditionalPoint(newX, newY); } // Cancel path if player changes destination function onNewDestination(newX, newY) { if (currentPathId) { pathfinder.cancelPath(currentPathId); } currentPathId = pathfinder.findPath(playerX, playerY, newX, newY, handlePath); } ``` ### Response This example demonstrates the usage of various EasyStar.js methods and does not have a direct API response. The output is logged to the console. ``` -------------------------------- ### Clone Repository and Run Demo (Shell) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Steps to clone the EasyStar.js GitHub repository, navigate to the demo directory, install dependencies, and run the demo application using Node.js. ```shell git clone https://github.com/prettymuchbryce/easystarjs.git cd easystarjs/demo npm install node app.js ``` -------------------------------- ### Install EasyStar via npm (Shell) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Command to install the easystarjs package using npm, the Node Package Manager. This is the standard way to add the library to a Node.js project. ```shell npm install easystarjs ``` -------------------------------- ### Execute Pathfinding Calculations (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Starts the actual pathfinding calculations. This method should be called periodically (e.g., on a game loop or interval) to allow EasyStar to process path requests without blocking the main thread. ```javascript easystar.calculate(); ``` -------------------------------- ### Find Path Asynchronously (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Initiates an asynchronous pathfinding request from a start point to an end point. A callback function is provided to handle the result, which can be a path array or null if no path is found. ```javascript easystar.findPath(0, 0, 4, 0, function( path ) { if (path === null) { alert("Path was not found."); } else { alert("Path was found. The first Point is " + path[0].x + " " + path[0].y); } }); ``` -------------------------------- ### Initialize EasyStar Pathfinding (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Demonstrates how to create a new instance of the EasyStar pathfinding object. This is the first step before configuring grids or finding paths. ```javascript var easystar = new EasyStar.js(); ``` -------------------------------- ### Initialize Easystar Demo and Handle Resize Source: https://github.com/prettymuchbryce/easystarjs/blob/master/demo/views/index.html Initializes the EasystarDemo with the current dimensions of the demo container and sets up a window resize handler to update the demo's dimensions accordingly. This ensures the pathfinding visualization adapts to different screen sizes. ```javascript var easyStarDemo = new EasyStarDemo($('.demo').width(), $('.demo').height()); window.onresize = function() { easyStarDemo.resize( $('.demo').width(), $('.demo').height()); } ``` -------------------------------- ### Initialize EasyStar.js Instance Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Demonstrates how to instantiate the EasyStar pathfinder in both browser and Node.js environments. ```javascript // Browser var easystar = new EasyStar.js(); // Node.js var easystarjs = require('easystarjs'); var easystar = new easystarjs.js(); ``` -------------------------------- ### EasyStar Configuration and Features Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Advanced configuration methods for fine-tuning pathfinding behavior, costs, and constraints. ```APIDOC ## EasyStar.js Advanced Configuration ### Description Methods to modify pathfinding logic, such as enabling diagonals, setting tile costs, and managing performance. ### Configuration Methods - `setIterationsPerCalculation(value)`: Limits the number of iterations per frame to prevent performance bottlenecks. - `enableDiagonals()`: Allows movement along diagonals. - `setTileCost(tileType, cost)`: Sets a multiplicative cost for specific tile types. - `avoidAdditionalPoint(x, y)`: Dynamically marks a point as unwalkable. - `cancelPath(instanceId)`: Cancels a pending path calculation. ### Usage Example ```javascript easystar.enableDiagonals(); easystar.setIterationsPerCalculation(1000); easystar.setTileCost(2, 5.0); // Tile type 2 costs 5x more ``` ``` -------------------------------- ### EasyStar Pathfinding API Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Core methods for initializing the pathfinding engine, defining the grid, and calculating paths. ```APIDOC ## EasyStar.js Core Methods ### Description Initializes the pathfinding engine, configures the grid, and triggers path calculation. ### Methods - `new EasyStar.js()`: Initializes a new instance. - `setGrid(twoDimensionalArray)`: Sets the grid for the pathfinder. - `setAcceptableTiles(arrayOfAcceptableTiles)`: Defines which tile values are walkable. - `findPath(startX, startY, endX, endY, callback)`: Queues a path calculation request. - `calculate()`: Executes the queued path calculations. ### Request Example ```javascript var easystar = new EasyStar.js(); easystar.setGrid([[0,0,1],[0,0,0]]); easystar.setAcceptableTiles([0]); easystar.findPath(0, 0, 2, 1, function(path) { console.log(path); }); easystar.calculate(); ``` ### Response - **path** (Array) - An array of coordinate objects {x, y} representing the path, or null if no path is found. ``` -------------------------------- ### Require EasyStar for Node.js (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Demonstrates how to import and initialize the EasyStar.js library when using Node.js. This involves using the `require` function to load the module. ```javascript var easystarjs = require('easystarjs'); var easystar = new easystarjs.js(); ``` -------------------------------- ### Run Tests (Shell) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Command to execute the test suite for the EasyStar.js library using npm. ```shell npm run test ``` -------------------------------- ### Enable Synchronous Pathfinding Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Demonstrates how to toggle between synchronous and asynchronous modes. Synchronous mode ensures the path is calculated immediately within the call. ```javascript var easystar = new EasyStar.js(); var grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); easystar.enableSync(); var resultPath = null; easystar.findPath(0, 0, 2, 2, function(path) { resultPath = path; }); easystar.calculate(); console.log("Sync path:", resultPath); easystar.disableSync(); ``` -------------------------------- ### Integrate Path Calculation in Game Loop Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Shows how to integrate the calculate() method into a game loop or interval to ensure pathfinding runs without blocking the main thread. ```javascript function gameLoop() { easystar.calculate(); requestAnimationFrame(gameLoop); } gameLoop(); ``` -------------------------------- ### Configure Pathfinding Grid (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Sets the grid or tilemap that EasyStar will use for pathfinding calculations. The grid is represented as a 2D array where each element corresponds to a tile. ```javascript var grid = [[0,0,1,0,0], [0,0,1,0,0], [0,0,1,0,0], [0,0,1,0,0], [0,0,0,0,0]]; easystar.setGrid(grid); ``` -------------------------------- ### calculate() Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Processes pending pathfinding requests. ```APIDOC ## calculate() ### Description Processes the queue of pending pathfinding requests. This should be called within a game loop to ensure non-blocking performance. ### Request Example ```javascript function gameLoop() { easystar.calculate(); requestAnimationFrame(gameLoop); } ``` ``` -------------------------------- ### Find Path and Process Calculation Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Initiates a pathfinding request between two points and triggers the calculation process, which must be called periodically to handle paths asynchronously. ```javascript easystar.findPath(0, 0, 4, 0, function(path) { if (path === null) { console.log("No path found!"); } else { console.log("Path found with " + path.length + " steps:"); } }); easystar.calculate(); ``` -------------------------------- ### Performance Tuning Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Options for tuning the performance of the pathfinding calculations to balance CPU usage and pathfinding speed. ```APIDOC ## setIterationsPerCalculation(iterations) ### Description Controls how many A* iterations are performed per `calculate()` call. Lower values reduce CPU usage per frame but increase total time to find a path. Higher values find paths faster but may cause frame drops on large grids. ### Method `setIterationsPerCalculation` ### Parameters #### Path Parameters - **iterations** (number) - Required - The maximum number of iterations to perform per calculation. ### Request Example ```javascript var easystar = new EasyStar.js(); var grid = []; for (var i = 0; i < 100; i++) { grid[i] = []; for (var j = 0; j < 100; j++) { grid[i][j] = 1; } } easystar.setGrid(grid); easystar.setAcceptableTiles([1]); // Limit iterations to prevent frame drops easystar.setIterationsPerCalculation(1000); easystar.findPath(0, 0, 99, 99, function(path) { console.log("Path found on large grid:", path.length, "steps"); }); // Call calculate multiple times to process the path gradually var interval = setInterval(function() { easystar.calculate(); }, 16); ``` ### Response This method does not return a value. It configures the pathfinder. ## enableSync() / disableSync() ### Description Enables or disables synchronous mode for path calculations. In synchronous mode, paths are calculated completely within the `calculate()` call, useful for non-interactive scenarios or when the path is needed immediately. ### Method `enableSync`, `disableSync` ### Parameters These methods do not accept any parameters. ### Request Example ```javascript var easystar = new EasyStar.js(); var grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); // Enable synchronous calculation easystar.enableSync(); var resultPath = null; easystar.findPath(0, 0, 2, 2, function(path) { resultPath = path; }); easystar.calculate(); // Path is immediately available after calculate() console.log("Sync path:", resultPath); // Disable sync mode for normal async operation easystar.disableSync(); ``` ### Response These methods do not return a value. They toggle the calculation mode. ``` -------------------------------- ### Enable Diagonal Movement (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Allows the pathfinding algorithm to consider diagonal movements between tiles, in addition to horizontal and vertical movements. ```javascript easystar.enableDiagonals(); ``` -------------------------------- ### Enable Synchronous Calculation (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Forces EasyStar to perform pathfinding calculations synchronously, meaning it will block the main thread until a path is found. Use with caution on large grids. ```javascript easystar.enableSync(); ``` -------------------------------- ### Configure Grid and Walkable Tiles Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets the 2D collision grid and defines which tile values are considered walkable for the pathfinder. ```javascript var easystar = new EasyStar.js(); var grid = [[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]; easystar.setGrid(grid); easystar.setAcceptableTiles([0, 2]); ``` -------------------------------- ### findPath(startX, startY, endX, endY, callback) Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Initiates a request to calculate a path between two points. ```APIDOC ## findPath(startX, startY, endX, endY, callback) ### Description Starts a pathfinding request. The calculation is performed asynchronously when calculate() is called. ### Parameters #### Request Body - **startX** (number) - Required - Starting X coordinate. - **startY** (number) - Required - Starting Y coordinate. - **endX** (number) - Required - Destination X coordinate. - **endY** (number) - Required - Destination Y coordinate. - **callback** (function) - Required - Function executed upon completion, receiving the path array or null. ### Response #### Success Response (200) - **instanceId** (number) - The ID of the pathfinding request, used for cancellation. ``` -------------------------------- ### Optimize Performance with Iteration Limits Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Uses setIterationsPerCalculation to balance CPU usage and pathfinding speed. This prevents frame drops in large grids by spreading the calculation over multiple frames. ```javascript var easystar = new EasyStar.js(); var grid = []; for (var i = 0; i < 100; i++) { grid[i] = []; for (var j = 0; j < 100; j++) { grid[i][j] = 1; } } easystar.setGrid(grid); easystar.setAcceptableTiles([1]); easystar.setIterationsPerCalculation(1000); easystar.findPath(0, 0, 99, 99, function(path) { console.log("Path found on large grid:", path.length, "steps"); }); var interval = setInterval(function() { easystar.calculate(); }, 16); ``` -------------------------------- ### Define Walkable Tiles (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Specifies which tile types are considered 'walkable' by the pathfinding algorithm. Only tiles matching these values will be traversed. ```javascript easystar.setAcceptableTiles([0]); ``` -------------------------------- ### Set Tile Cost (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Assigns a multiplicative cost to specific tile types. This allows certain tiles to be more or less expensive to traverse than others, influencing path selection. ```javascript easystar.setTileCost(2, 2); ``` -------------------------------- ### setAcceptableTiles(tiles) Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Defines which tile values are considered walkable by the pathfinder. ```APIDOC ## setAcceptableTiles(tiles) ### Description Specifies the tile values that the pathfinder is allowed to traverse. ### Parameters #### Request Body - **tiles** (number | Array) - Required - A single tile value or an array of values representing walkable terrain. ### Request Example ```javascript easystar.setAcceptableTiles([0, 2]); ``` ``` -------------------------------- ### Enable Corner Cutting (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Enables a feature where the path can cut across corners of obstacles if the diagonal path is clear, potentially creating shorter and more natural-looking paths. ```javascript easystar.enableCornerCutting(); ``` -------------------------------- ### Avoid/Stop Avoiding Additional Points in Easystar.js Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Marks a specific point (x, y) as completely impassable, regardless of its tile type. This is useful for dynamic obstacles like moving enemies or temporarily blocked paths. The library provides functions to avoid and stop avoiding points, as well as to clear all avoided points. ```javascript var easystar = new EasyStar.js(); var grid = [ [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); // Block the shortest path through (2,3) easystar.avoidAdditionalPoint(2, 3); easystar.findPath(1, 2, 3, 2, function(path) { // Path will route around the avoided point console.log("Path length avoiding (2,3):", path.length); // 7 steps instead of 5 }); // Later, stop avoiding the point easystar.stopAvoidingAdditionalPoint(2, 3); // Clear all avoided points easystar.stopAvoidingAllAdditionalPoints(); easystar.calculate(); ``` -------------------------------- ### setGrid(grid) Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets the 2D collision grid used for pathfinding calculations. ```APIDOC ## setGrid(grid) ### Description Defines the 2D collision grid for the pathfinder. The grid is represented as a 2D array of numbers where each number corresponds to a specific tile type. ### Parameters #### Request Body - **grid** (Array>) - Required - A 2D array representing the map layout. ### Request Example ```javascript easystar.setGrid([[1, 1, 0], [1, 1, 0], [1, 1, 1]]); ``` ``` -------------------------------- ### Set Tile Cost in Easystar.js Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets a multiplicative cost for a specific tile type. Higher costs make the pathfinder prefer other routes. The default cost for all tiles is 1. This impacts pathfinding efficiency by influencing route selection. ```javascript var easystar = new EasyStar.js(); // 0 = grass, 1 = road, 2 = swamp var grid = [ [0, 0, 1, 0, 0], [0, 2, 1, 2, 0], [0, 2, 1, 2, 0], [0, 0, 1, 0, 0] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([0, 1, 2]); // Roads are fast, swamps are slow easystar.setTileCost(0, 1); // grass: normal cost easystar.setTileCost(1, 0.5); // road: half cost (preferred) easystar.setTileCost(2, 3); // swamp: triple cost (avoided) easystar.findPath(0, 0, 4, 0, function(path) { // Path will prefer the road (column 2) over grass or swamp console.log("Optimal path:", path); }); easystar.calculate(); ``` -------------------------------- ### Set Iterations Per Calculation (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Limits the number of pathfinding iterations performed in a single call to `calculate()`. This helps prevent performance issues on large grids by distributing the calculation load over time. ```javascript easystar.setIterationsPerCalculation(1000); ``` -------------------------------- ### Toggle Grass Preference with Bootstrap Switch Source: https://github.com/prettymuchbryce/easystarjs/blob/master/demo/views/index.html Handles the click event for a Bootstrap Switch to toggle the preference for 'dry land' (grass) tiles in Easystar.js. When the switch is on, grass preference is unset; when off, it's set. This affects pathfinding cost calculations. ```javascript $('#check-tile-cost').click(function() { if ($('#check-tile-cost').bootstrapSwitch('status')) { easyStarDemo.unsetGrassPreference(); } else { easyStarDemo.setGrassPreference(); } }); ``` -------------------------------- ### Set Tile Cost Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets a multiplicative cost for a specific tile type. Higher costs make the pathfinder prefer other routes. The default cost is 1. ```APIDOC ## setTileCost(tileType, cost) ### Description Sets a multiplicative cost for a specific tile type. Higher costs make the pathfinder prefer other routes. Default cost is 1. ### Method `setTileCost(tileType, cost)` ### Endpoint N/A (Instance method) ### Parameters - **tileType** (number) - Required - The type of tile to set the cost for. - **cost** (number) - Required - The multiplicative cost for the tile type. A cost of 1 is normal, less than 1 is cheaper, greater than 1 is more expensive. ### Request Example ```javascript var easystar = new EasyStar.js(); // ... setup grid and acceptable tiles ... easystar.setTileCost(0, 1); // grass: normal cost easystar.setTileCost(1, 0.5); // road: half cost (preferred) easystar.setTileCost(2, 3); // swamp: triple cost (avoided) easystar.findPath(0, 0, 4, 0, function(path) { console.log("Optimal path:", path); }); easystar.calculate(); ``` ### Response N/A (Modifies internal state) ### Response Example N/A ``` -------------------------------- ### Enable/Disable Diagonal Movement in Easystar.js Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Enables or disables 8-direction diagonal movement for pathfinding. When enabled, paths can move diagonally between tiles. Diagonal movement is disabled by default. ```javascript var easystar = new EasyStar.js(); var grid = [ [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); easystar.enableDiagonals(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("Diagonal path length:", path.length); // 5 steps (diagonal) // Path: (0,0) -> (1,1) -> (2,2) -> (3,3) -> (4,4) }); easystar.calculate(); ``` -------------------------------- ### Configure Iterations Per Calculation Slider Source: https://github.com/prettymuchbryce/easystarjs/blob/master/demo/views/index.html Initializes a jQuery UI slider to control the 'Iterations Per Calculation' setting for Easystar.js. The slider's value is used to set the asynchrony of the pathfinding algorithm, with the actual value being the cube of the slider's value (min 1, max 4). ```javascript var $slider = $("#slider"); if ($slider.length) { $slider.slider({ min: 1, max: 4, value: 2, orientation: "horizontal", range: "min", change: function( event, ui ) { easyStarDemo.setIterationsPerCalculation(Math.pow(ui.value,3)); } }); } ``` -------------------------------- ### Avoid Additional Point Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Marks a specific point as completely impassable regardless of the tile type. Useful for dynamic obstacles like moving enemies or temporarily blocked paths. ```APIDOC ## avoidAdditionalPoint(x, y) / stopAvoidingAdditionalPoint(x, y) ### Description Marks a specific point as completely impassable regardless of the tile type. Useful for dynamic obstacles like moving enemies or temporarily blocked paths. ### Method `avoidAdditionalPoint(x, y)` / `stopAvoidingAdditionalPoint(x, y)` ### Endpoint N/A (Instance method) ### Parameters - **x** (number) - Required - The x-coordinate of the point. - **y** (number) - Required - The y-coordinate of the point. ### Request Example ```javascript var easystar = new EasyStar.js(); // ... setup grid and acceptable tiles ... // Block the shortest path through (2,3) easystar.avoidAdditionalPoint(2, 3); easystar.findPath(1, 2, 3, 2, function(path) { console.log("Path length avoiding (2,3):", path.length); }); easystar.calculate(); // Later, stop avoiding the point easystar.stopAvoidingAdditionalPoint(2, 3); // Clear all avoided points easystar.stopAvoidingAllAdditionalPoints(); ``` ### Response N/A (Modifies internal state) ### Response Example N/A ``` -------------------------------- ### Toggle Diagonal Movement with Bootstrap Switch Source: https://github.com/prettymuchbryce/easystarjs/blob/master/demo/views/index.html Manages the click event for a Bootstrap Switch to enable or disable diagonal movement in Easystar.js. When the switch is on, diagonals are disabled; when off, they are enabled. This impacts the possible paths the algorithm can take. ```javascript $('#check-diagonals').click(function() { if ($('#check-diagonals').bootstrapSwitch('status')) { easyStarDemo.disableDiagonals(); } else { easyStarDemo.enableDiagonals(); } }); ``` -------------------------------- ### Cancel a Pending Path Request (JavaScript) Source: https://github.com/prettymuchbryce/easystarjs/blob/master/README.md Allows for the cancellation of a previously requested pathfinding operation using its unique instance ID. This is useful for managing multiple path requests or aborting unnecessary ones. ```javascript var instanceId = easystar.findPath(startX, startY, endX, endY, callback); // ... easystar.cancelPath(instanceId); ``` -------------------------------- ### Enable/Disable Corner Cutting Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Control whether diagonal paths can cut through corners when adjacent tiles are blocked. Corner cutting is enabled by default when diagonals are enabled. ```APIDOC ## enableCornerCutting() / disableCornerCutting() ### Description Controls whether diagonal paths can cut through corners when adjacent tiles are blocked. Corner cutting is enabled by default when diagonals are enabled. ### Method `enableCornerCutting()` / `disableCornerCutting()` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript var easystar = new EasyStar.js(); // ... setup grid, acceptable tiles, and enableDiagonals() ... easystar.enableCornerCutting(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("With corner cutting:", path ? path.length : "no path"); }); easystar.calculate(); easystar.disableCornerCutting(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("Without corner cutting:", path ? path.length : "no path"); }); easystar.calculate(); ``` ### Response N/A (Modifies internal state) ### Response Example N/A ``` -------------------------------- ### cancelPath(instanceId) Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Cancels a pending path calculation by its instance ID. ```APIDOC ## cancelPath(instanceId) ### Description Removes a pending path calculation from the queue. ### Parameters #### Request Body - **instanceId** (number) - Required - The ID returned by findPath. ### Response #### Success Response (200) - **result** (boolean) - Returns true if the path was successfully cancelled. ``` -------------------------------- ### Enable/Disable Corner Cutting in Easystar.js Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Controls whether diagonal paths can cut through corners when adjacent tiles are blocked. Corner cutting is enabled by default when diagonals are enabled. This feature affects pathfinding when diagonal movement is active. ```javascript var easystar = new EasyStar.js(); // Grid with diagonal walkable tiles var grid = [ [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); easystar.enableDiagonals(); // With corner cutting enabled, path can traverse diagonally easystar.enableCornerCutting(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("With corner cutting:", path ? path.length : "no path"); // 5 }); // Without corner cutting, the diagonal path is blocked easystar.disableCornerCutting(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("Without corner cutting:", path ? path.length : "no path"); // null }); easystar.calculate(); ``` -------------------------------- ### Restrict Tile Access with Directional Conditions Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Configures specific tiles to be accessible only from defined directions using setDirectionalCondition. This is essential for implementing one-way paths or restricted terrain. ```javascript var easystar = new EasyStar.js(); var grid = [[0, 1, 0], [0, 0, 0], [0, 0, 0]]; easystar.setGrid(grid); easystar.setAcceptableTiles([0]); easystar.enableDiagonals(); easystar.setDirectionalCondition(2, 1, [EasyStar.TOP]); easystar.setDirectionalCondition(1, 1, [EasyStar.RIGHT]); easystar.setDirectionalCondition(0, 0, [EasyStar.BOTTOM]); easystar.findPath(2, 0, 0, 0, function(path) { console.log("Path with directional constraints:", path); }); easystar.removeAllDirectionalConditions(); easystar.calculate(); ``` -------------------------------- ### Set Additional Point Cost Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets or removes a custom cost for a specific point, overriding the tile type cost. Useful for dynamic obstacles or temporary hazards. ```APIDOC ## setAdditionalPointCost(x, y, cost) / removeAdditionalPointCost(x, y) ### Description Sets or removes a custom cost for a specific point, overriding the tile type cost. Useful for dynamic obstacles or temporary hazards. ### Method `setAdditionalPointCost(x, y, cost)` / `removeAdditionalPointCost(x, y)` ### Endpoint N/A (Instance method) ### Parameters - **x** (number) - Required - The x-coordinate of the point. - **y** (number) - Required - The y-coordinate of the point. - **cost** (number) - Required (for `setAdditionalPointCost`) - The multiplicative cost for the point. ### Request Example ```javascript var easystar = new EasyStar.js(); // ... setup grid and acceptable tiles ... // Make the center tile expensive easystar.setAdditionalPointCost(2, 1, 10); easystar.findPath(0, 1, 4, 1, function(path) { console.log("Path avoids expensive point:", path); }); easystar.calculate(); // Later, remove the additional cost easystar.removeAdditionalPointCost(2, 1); // Remove all additional point costs at once easystar.removeAllAdditionalPointCosts(); ``` ### Response N/A (Modifies internal state) ### Response Example N/A ``` -------------------------------- ### Enable/Disable Diagonal Movement Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Control whether the pathfinder can move diagonally between tiles. Diagonal movement is disabled by default. ```APIDOC ## enableDiagonals() / disableDiagonals() ### Description Enables or disables 8-direction diagonal movement. When enabled, paths can move diagonally between tiles. Diagonal movement is disabled by default. ### Method `enableDiagonals()` / `disableDiagonals()` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript var easystar = new EasyStar.js(); // ... setup grid and acceptable tiles ... easystar.enableDiagonals(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("Path found with diagonals:", path); }); easystar.calculate(); easystar.disableDiagonals(); easystar.findPath(0, 0, 4, 4, function(path) { console.log("Path found without diagonals:", path); }); easystar.calculate(); ``` ### Response N/A (Modifies internal state) ### Response Example N/A ``` -------------------------------- ### setDirectionalCondition Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Restricts movement to a tile from specific directions only. This is useful for implementing one-way passages, doors, or terrain that can only be entered from certain angles. ```APIDOC ## setDirectionalCondition(x, y, allowedDirections) ### Description Restricts access to a tile from specific directions only. Useful for one-way passages, doors, or terrain that can only be entered from certain angles. ### Method `setDirectionalCondition` ### Parameters #### Path Parameters - **x** (number) - Required - The x-coordinate of the tile. - **y** (number) - Required - The y-coordinate of the tile. - **allowedDirections** (array) - Required - An array of allowed directions. Available directions: `EasyStar.TOP`, `EasyStar.TOP_RIGHT`, `EasyStar.RIGHT`, `EasyStar.BOTTOM_RIGHT`, `EasyStar.BOTTOM`, `EasyStar.BOTTOM_LEFT`, `EasyStar.LEFT`, `EasyStar.TOP_LEFT`. ### Request Example ```javascript var easystar = new EasyStar.js(); var grid = [ [0, 1, 0], [0, 0, 0], [0, 0, 0] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([0]); easystar.enableDiagonals(); // Tile at (2,1) can only be entered from the TOP (walking down onto it) easystar.setDirectionalCondition(2, 1, [EasyStar.TOP]); // Tile at (1,1) can only be entered from the RIGHT easystar.setDirectionalCondition(1, 1, [EasyStar.RIGHT]); // Tile at (0,0) can only be entered from BOTTOM easystar.setDirectionalCondition(0, 0, [EasyStar.BOTTOM]); easystar.findPath(2, 0, 0, 0, function(path) { // Path must respect directional conditions console.log("Path with directional constraints:", path); }); // Clear all directional conditions easystar.removeAllDirectionalConditions(); easystar.calculate(); ``` ### Response This method does not return a value. It configures the pathfinder. ### Error Handling - If invalid coordinates or directions are provided, the behavior is undefined. - Use `removeAllDirectionalConditions()` to clear all previously set conditions. ``` -------------------------------- ### Set/Remove Additional Point Cost in Easystar.js Source: https://context7.com/prettymuchbryce/easystarjs/llms.txt Sets or removes a custom cost for a specific point (x, y), overriding the default tile type cost. This is useful for dynamic obstacles or temporary hazards that need a specific cost. ```javascript var easystar = new EasyStar.js(); var grid = [ [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1] ]; easystar.setGrid(grid); easystar.setAcceptableTiles([1]); // Make the center tile expensive (e.g., enemy presence) easystar.setAdditionalPointCost(2, 1, 10); easystar.findPath(0, 1, 4, 1, function(path) { console.log("Path avoids expensive point:", path); }); // Later, remove the additional cost easystar.removeAdditionalPointCost(2, 1); // Remove all additional point costs at once easystar.removeAllAdditionalPointCosts(); easystar.calculate(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.