gwg/pathfinding
🚲 Pathfinding library for Gleam
https://gwg-pathfinding.hexdocs.pm/
- Gleam 100%
| src/gwg | docs: Improve examples. | |
| test | 2026年02月22日T13:20:47.111+07:00 | |
| .gitignore | feat: Init. | |
| gleam.toml | docs: Update README.md. | |
| manifest.toml | 2026年02月22日T13:20:47.111+07:00 | |
| README.md | docs: Update README.md. | |
gwg_pathfinding
This is a generic searching/pathfinding algorithm library for the Gleam programming language.
Installation
gleam add gwg_pathfinding
importgleam/boolimportgleam/dictimportgleam/floatimportgleam/listimportgwg/pathfinding.{Action}importvec/dict/vec2i_dictimportvec/vec2.{Vec2}importvec/vec2i.{typeVec2i}pubfnmain(){letactions=[Vec2(-1,0),Vec2(1,0),Vec2(0,-1),Vec2(0,1),Vec2(-1,-1),Vec2(-1,1),Vec2(1,-1),Vec2(1,1),]letworld=vec2i_dict.from_string(""<>"###########\n"<>"# # #\n"<>"# # #\n"<>"# # #\n"<>"# ## ####\n"<>"# # #\n"<>"# # #\n"<>"## ##### ##\n"<>"# # # #\n"<>"# #\n"<>"###########\n",)letinit=Vec2(2,2)lettarget=Vec2(7,2)pathfinding.astar(init:,successor:fn(state,g_score){actions|>list.filter_map(fn(action){letweight=action|>vec2i.lengthuse<-bool.guard(g_score+.weight>.32.0,Error(Nil))letstate=state|>vec2i.add(action)use<-bool.guard(world|>dict.has_key(state),Error(Nil))Ok(Action(action:,state:,weight:))})},heuristic:vec2i.distance(_,target),)// ###########
// # # #
// # @ # * #
// # ↓ # ↗ #
// # ↓ ##↑####
// # ↓ # ↖ #
// # ↓ # ↖ #
// ##↘#####↑##
// # ↘# #↗ #
// # →→↗ #
// ###########
}Further documentation can be found at https://hexdocs.pm/gwg_pathfinding.