| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 09:52:54 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 09:52:54 +0200 | 
| commit | 9a2d8f37dea8e14afa57affb135def13954df547 (patch) | |
| tree | ee7daa101ffdb76bc4a5932c3698b6a89613df78 /client/elm/battlemap/src/Battlemap/Navigator.elm | |
Satisfied with Elm so far, let's go with it.
Diffstat (limited to 'client/elm/battlemap/src/Battlemap/Navigator.elm')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 50 | 
1 files changed, 50 insertions, 0 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm new file mode 100644 index 0000000..ffd52cc --- /dev/null +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -0,0 +1,50 @@ +module Battlemap.Navigator exposing (Navigator, new_navigator, go) + +import Set exposing (Set, member, empty) + +import Battlemap exposing (Battlemap, has_location) +import Battlemap.Location exposing (..) +import Battlemap.Direction exposing (..) +import Battlemap.Tile exposing (set_tile_direction) + +type alias Navigator = +   { +      current_location : Location, +      visited_locations : (Set Location) +   } + +new_navigator : Location -> Navigator +new_navigator start = +   { +      current_location = start, +      visited_locations = empty +   } + +go : Navigator -> Direction -> (Battlemap, Navigator) +go battlemap nav dir = +   let +      next_location = (neighbor nav.current_location dir) +   in +      if +      ( +         (has_location battlemap next_location) +         && (current_location != next_location) +         && (not (member next_location nav.visited_locations)) +      ) +      then +         ( +            (set_tile_direction +               nav.current_location +               dir +            ), +            { +               current_location = next_location, +               visited_locations = +                  (insert +                     nav.current_location +                     nav.visited_locations +                  ) +            } +         ) +      else +         nav | 


