Skip to content

Commit

Permalink
docs: add notes on JPS, landmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchassassin committed Dec 17, 2024
1 parent e92130a commit 1cb326a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/primitives/astar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@

The [venerable A\* algorithm](https://www.redblobgames.com/pathfinding/a-star/introduction.html) provides the baseline for pathfinding in Screeps.

Red Blob Games has some [WIP articles on heuristics](https://www.redblobgames.com/blog/2024-05-05-wip-heuristics/).
Within a single room, the Clockwork implementation of the A\* algorithm alone is competitive with PathFinder. However, across longer distances (greater than a single room), PathFinder's JPS optimizations make a significant difference.

We'll experiment with a few different options.

## Optimizations

- [Jump-Point Search](https://zerowidth.com/2013/a-visual-explanation-of-jump-point-search/) is also used under the hood by PathFinder
- [Pre-computed landmarks](https://www.redblobgames.com/blog/2024-05-05-wip-heuristics/) for more accurate A\* heuristics

### Landmarks

The theory:

1. Pick a non-wall spot near the middle of the room and Dijkstra-map out from there.
2. Cache the center spot, one exit on each of the (1-4) sides, and cost for each.
3. Use these points as landmarks for the A\* heuristic.

Drawbacks:

Cost matrix used for calculating landmarks needs to be the same as cost matrix for pathing

## Other interesting variants

- [Cooperative Pathfinding](https://theory.stanford.edu/~amitp/GameProgramming/MovingObstacles.html#predicting-obstacle-movement) (building a table of the paths of other units)
- JPS (generating paths, ignoring terrain costs)
- [Incremental heuristic search](https://en.wikipedia.org/wiki/Incremental_heuristic_search) (tracking moving targets)
- [Parallel Breadth-First Search](https://arxiv.org/abs/2210.16351)
1 change: 1 addition & 0 deletions docs/wasm/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
We are using wasm-bindgen to create the WASM and a JS shim (`packages/wasm`). There are a few things we tweak to improve performance (such as passing in the `__packedPos` instead of the whole RoomPosition), so this is further wrapped in a Typescript library (`packages/screeps-clockwork`) which wraps and re-exports the WASM functionality.

- Copying data across the [WASM boundary](./boundary.md) adds up, so we must be thoughtful about when and how we copy data back and forth.
- Javascript can't garbage-collect our Rust objects, so we need to [clean them up explicitly](./cleanup.md).

0 comments on commit 1cb326a

Please sign in to comment.