Algorithm Plugin
The Clay Algorithm plugin provides computational algorithm components
for use in games and simulations. It has zero Clayground dependencies
and serves as a foundation layer.
Getting Started
import Clayground.Algorithm
Components
- GridPathfinder - A* pathfinding on a 2D grid with binary heap,
supporting diagonal movement and incremental cell updates.
Usage Example
Grid Pathfinding
import Clayground.Algorithm
GridPathfinder {
id: pathfinder
columns: 50
rows: 50
diagonal: true
walkableData: levelTileData // flat array: 0 = walkable, 1+ = blocked
}
// Compute a path
// var path = pathfinder.findPath(0, 0, 49, 49)
// Returns: [{x:0, y:0}, {x:1, y:1}, ...] or [] if unreachable
Incremental Updates
// Block a single cell
pathfinder.setWalkable(10, 5, false)
// Unblock it
pathfinder.setWalkable(10, 5, true)
API Reference
GridPathfinder Properties
| Property |
Type |
Description |
columns |
int |
Number of grid columns (default: 10) |
rows |
int |
Number of grid rows (default: 10) |
walkableData |
var |
Flat array indexed [y * columns + x], 0 = walkable |
diagonal |
bool |
Allow diagonal movement (default: false) |
GridPathfinder Methods
| Method |
Returns |
Description |
findPath(startX, startY, endX, endY) |
list |
A* shortest path as [{x, y}, ...] |
setWalkable(x, y, walkable) |
void |
Update a single cell |
API Reference
GridPathfinder
A* pathfinding on a 2D grid
View full documentation
Properties
| Name | Type | Description |
columns | int | Number of columns in the grid |
diagonal | bool | Allow diagonal movement (default: false) |
rows | int | Number of rows in the grid |
walkableData | var | Flat array of grid cell values. 0 means walkable, 1+ means blocked |
Methods
| Method | Returns | Description |
findPath(int startX, int startY, int endX, int endY) | list | |
setWalkable(int x, int y, bool walkable) | void | |
KalmanFilter2D
Constant-velocity Kalman filter for 2D position tracking
View full documentation
Properties
| Name | Type | Description |
estX readonly | real | Estimated x position |
estY readonly | real | Estimated y position |
processNoise | real | Acceleration standard deviation of the motion model |
sigmaX readonly | real | Position uncertainty (std dev) along x |
sigmaY readonly | real | Position uncertainty (std dev) along y |
Methods
| Method | Returns | Description |
correct(real zx, real zy, real sigma) | void | |
predict(real dt) | void | |
reset(real px, real py) | void | |