chore: add mooncake.yaml for publishing metadata
A comprehensive pathfinding library for MoonBit, featuring 9 algorithms, 5 graph types, maze generators, and ASCII/HTML visualization.
moon add hzc-666-ai/moonpathfinding
// Grid pathfinding with A* let lines = [ "S....", ".###.", ".....", ".###.", "....E", ] let grid = @graph.Grid::from_strings(lines).unwrap() let start = grid.pos_to_id(0, 0) // 'S' position let goal = grid.pos_to_id(4, 4) // 'E' position let result = @algo.astar(grid, start, goal) println(@visualize.ascii_render(grid, result, start, goal)) // S···· // *###· // ***** // ·###* // ····E
// General graph let g = @graph.AdjacencyList::new(4) g.add_edge_undirected(0, 1, 5) g.add_edge_undirected(1, 2, 3) g.add_edge_undirected(2, 3, 1) let r = @algo.dijkstra(g, 0, 3) // r.cost = 9, r.path = [0, 1, 2, 3]
// Generate and solve a maze let maze = @maze.dfs_maze(15, 15, 42) let grid = @graph.Grid::from_strings(maze).unwrap() let r = @algo.astar(grid, 0, grid.width * grid.height - 1) println(@visualize.ascii_render(grid, r, 0, grid.width * grid.height - 1))
// Compare all algorithms let report = @bench.maze_benchmark() println(report)
moonpathfinding/ ├── graph/ # Graph trait, AdjacencyList, Grid, WeightedGrid, HexGrid ├── algo/ # 9 algorithms + MinHeap ├── visualize/ # ASCII and HTML renderers ├── maze/ # Maze generators (DFS, Prim, random) ├── bench/ # Performance benchmarks ├── cmd/main/ # CLI demo (moon run cmd/main) └── docs/ # Competition documents
@algo.bfs(graph, start, goal) -> PathResult @algo.dfs(graph, start, goal) -> PathResult @algo.dijkstra(graph, start, goal) -> PathResult @algo.astar(graph, start, goal) -> PathResult @algo.greedy_bfs(graph, start, goal) -> PathResult @algo.bidirectional_bfs(graph, start, goal)-> PathResult @algo.bellman_ford(graph, start, goal) -> PathResult @algo.idastar(graph, start, goal) -> PathResult @algo.jps(grid, start, goal) -> PathResult
@algo.smooth_path(path, line_of_sight) -> Array[Int] @algo.simplify_path(path, is_passable) -> Array[Int] @algo.expand_path(path, neighbors) -> Array[Int] @algo.decimate_path(path, min_dist) -> Array[Int]
smooth_path uses an explicit two-node line-of-sight predicate. expand_path connects each waypoint pair with a continuous unweighted BFS segment and returns an empty path when a segment is unreachable.
smooth_path
expand_path
pub trait Graph { node_count(Self) -> Int neighbors(Self, Int) -> Array[(Int, Int)] // (node_id, edge_cost) heuristic(Self, Int, Int) -> Int // estimated cost }
pub(all) struct PathResult { path : Array[Int] // ordered node IDs cost : Int // total path cost nodes_visited : Int // exploration count }
@visualize.ascii_render(grid, result, start, goal) -> String @visualize.html_render(grid, result, start, goal, title) -> String @visualize.result_summary(algo_name, result) -> String
moon run cmd/main
moon test
MIT
纯 MoonBit 实现的路径查找算法库,提供 9 种算法(BFS/DFS/Dijkstra/A*/Greedy BFS/Bidirectional BFS/Bellman-Ford/IDA*/JPS)、5 种图类型(图/网格/加权网格/六边形网格/Trait 接口)、3 种迷宫生成器和 ASCII/HTML 双模式可视化。零外部依赖,基于 Graph trait 泛型设计。
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
MoonPathfinding
A comprehensive pathfinding library for MoonBit, featuring 9 algorithms, 5 graph types, maze generators, and ASCII/HTML visualization.
Features
Algorithms (9)
Graph Types (5)
Maze Generators (3)
Visualization
Installation
Quick Start
Project Structure
API Overview
Algorithms
Path Utilities
smooth_pathuses an explicit two-node line-of-sight predicate.expand_pathconnects each waypoint pair with a continuous unweighted BFS segment and returns an empty path when a segment is unreachable.Graph Trait
PathResult
Visualization
Run CLI Demo
Run Tests
License
MIT
Links