Haskell Tail Tracking Recursion

I implement this in haskell.

https://www.cs.bu.edu/teaching/alg/maze/

I can get the list when the "goal" is reached, but if the goal is unavailable, the list is not updated. for instance

...#@                           !!!#@
..#..                           !!#..
.##.#     it should return      !##.#
...#.                           !!!#.

My code is as follows

path maze x y
    | x >= length (head maze) = (False, maze)
    | y >= length maze = (False, maze)
    | x < 0 = (False, maze)
    | y < 0 = (False,maze)
    | check maze x y '+' = (False, maze)
    | check maze x y '#' = (False,maze)
    | check maze x y '!' = (False, maze)
    | check maze x y 'G' = (True,maze)
    | fst east = (True,snd east)
    | fst south = (True, snd south)
    | fst west = (True, snd west)
    | fst north = (True, snd north)
    | fst noWay = (True, snd noWay)
    | otherwise = (False, maze)
            where 
                    noWay = path (changeVal maze x y '!') x (y+1)
                    north = path(changeVal maze x y '+') x (y-1)
                    south = path (changeVal maze x y '+') x (y+1)
                    east = path (changeVal maze x y '+') (x+1) y
                    west = path (changeVal maze x y '+') (x-1) y

I do not get the result. I'm new to Haskell if anyone can give me a boost so that I can solve this stupid problem.

+4
source share
1 answer

Immediately, the cause of your problem is that

| otherwise = (False, maze)

maze , . snd noWay . ( , ! .)

: , , maze . , . . (, → → → ), south , east , -

south = path (snd east) x (y+1)

, noWay. ( , .) , north , , ,

| otherwise = (False, changeVal (snd north) x y '!')
+2

All Articles