-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neighbour.hs
45 lines (33 loc) · 1.56 KB
/
Neighbour.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Neighbour
( stateOfAllRightNeighbours
, stateOfAllLeftNeighbours
, stateOfAllBotNeighbours
, stateOfAllTopNeighbours
, stateOfAllBotRightNeighbours
, stateOfAllTopRightNeighbours
, stateOfAllBotLeftNeighbours
, stateOfAllTopLeftNeighbours
) where
import Data.List
import Cell
stateOfRightNeighbour :: String -> [Int]
stateOfRightNeighbour (_:y:rest)
| y == toChar Alive = 1 : stateOfRightNeighbour (y:rest)
| otherwise = 0 : stateOfRightNeighbour (y:rest)
stateOfRightNeighbour _ = [0]
stateOfAllRightNeighbours :: [String] -> [[Int]]
stateOfAllRightNeighbours = map stateOfRightNeighbour
stateOfAllLeftNeighbours :: [String] -> [[Int]]
stateOfAllLeftNeighbours = map ((reverse . stateOfRightNeighbour) . reverse)
stateOfAllBotNeighbours :: [String] -> [[Int]]
stateOfAllBotNeighbours lst = transpose $ stateOfAllRightNeighbours $ transpose lst
stateOfAllTopNeighbours :: [String] -> [[Int]]
stateOfAllTopNeighbours lst = transpose $ stateOfAllLeftNeighbours $ transpose lst
stateOfAllBotRightNeighbours :: [String] -> [[Int]]
stateOfAllBotRightNeighbours lst = stateOfAllBotNeighbours [tail l ++ toString Dead | l <- lst]
stateOfAllTopRightNeighbours :: [String] -> [[Int]]
stateOfAllTopRightNeighbours lst = stateOfAllTopNeighbours [tail l ++ toString Dead | l <- lst]
stateOfAllBotLeftNeighbours :: [String] -> [[Int]]
stateOfAllBotLeftNeighbours lst = stateOfAllBotNeighbours [toString Dead ++ init l | l <- lst]
stateOfAllTopLeftNeighbours :: [String] -> [[Int]]
stateOfAllTopLeftNeighbours lst = stateOfAllTopNeighbours [toString Dead ++ init l | l <- lst]