haskell - Loading a text file of values into a list of lists -
I have a text file (data.txt) that looks like this:
- This is an MAP where (-) I can go places, (#) is a wall, and (@) ---------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------------------- My goal is I I want to load a list in the list so that I can index it through (line, call) and then cross it (unless there is no better way Land, I'm new here). Using Readfile but it gives me all in one shot, trying to use it. There are lines to break it but it still will not work ...
I was hoping to do something like this:
myMap = [[, - , #, -, -], [-, #, -, @], [-, -, -, -, -]]
till I make a mistake By that time, I will have to work like my mama !! 0 !! To get 0 [-] which is the CRAC on the cell (0,0) on my map (and further).
Then with it I can pass it in a function and determine what I can do (clearly do not go to any wall) and as long as I have my (@), etc. Try to find a way to go again in any way ...
If I understand correctly, then you want to load a string in two-dimensional map. You can do something like this:
Import data. Map hidden (map) toMap :: string - & gt; Map (Int, Int) Four toMap = fromList ConcatMap (λ (r, line) - & gt; Map (λ (c, char) - & gt; ((RC), four) $ $ zip. ] $ String) ZIP [0 ..]
and then use it:
Raw: : String Crude = "- # - λn - # - @ λn -----" Main :: IO (Main) = Let's copy myMap = DentrestLN $ "map:" ++ MyMap putStrLn $ "Elem in pos Show (0,0): "++ Show (Mymap! (0,0))
Comments
Post a Comment