aboutsummaryrefslogtreecommitdiff
path: root/src/core/moves.h
diff options
context:
space:
mode:
authorenricotenuti <tenutz_27@outlook.it>2024-08-29 19:07:48 +0200
committerenricotenuti <tenutz_27@outlook.it>2024-08-29 19:07:48 +0200
commit47a65b676d1de889706517f05659f0bb659782c9 (patch)
tree51f3c25f3ae22699de269b493315eb579e280280 /src/core/moves.h
parenta2b868261d0504c95b1091db0ce014fd567281c3 (diff)
downloadnissy-core-47a65b676d1de889706517f05659f0bb659782c9.tar.gz
nissy-core-47a65b676d1de889706517f05659f0bb659782c9.zip
nissbranch ver1
Diffstat (limited to 'src/core/moves.h')
-rw-r--r--src/core/moves.h162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index 7da6405..726a452 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -1,8 +1,23 @@
1/* probably these can be placed in constants file */
2#define NONISS 0x00
3#define NISS 0x01
4#define INVERSEBRANCH 0x03
5#define BRANCH 0x02
6#define ALLMOVES 0x3FFFF
7#define NOHALFTURNS 0x2DB6D
8
1_static_inline bool allowednextmove(uint8_t *, uint8_t); 9_static_inline bool allowednextmove(uint8_t *, uint8_t);
10_static uint32_t allowednextmoveH48(uint8_t *, uint8_t, uint32_t);
11
2_static_inline uint8_t inverse_trans(uint8_t); 12_static_inline uint8_t inverse_trans(uint8_t);
3_static_inline uint8_t movebase(uint8_t); 13_static_inline uint8_t movebase(uint8_t);
4_static_inline uint8_t moveaxis(uint8_t); 14_static_inline uint8_t moveaxis(uint8_t);
5 15
16_static cube_t move(cube_t, uint8_t);
17_static cube_t premove(cube_t, uint8_t);
18_static uint8_t inverse_move(uint8_t);
19_static uint8_t* invertpremoves(uint8_t *, uint8_t);
20
6_static bool 21_static bool
7allowednextmove(uint8_t *moves, uint8_t n) 22allowednextmove(uint8_t *moves, uint8_t n)
8{ 23{
@@ -28,6 +43,40 @@ allowednextmove(uint8_t *moves, uint8_t n)
28 return axis[1] != axis[2] || base[0] != base[2]; 43 return axis[1] != axis[2] || base[0] != base[2];
29} 44}
30 45
46static uint32_t
47disable_moves(uint32_t current_result, uint8_t base_index)
48{
49 return current_result & ~((1 << base_index) | (1 << (base_index + 1)) | (1 << (base_index + 2)));
50}
51
52_static uint32_t
53allowednextmoveH48(uint8_t *moves, uint8_t n, uint32_t h48branch)
54{
55 uint32_t result = ALLMOVES;
56 if (h48branch & BRANCH)
57 result &= NOHALFTURNS;
58 if (n < 1)
59 return result;
60
61 uint8_t base1 = movebase(moves[n-1]);
62 uint8_t axis1 = moveaxis(moves[n-1]);
63
64 result = disable_moves(result, base1 * 3);
65 if (base1 >= 9)
66 result = disable_moves(result, (base1 * 3) - 9);
67
68 if (n == 1)
69 return result;
70
71 uint8_t base2 = movebase(moves[n-2]);
72 uint8_t axis2 = moveaxis(moves[n-2]);
73
74 if(axis1 == axis2)
75 result = disable_moves(result, base2 * 3);
76
77 return result;
78}
79
31_static_inline uint8_t 80_static_inline uint8_t
32inverse_trans(uint8_t t) 81inverse_trans(uint8_t t)
33{ 82{
@@ -45,3 +94,116 @@ moveaxis(uint8_t move)
45{ 94{
46 return move / 6; 95 return move / 6;
47} 96}
97
98_static cube_t
99move(cube_t c, uint8_t m)
100{
101 switch (m) {
102 case _move_U:
103 return _move(U, c);
104 case _move_U2:
105 return _move(U2, c);
106 case _move_U3:
107 return _move(U3, c);
108 case _move_D:
109 return _move(D, c);
110 case _move_D2:
111 return _move(D2, c);
112 case _move_D3:
113 return _move(D3, c);
114 case _move_R:
115 return _move(R, c);
116 case _move_R2:
117 return _move(R2, c);
118 case _move_R3:
119 return _move(R3, c);
120 case _move_L:
121 return _move(L, c);
122 case _move_L2:
123 return _move(L2, c);
124 case _move_L3:
125 return _move(L3, c);
126 case _move_F:
127 return _move(F, c);
128 case _move_F2:
129 return _move(F2, c);
130 case _move_F3:
131 return _move(F3, c);
132 case _move_B:
133 return _move(B, c);
134 case _move_B2:
135 return _move(B2, c);
136 case _move_B3:
137 return _move(B3, c);
138 default:
139 LOG("move error, unknown move\n");
140 return zero;
141 }
142}
143
144_static cube_t
145premove(cube_t c, uint8_t m)
146{
147 switch (m) {
148 case _move_U:
149 return _premove(U3, c);
150 case _move_U2:
151 return _premove(U2, c);
152 case _move_U3:
153 return _premove(U, c);
154 case _move_D:
155 return _premove(D3, c);
156 case _move_D2:
157 return _premove(D2, c);
158 case _move_D3:
159 return _premove(D, c);
160 case _move_R:
161 return _premove(R3, c);
162 case _move_R2:
163 return _premove(R2, c);
164 case _move_R3:
165 return _premove(R, c);
166 case _move_L:
167 return _premove(L3, c);
168 case _move_L2:
169 return _premove(L2, c);
170 case _move_L3:
171 return _premove(L, c);
172 case _move_F:
173 return _premove(F3, c);
174 case _move_F2:
175 return _premove(F2, c);
176 case _move_F3:
177 return _premove(F, c);
178 case _move_B:
179 return _premove(B3, c);
180 case _move_B2:
181 return _premove(B2, c);
182 case _move_B3:
183 return _premove(B, c);
184 default:
185 LOG("move error, unknown move\n");
186 return zero;
187 }
188}
189
190_static uint8_t
191inverse_move(uint8_t m)
192{
193 return m - 2 * (m % 3) + 2;
194}
195
196_static uint8_t*
197invertpremoves(uint8_t *moves, uint8_t nmoves)
198{
199 uint8_t i;
200 uint8_t *ret = malloc(nmoves * sizeof(uint8_t));
201
202 for (i = 0; i < nmoves; i++)
203 ret[i] = inverse_move(moves[i]);
204
205 // invert elements in the array
206 for (i = 0; i < nmoves / 2; i++)
207 _swap(ret[i], ret[nmoves - i - 1]);
208 return ret;
209}

Generated with cgit - Back to sebastiano.tronto.net