| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 21:22:45 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 21:22:45 +0200 | 
| commit | 1b72f37fc04cd7851bd2f289d7776a1c7c35f48d (patch) | |
| tree | 2349fe545bfa81451f81a7cef8e5838c1cf6acb6 /client/elm/battlemap/src/Battlemap | |
| parent | 36344e727e45b6a1d39f372a6a39ab973e023bdf (diff) | |
Adds backtrack support.
Diffstat (limited to 'client/elm/battlemap/src/Battlemap')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Direction.elm | 11 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 54 | 
2 files changed, 54 insertions, 11 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/Direction.elm b/client/elm/battlemap/src/Battlemap/Direction.elm index b943c2d..e301177 100644 --- a/client/elm/battlemap/src/Battlemap/Direction.elm +++ b/client/elm/battlemap/src/Battlemap/Direction.elm @@ -1,4 +1,4 @@ -module Battlemap.Direction exposing (..) +module Battlemap.Direction exposing (Direction(..), opposite_of)  type Direction =     None @@ -6,3 +6,12 @@ type Direction =     | Right     | Up     | Down + +opposite_of : Direction -> Direction +opposite_of d = +   case d of +      Left -> Right +      Right -> Left +      Up -> Down +      Down -> Up +      None -> None diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index df0e2cf..d26a56a 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -6,10 +6,11 @@ module Battlemap.Navigator exposing        go     ) -import Set exposing (Set, member, empty, insert) +import Set exposing (Set, member, empty, insert, remove) +import List as Lt exposing (head, tail)  import Battlemap exposing (Battlemap, has_location, apply_to_tile) -import Battlemap.Direction exposing (Direction(..)) +import Battlemap.Direction exposing (Direction(..), opposite_of)  import Battlemap.Tile exposing (Tile, set_direction)  import Battlemap.Location exposing @@ -23,14 +24,16 @@ import Battlemap.Location exposing  type alias Navigator =     {        current_location : Location, -      visited_locations : (Set LocationRef) +      visited_locations : (Set LocationRef), +      previous_directions : (List Direction)     }  new_navigator : Location -> Navigator  new_navigator start =     {        current_location = start, -      visited_locations = empty +      visited_locations = empty, +      previous_directions = []     } @@ -63,17 +66,48 @@ go battlemap nav dir =                    Nothing -> battlemap                    (Just bmap) -> bmap              ), -            { +            {nav |                 current_location = next_location,                 visited_locations =                    (insert                       (to_comparable nav.current_location)                       nav.visited_locations -                  ) +                  ), +               previous_directions = (dir :: nav.previous_directions)              }           )        else -         ( -            battlemap, -            nav -         ) +         case +            ( +               (Lt.head nav.previous_directions), +               (Lt.tail nav.previous_directions) +            ) +         of +            (Nothing, _) -> (battlemap, nav) +            (_ , Nothing) -> (battlemap, nav) +            ((Just prev_dir), (Just prev_dir_list)) -> +               if (dir == (opposite_of prev_dir)) +               then +                  ( +                     (case +                        (apply_to_tile +                           battlemap +                           next_location +                           (set_direction None) +                        ) +                        of +                           Nothing -> battlemap +                           (Just bmap) -> bmap +                     ), +                     {nav | +                        current_location = next_location, +                        visited_locations = +                           (remove +                              (to_comparable next_location) +                              nav.visited_locations +                           ), +                        previous_directions = prev_dir_list +                     } +                  ) +               else +                  (battlemap, nav) | 


