aboutsummaryrefslogtreecommitdiff
path: root/src/core/oriented_cube.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-25 10:09:22 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-25 10:09:22 +0200
commit7faca28009c5efb0ba2b897b34dbdcac47a1a6f3 (patch)
treefd507509d00d2926175c72f4c06b9158c3a331a7 /src/core/oriented_cube.h
parent17e5a9e1e2b241c67956651f87f40236467fe7d8 (diff)
downloadnissy-core-7faca28009c5efb0ba2b897b34dbdcac47a1a6f3.tar.gz
nissy-core-7faca28009c5efb0ba2b897b34dbdcac47a1a6f3.zip
NISS
Diffstat (limited to 'src/core/oriented_cube.h')
-rw-r--r--src/core/oriented_cube.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/core/oriented_cube.h b/src/core/oriented_cube.h
new file mode 100644
index 0000000..2c86af0
--- /dev/null
+++ b/src/core/oriented_cube.h
@@ -0,0 +1,78 @@
1STATIC oriented_cube_t solvedcube(void);
2
3STATIC oriented_cube_t move_extended(oriented_cube_t, uint8_t);
4STATIC oriented_cube_t applymoves(oriented_cube_t, const char *);
5
6/* This is used only in tests, use SOLVED_ORIENTED_CUBE everywhere else */
7STATIC oriented_cube_t
8solvedcube(void)
9{
10 return SOLVED_ORIENTED_CUBE;
11}
12
13STATIC oriented_cube_t
14compose_oriented(oriented_cube_t c, oriented_cube_t d)
15{
16 int i;
17 cube_t transformed_d;
18 oriented_cube_t ret;
19
20 transformed_d = transform(d.cube, orientation_trans[c.orientation]);
21
22 ret.cube = compose(c.cube, transformed_d);
23 ret.orientation = c.orientation;
24
25 for (i = 0; orientation_moves[d.orientation][i] != UINT8_MAX; i++)
26 ret = move_extended(ret, orientation_moves[d.orientation][i]);
27
28 return ret;
29}
30
31STATIC oriented_cube_t
32move_extended(oriented_cube_t c, uint8_t m)
33{
34 int i;
35 equivalent_moves_t eqm;
36 oriented_cube_t ret;
37
38 eqm = equivalent_moves_table[m];
39 ret = c;
40
41 for (i = 0; eqm.move[i] != UINT8_MAX; i++)
42 ret.cube = move(
43 ret.cube, reorient_move(eqm.move[i], ret.orientation));
44
45 for (i = 0; eqm.rotation[i] != UINT8_MAX; i++)
46 ret.orientation = orientation_transition_table[
47 ret.orientation][eqm.rotation[i]];
48
49 return ret;
50}
51
52STATIC oriented_cube_t
53applymoves(oriented_cube_t cube, const char *buf)
54{
55 int count;
56 uint8_t m;
57 oriented_cube_t c, cinv;
58
59 DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE,
60 "move error: inconsistent cube\n");
61
62 c = cube;
63 cinv = SOLVED_ORIENTED_CUBE;
64 FOREACH_READMOVE(buf, m, count, -1, ZERO_ORIENTED_CUBE,
65 if (!VAR_IN_PARENTHESES)
66 c = move_extended(c, m);
67 else
68 cinv = move_extended(cinv, m);
69 )
70
71 if (cinv.orientation != ORIENTATION_UF) {
72 LOG("Error applying moves: NISS part must not move centers\n");
73 return ZERO_ORIENTED_CUBE;
74 }
75
76 cinv.cube = inverse(cinv.cube);
77 return compose_oriented(cinv, c);
78}

Generated with cgit - Back to sebastiano.tronto.net