-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.hs
130 lines (118 loc) · 3.44 KB
/
Utils.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
module Utils where
import Types
import Prelude hiding (Left, Right)
replace3 :: (a, a, a) -> (Int, Int, Int) -> [a] -> [a]
replace3 (v1, v2, v3) (t1, t2, t3) target = replace v3 t3 (replace v2 t2 (replace v1 t1 target))
replace :: a -> Int -> [a] -> [a]
replace _ _ [] = []
replace value n (x : xs) = if n == 0 then value : xs else x : replace value (n - 1) xs
{- Getters -}
getSolvedCube :: Cube
getSolvedCube =
[ (Front, [Red, Red, Red, Red, Red, Red, Red, Red, Red]),
(Right, [Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue]),
(Back, [Orange, Orange, Orange, Orange, Orange, Orange, Orange, Orange, Orange]),
(Left, [Green, Green, Green, Green, Green, Green, Green, Green, Green]),
(Up, [White, White, White, White, White, White, White, White, White]),
(Down, [Yellow, Yellow, Yellow, Yellow, Yellow, Yellow, Yellow, Yellow, Yellow])
]
getTargetSideColor :: Side -> Color
getTargetSideColor Up = White
getTargetSideColor Down = Yellow
getTargetSideColor Left = Green
getTargetSideColor Right = Blue
getTargetSideColor Front = Red
getTargetSideColor Back = Orange
getSide :: Side -> Cube -> [Color]
getSide side cube = concat [snd face | face <- cube, side == fst face]
getSides :: Cube -> ([Color], [Color], [Color], [Color], [Color], [Color])
getSides cube = (getSide Front cube, getSide Left cube, getSide Back cube, getSide Right cube, getSide Up cube, getSide Down cube)
translateMoveWhiteUp :: Side -> Move -> Move
translateMoveWhiteUp Front move = move
translateMoveWhiteUp Up move = move
translateMoveWhiteUp Down move = move
translateMoveWhiteUp Right move
| move == L = F
| move == L' = F'
| move == R = B
| move == R' = B'
| move == F = R
| move == F' = R'
| move == B = L
| move == B' = L'
| otherwise = move
translateMoveWhiteUp Left move
| move == L = B
| move == L' = B'
| move == R = F
| move == R' = F'
| move == F = L
| move == F' = L'
| move == B = R
| move == B' = R'
| otherwise = move
translateMoveWhiteUp Back move
| move == L = R
| move == L' = R'
| move == R = L
| move == R' = L'
| move == F = B
| move == F' = B'
| move == B = F
| move == B' = F'
| otherwise = move
translateMoveWhiteDown :: Side -> Move -> Move
translateMoveWhiteDown Up move = move
translateMoveWhiteDown Down move = move
translateMoveWhiteDown Front move
| move == U = D
| move == U' = D'
| move == D = U
| move == D' = U'
| move == L = R
| move == L' = R'
| move == R = L
| move == R' = L'
| otherwise = move
translateMoveWhiteDown Right move
| move == U = D
| move == U' = D'
| move == D = U
| move == D' = U'
| move == L = B
| move == L' = B'
| move == R = F
| move == R' = F'
| move == F = R
| move == F' = R'
| move == B = L
| move == B' = L'
| otherwise = move
translateMoveWhiteDown Left move
| move == U = D
| move == U' = D'
| move == D = U
| move == D' = U'
| move == L = F
| move == L' = F'
| move == R = B
| move == R' = B'
| move == F = L
| move == F' = L'
| move == B = R
| move == B' = R'
| otherwise = move
translateMoveWhiteDown Back move
| move == U = D
| move == U' = D'
| move == D = U
| move == D' = U'
| move == F = B
| move == F' = B'
| move == B = F
| move == B' = F'
| otherwise = move
translateMovesWhiteUp :: Side -> [Move] -> [Move]
translateMovesWhiteUp side = map (translateMoveWhiteUp side)
translateMovesWhiteDown :: Side -> [Move] -> [Move]
translateMovesWhiteDown side = map (translateMoveWhiteDown side)