aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/core_types.h9
-rw-r--r--src/core/moves.h69
-rw-r--r--src/nissy.c12
-rw-r--r--src/nissy.h22
4 files changed, 109 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,
diff --git a/src/nissy.c b/src/nissy.c
index 93a4841..4b5d476 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -354,6 +354,18 @@ nissy_countmoves(
354} 354}
355 355
356long long 356long long
357nissy_comparemoves(
358 const char *moves1,
359 const char *moves2
360)
361{
362 if (moves1 == NULL || moves2 == NULL)
363 return NISSY_ERROR_NULL_POINTER;
364
365 return comparemoves(moves1, moves2);
366}
367
368long long
357nissy_setlogger( 369nissy_setlogger(
358 void (*log)(const char *, void *), 370 void (*log)(const char *, void *),
359 void *user_data 371 void *user_data
diff --git a/src/nissy.h b/src/nissy.h
index 0c1d18d..38fe656 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -42,6 +42,10 @@ for example 'rotation UF' or 'mirrored BL'.
42#define NISSY_STATUS_STOP 1 42#define NISSY_STATUS_STOP 1
43#define NISSY_STATUS_PAUSE 2 43#define NISSY_STATUS_PAUSE 2
44 44
45/* Possible results of move sequence comparison */
46#define NISSY_COMPARE_MOVES_EQUAL 0
47#define NISSY_COMPARE_MOVES_DIFFERENT 99
48
45/* The solved cube */ 49/* The solved cube */
46#define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL=A" 50#define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL=A"
47 51
@@ -375,6 +379,24 @@ nissy_countmoves(
375); 379);
376 380
377/* 381/*
382Parameters:
383 moves1 - The first sequence of moves to compare.
384 moves2 - The second sequence of moves to compare.
385
386Return values:
387 NISSY_ERROR_INVALID_MOVES - One of the given moves sequences is invalid.
388 NISSY_ERROR_NULL_POINTER - One of the arguments is NULL.
389 NISSY_COMPARE_MOVES_EQUAL - The two moves sequences are indentical, up
390 to swapping parallel moves.
391 NISSY_COMPARE_MOVES_DIFFERENT - The two moves sequences are different.
392*/
393long long
394nissy_comparemoves(
395 const char *moves1,
396 const char *moves2
397);
398
399/*
378Set a global logger function used by this library. Setting the logger to NULL 400Set a global logger function used by this library. Setting the logger to NULL
379disables logging. 401disables logging.
380 402

Generated with cgit - Back to sebastiano.tronto.net