gwg/pathfinding
2
0
Fork
You've already forked pathfinding
0
🚲 Pathfinding library for Gleam https://gwg-pathfinding.hexdocs.pm/
  • Gleam 100%
2026年03月18日 19:59:20 +07:00
src/gwg docs: Improve examples. 2026年02月22日 16:55:00 +07:00
test 2026年02月22日T13:20:47.111+07:00 2026年02月22日 13:20:47 +07:00
.gitignore feat: Init. 2026年01月08日 23:09:46 +07:00
gleam.toml docs: Update README.md. 2026年03月18日 19:59:20 +07:00
manifest.toml 2026年02月22日T13:20:47.111+07:00 2026年02月22日 13:20:47 +07:00
README.md docs: Update README.md. 2026年03月18日 19:59:20 +07:00

gwg_pathfinding

Package Version Hex Docs

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.