MoonPath: A Grid Pathfinding Toolkit for MoonBit. Provides BFS, Dijkstra, and A* pathfinding on 2D grid maps with configurable movement, heuristics, and terrain costs.
| 维度 | 已完成内容 |
|---|---|
| 核心能力 | BFS、Dijkstra、A*,权重地形,四/八向移动,自定义启发式 |
| 正确性 | 65 / 65 测试通过,覆盖不可达、越界、溢出、非法权重和禁止穿角等边界 |
| 覆盖率 | 库核心源码 355 / 381 个插桩点,约 93.2% |
| 工程质量 | format、全目标静态检查、零警告、build、test、coverage、Demo 全部进入 CI |
| 可复测性 | Demo 与 benchmark 均为仓库内可执行入口,CI 会记录实际安装的 MoonBit 版本 |
git clone https://github.com/Burnling-gx/moonpath.git
cd moonpath
moon test
moon run src/cmd/demoS 9 9 9 9 9 G
. # # # # # .
. . . . . . .BFS(最少步数) Dijkstra / A*(最低代价)
S * * * * * G S 9 9 9 9 9 G
. # # # # # . * # # # # # *
. . . . . . . * * * * * * *| Algorithm | Steps | Reported cost | Actual terrain cost | Visited / expanded |
|---|---|---|---|---|
| BFS | 6 | 6 | 46 | 14 / 12 |
| Dijkstra | 10 | 10 | 10 | 13 / 11 |
| A* + Manhattan | 10 | 10 | 10 | 12 / 10 |
| Algorithm | Mean time |
|---|---|
| BFS | 385.29 µs |
| Dijkstra | 995.29 µs |
| A* + Manhattan | 44.89 µs |
git clone https://github.com/Burnling-gx/moonpath.git
cd moonpath
moon check --target all --deny-warn
moon test
moon build
moon run src/cmd/demo
# Optional: run the benchmark suite
moon bench --releaseTotal tests: 65, passed: 65, failed: 0.moon add Burnling-gx/moonpathimport {
"Burnling-gx/moonpath",
}let grid = @moonpath.Grid::new(10, 10).set_cells([
(@moonpath.Point::new(3, 3), @moonpath.Cell::Blocked),
(@moonpath.Point::new(3, 4), @moonpath.Cell::Blocked),
(@moonpath.Point::new(4, 2), @moonpath.Cell::Weighted(5)),
])
let start = @moonpath.Point::new(0, 0)
let goal = @moonpath.Point::new(9, 9)
let result = @moonpath.astar(
grid,
start,
goal,
@moonpath.SearchOptions::four_way(),
)
match result.path {
Some(path) => {
println("Steps: " + result.steps().to_string())
println("Cost: " + result.total_cost.to_string())
}
None => println("No path found")
}| Algorithm | Weighted terrain | Movement | Optimality |
|---|---|---|---|
| bfs | Ignored | Four-way | Fewest steps |
| dijkstra | Yes | Four-way | Lowest cost for positive weights |
| dijkstra_with_movement | Yes | Four/eight-way | Lowest cost for positive weights |
| astar | Yes | Four/eight-way | Lowest cost when its heuristic contract holds |
Grid
new / try_new / from_cells
width / height / size / in_bounds
get_cell / try_get_cell / cost / is_passable
set_cell / try_set_cell / set_cells / set_wall
set_weighted / try_set_weighted / clear
Search
bfs
dijkstra / dijkstra_with_movement
astar + SearchOptions
Result
path / total_cost / nodes_visited / nodes_expanded
found / stepsmoon.mod module metadata (source root: src)
src/
moon.pkg library package configuration
types.mbt public data model and result semantics
grid.mbt validated immutable-style grid
neighbors.mbt four/eight-way movement and costs
priority_queue.mbt O(log n) deterministic binary min-heap
bfs.mbt
dijkstra.mbt
astar.mbt
heuristics.mbt
*_test.mbt black-box tests and benchmark cases
cmd/demo/
moon.pkg
main.mbt weighted ASCII comparison demo
.github/workflows/ci.yml format, check, build, test, coverage, demopub struct Grid {
// private fields
}fn dijkstra_with_movement(grid : Grid, start : Point, goal : Point, movement : Movement) -> SearchResultMoonPath: A Grid Pathfinding Toolkit for MoonBit. Provides BFS, Dijkstra, and A* pathfinding on 2D grid maps with configurable movement, heuristics, and terrain costs.