moonbitstack/moongraph/grid does not have a README file
pub struct DStar {
grid : Grid
start : Int
goal : Int
g : Array[Double]
rhs : Array[Double]
km : Double
open : PairingHeap[(Double, Double, Int)]
}test {
let board = @grid.Grid::new(6, 6)
let walker = board.d_star_lite(board.node(0, 0), board.node(5, 5))
// Five across and five down, all diagonal: the octile distance.
assert_eq(walker.cost(), board.estimate(board.node(0, 0), board.node(5, 5)))
// A wall across the middle, with the walker still at the start.
for y in 0..<5 {
board.block(3, y)
}
walker.replan(board.node(0, 0), [
board.node(3, 0),
board.node(3, 1),
board.node(3, 2),
board.node(3, 3),
board.node(3, 4),
])
// The only way across is the bottom row, so the route is longer than the straight line.
assert_true(
walker.cost() > board.estimate(board.node(0, 0), board.node(5, 5)),
)
}test {
let board = @grid.Grid::new(5, 5)
assert_true(board.line_of_sight(board.node(0, 0), board.node(4, 4)))
board.block(2, 2)
assert_false(board.line_of_sight(board.node(0, 0), board.node(4, 4)))
}test {
let board = @grid.Grid::new(6, 6)
let route = board.theta_star(board.node(0, 0), board.node(5, 5))
match route {
// Nothing in the way, so the route is a straight diagonal: two cells, not six.
Some(cells) => assert_eq(cells.length(), 2)
None => fail("an empty board has a route")
}
}Install
Download zipGraphs and graph algorithms for MoonBit: four storage types that share one interface, and the algorithm families that run on all of them.