aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-31 09:47:57 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-31 09:47:57 +0200
commit992de12cc081e7dde16c3c231f83bfa77c67825a (patch)
treeaf0b2d51b1a6cd92ae2cd6a32d581d752ddce8ea /src/core
parente2b154c40acaac4e7a7b3e379ada0404519c3750 (diff)
downloadnissy-core-992de12cc081e7dde16c3c231f83bfa77c67825a.tar.gz
nissy-core-992de12cc081e7dde16c3c231f83bfa77c67825a.zip
Added move sequence comparison function
Diffstat (limited to '')
-rw-r--r--src/core/core_types.h9
-rw-r--r--src/core/moves.h69
2 files changed, 75 insertions, 3 deletions
diff --git a/src/core/core_types.h b/src/core/core_types.h
index 2ad8938..19a9f42 100644
--- a/src/core/core_types.h
+++ b/src/core/core_types.h
@@ -1,4 +1,13 @@
1#define MOVES_STRUCT_MAXLEN 1000
2
1typedef struct { 3typedef struct {
2 cube_t cube; 4 cube_t cube;
3 uint8_t orientation; 5 uint8_t orientation;
4} oriented_cube_t; 6} oriented_cube_t;
7
8typedef struct {
9 size_t nnormal;
10 size_t ninverse;
11 uint8_t normal[MOVES_STRUCT_MAXLEN];
12 uint8_t inverse[MOVES_STRUCT_MAXLEN];
13} moves_struct_t;
diff --git a/src/core/moves.h b/src/core/moves.h
index d3ff4a3..9c8cc90 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -3,8 +3,12 @@
3 3
4STATIC uint8_t readmove(char); 4STATIC uint8_t readmove(char);
5STATIC int64_t readmoves(const char *, 5STATIC int64_t readmoves(const char *,
6 size_t, size_t, uint64_t *, uint64_t *, uint8_t *, uint8_t *); 6 size_t, size_t, size_t *, size_t *, uint8_t *, uint8_t *);
7STATIC int64_t readmoves_struct(const char *, moves_struct_t [static 1]);
7STATIC int64_t countmoves(const char *); 8STATIC int64_t countmoves(const char *);
9STATIC bool moves_struct_equal(
10 const moves_struct_t [static 1], const moves_struct_t [static 1]);
11STATIC long long comparemoves(const char *, const char *);
8STATIC uint8_t readmodifier(char); 12STATIC uint8_t readmodifier(char);
9STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *); 13STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *);
10 14
@@ -124,8 +128,8 @@ readmoves(
124 const char *buf, 128 const char *buf,
125 size_t nsize, 129 size_t nsize,
126 size_t invsize, 130 size_t invsize,
127 uint64_t *n, 131 size_t *n,
128 uint64_t *i, 132 size_t *i,
129 uint8_t *normal, 133 uint8_t *normal,
130 uint8_t *inverse 134 uint8_t *inverse
131) 135)
@@ -154,6 +158,13 @@ readmoves(
154} 158}
155 159
156STATIC int64_t 160STATIC int64_t
161readmoves_struct(const char *moves, moves_struct_t ret[static 1])
162{
163 return readmoves(moves, MOVES_STRUCT_MAXLEN, MOVES_STRUCT_MAXLEN,
164 &ret->nnormal, &ret->ninverse, ret->normal, ret->inverse);
165}
166
167STATIC int64_t
157countmoves(const char *buf) 168countmoves(const char *buf)
158{ 169{
159 uint8_t m; 170 uint8_t m;
@@ -168,6 +179,58 @@ countmoves(const char *buf)
168 return count; 179 return count;
169} 180}
170 181
182STATIC bool
183moves_struct_equal(
184 const moves_struct_t ms1[static 1],
185 const moves_struct_t ms2[static 1]
186)
187{
188 size_t i;
189
190 if (ms1->nnormal != ms2->nnormal || ms1->ninverse != ms2->ninverse)
191 return false;
192
193 for (i = 0; i < ms1->nnormal; i++)
194 if (ms1->normal[i] != ms2->normal[i])
195 return false;
196
197 for (i = 0; i < ms1->ninverse; i++)
198 if (ms1->inverse[i] != ms2->inverse[i])
199 return false;
200
201 return true;
202}
203
204STATIC long long
205comparemoves(const char *moves1, const char *moves2)
206{
207 int64_t err;
208 moves_struct_t ms1, ms2;
209
210 if ((err = readmoves_struct(moves1, &ms1)) < 0)
211 return err;
212 sortparallel_moves(ms1.nnormal, ms1.normal);
213 sortparallel_moves(ms1.ninverse, ms1.inverse);
214
215 if ((err = readmoves_struct(moves2, &ms2)) < 0)
216 return err;
217 sortparallel_moves(ms2.nnormal, ms2.normal);
218 sortparallel_moves(ms2.ninverse, ms2.inverse);
219
220 if (moves_struct_equal(&ms1, &ms2))
221 return NISSY_COMPARE_MOVES_EQUAL;
222
223 /*
224 TODO: more types of move comparison
225 - up to moving rotations around
226 - up to rotation
227 - up transformation (including mirror or not including it)
228 - ...
229 */
230
231 return NISSY_COMPARE_MOVES_DIFFERENT;
232}
233
171STATIC int64_t 234STATIC int64_t
172writemoves( 235writemoves(
173 size_t nmoves, 236 size_t nmoves,

Generated with cgit - Back to sebastiano.tronto.net