我的目标是编写一个名为 walk 的函数,它可以将迷宫单元的值与其邻居切换。例如,调用 walk 0 labyrinthA 应该将 T 单元格向左移动。在这里,我尝试更改 ghci 中迷宫单元的值。
showLabyrinth labyrinth =
putStrLn $ unlines $ [[labyrinth j i | i <- [1..dimH]] | j <- [1..dimV]]
where
dimH = length . takeWhile (/='O') $ [labyrinth 1 i | i <- [1..]]
dimV = length . takeWhile (/='O') $ [labyrinth i 1 | i <- [1..]]
labyrinthA 9 _ = 'O'
labyrinthA _ 16 = 'X'
labyrinthA _ 17 = 'O'
labyrinthA 1 _ = 'X'
labyrinthA 2 1 = 'X'
labyrinthA 2 8 = 'X'
labyrinthA 2 12 = 'X'
labyrinthA 2 _ = ' '
labyrinthA 3 1 = 'X'
labyrinthA 3 3 = 'X'
labyrinthA 3 5 = 'X'
labyrinthA 3 6 = 'X'
labyrinthA 3 8 = 'X'
labyrinthA 3 9 = 'X'
labyrinthA 3 10 = 'X'
labyrinthA 3 12 = 'X'
labyrinthA 3 14 = 'M'
labyrinthA 3 _ = ' '
labyrinthA 4 1 = 'X'
labyrinthA 4 2 = 'X'
labyrinthA 4 3 = 'X'
labyrinthA 4 5 = 'X'
labyrinthA 4 6 = 'X'
labyrinthA 4 12 = 'X'
labyrinthA 4 _ = ' '
labyrinthA 5 1 = 'X'
labyrinthA 5 5 = 'X'
labyrinthA 5 8 = 'X'
labyrinthA 5 9 = 'X'
labyrinthA 5 10 = 'X'
labyrinthA 5 12 = 'X'
labyrinthA 5 13 = 'X'
labyrinthA 5 15 = 'X'
labyrinthA 5 _ = ' '
labyrinthA 6 1 = 'X'
labyrinthA 6 3 = 'X'
labyrinthA 6 4 = 'X'
labyrinthA 6 5 = 'X'
labyrinthA 6 7 = 'X'
labyrinthA 6 8 = 'X'
labyrinthA 6 10 = 'X'
labyrinthA 6 _ = ' '
labyrinthA 7 1 = 'X'
labyrinthA 7 6 = 'T'
labyrinthA 7 9 = 'X'
labyrinthA 7 10 = 'X'
labyrinthA 7 11 = 'X'
labyrinthA 7 12 = 'X'
labyrinthA 7 13 = 'X'
labyrinthA 7 14 = 'X'
labyrinthA 7 15 = 'X'
labyrinthA 7 _ = ' '
labyrinthA 8 6 = 'E'
labyrinthA 8 _ = 'X'
现在我试着让'T'用 walk 0 labyrinthA 向左走
walk direction labyrinth | direction == 0 = let labyrinth (yKoord 'T')
(xKoord 'T') = ' ' && let labyrinth (yKoord) ((xKoord+1)) = 'T'
| direction == 1 = undefined
| direction == 2 = undefined
| direction == 3 = undefined
其中 yKoord 和 xKoord 是整数。
在此处输入图像描述