aboutsummaryrefslogtreecommitdiff
path: root/cube.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-11-10 14:44:48 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-11-10 14:44:48 +0100
commitfb9ae9e41eaf01b3651395fdd450ac1a4743e592 (patch)
tree8fb29e9b62d40d6407f082f55a7164775154bf78 /cube.h
parent04c3ee1f5acac47650be8d0ffbf90e238df0d12b (diff)
downloadnissy-core-fb9ae9e41eaf01b3651395fdd450ac1a4743e592.tar.gz
nissy-core-fb9ae9e41eaf01b3651395fdd450ac1a4743e592.zip
Big changes to the interface
Diffstat (limited to '')
-rw-r--r--cube.h161
1 files changed, 52 insertions, 109 deletions
diff --git a/cube.h b/cube.h
index 889569f..d8896d8 100644
--- a/cube.h
+++ b/cube.h
@@ -17,6 +17,7 @@ corners is with respect to U/D.
17The permutation of the center pieces is not stored. This means that the 17The permutation of the center pieces is not stored. This means that the
18cube is assumed to be in a fixed orientation. 18cube is assumed to be in a fixed orientation.
19 19
20TODO: define EO and CO better, explain how to use them
20TODO: encode centers? 21TODO: encode centers?
21 22
22The exact cube type structure depends on your system's configuration. If 23The exact cube type structure depends on your system's configuration. If
@@ -24,22 +25,22 @@ you operate on the cube only via the functions provided below, you don't
24need to worry about this. 25need to worry about this.
25******************************************************************************/ 26******************************************************************************/
26 27
27#ifdef CUBE_AVX2
28typedef __m256i cube_t;
29#else
30typedef struct { 28typedef struct {
31 uint8_t c[8]; /* Corners */ 29 uint8_t corner[8];
32 uint8_t e[12]; /* Edges */ 30 uint8_t edge[12];
33} cube_t; 31} cube_t;
34#endif
35 32
36/* Returns a copy of the solved cube */ 33/* Returns a copy of the solved cube */
37cube_t solvedcube(void); 34cube_t solvedcube(void);
38 35
39/* Basic checks on the cube */ 36/* Basic checks on the cube */
37bool isconsistent(cube_t);
40bool issolvable(cube_t); 38bool issolvable(cube_t);
41bool equal(cube_t, cube_t);
42bool issolved(cube_t); 39bool issolved(cube_t);
40bool equal(cube_t, cube_t);
41
42/* All functions can return an error value, use iserror() to check this */
43bool iserror(cube_t);
43 44
44/* Apply the second cube on the first as a move sequence */ 45/* Apply the second cube on the first as a move sequence */
45cube_t compose(cube_t, cube_t); 46cube_t compose(cube_t, cube_t);
@@ -47,134 +48,75 @@ cube_t compose(cube_t, cube_t);
47/* Invert the cube */ 48/* Invert the cube */
48cube_t inverse(cube_t); 49cube_t inverse(cube_t);
49 50
50/* All functions can return an error value, use iserror() to check this */ 51/* Check if a cube represent a valid state (possibly unsolvable) */
51bool iserror(cube_t);
52
53/******************************************************************************
54Moves and transformations
55
56Moves and transformations are represented each as an (unsigned) 8 bit integer.
57 52
58Moves are numbered as follows: 53/* TODO comment on these and the format for moves and trans */
59U=0 U2=1 U'=2 D=3 D2=4 D'=5 54/* For trans, only one trans is supported */
60R=6 R2=7 R'=8 L=9 L2=10 L'=11 55cube_t applymoves(cube_t, char *);
61F=12 F2=13 F'=14 B=15 B2=16 B'=17 56cube_t applytrans(cube_t, char *);
62 57
63TODO: NISS 58/******************************************************************************
59Read / write utilities
64 60
65TODO: Extend the moveset? 61Reading and writing is not done directly via stdin / stdout, but via an
62array of char (called buf in the prototypes below).
66 63
67Transformations can be either simple rotations or a rotation composed 64Multiple representations of the cube as text are supported:
68with a mirroring. A composed rotation + mirror is obtained by applying
69the corresponding rotation to the solved cube mirrored along the M plane.
70 65
71For example, to apply the transformation RBm (mirrored RB) to a cube C: 66- H48: a human-readable format.
72 1. Apply a mirror along the M plane to the solved cube 67 Each edge is represented by two letters denoting the sides it
73 2. Rotate the mirrored cube with z' y2 68 belongs to and one number denoting its orientation (0 oriented, 1
74 3. Apply the cube C to the transformed solved cube 69 mis-oriented). Similarly, each corner is represented by three letters and
75 4. Apply the transformations of step 1a and 1b in reverse 70 a number (0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise).
76 71
77See cube.c for a full list of transformations. 72 The solved cube looks like this:
78******************************************************************************/
79 73
80typedef uint8_t move_t; 74 UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
81typedef uint8_t trans_t; 75 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
82 76
83/* Apply a move or a transformation on the cube */ 77 The cube after the moves R'U'F looks like this:
84cube_t move(cube_t, move_t);
85cube_t transform(cube_t, trans_t);
86 78
87/****************************************************************************** 79 FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
88Read / write utilities 80 UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
89 81
90Reading and writing is not done directly via stdin / stdout, but via an 82 Whitespace (including newlines) between pieces is ignored when reading the
91array of char (called buf in the prototypes below). 83 cube. A single whitespace character is added between pieces when writing.
92 84
93Multiple representations of the cube as text are supported, although 85- SRC: format used to generate code for internal use.
94not all of them are supported for both reading and writing. See below 86 In cube.c, a type called cube_array_t is defined and used for basic,
95for details. More formats may be supported in the future. 87 non-performance-critical methods. If OUT is the output in SRC format,
88 the following line can be used to declare a new cube object:
96 89
97Moves are read using the standard notation. Each move (U, D, R, L, F, 90cube_array_t cube = OUT
98B) can be followed by a modifier (1, 2, 3, '). Whitespace (spaces, tabs, 91
99newlines) are ignored. Parantheses and other notation is not supported. 92- AVX: analogue to SRC, but for the AVX2 internal representation of the cube.
100TODO: parantheses for NISS
101 93
102For how transformations are read or written, see cube.c. 94Not all formats are supported for both reading and writing. More formats
95may be supported in the future.
103******************************************************************************/ 96******************************************************************************/
104 97
105/* The different formats for reading or writing the cube */
106typedef enum {
107 H48, /* H48 is a human-readable format.
108 *
109 * Each edge is represented by two letters denoting the sides it
110 * belongs to and one number denoting its orientation (0 oriented,
111 * 1 mis-oriented). Similarly, each corner is represented by three
112 * letters and a number (0 oriented, 1 twisted clockwise, 2
113 * twisted counter-clockwise).
114 *
115 * The solved cube looks like this:
116 *
117 * UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
118 * UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
119 *
120 * The cube after the moves R'U'F looks like this:
121 *
122 * FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
123 * UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
124 *
125 * Whitespace (including newlines) between pieces is ignored when
126 * reading the cube. A single whitespace character is added
127 * between pieces when writing.
128 */
129 SRC, /* The SRC format can be used to generate code for internal use.
130 *
131 * In cube.c, a type called cube_array_t is defined and used for
132 * basic, non-performance-critical methods. If OUT is the output
133 * in SRC format, the following line can be used to declare a new
134 * cube object:
135 *
136 * cube_array_t cube = OUT
137 */
138 AVX, /* The AVX format is analogous to SRC, but for the AVX2 internal
139 * representation of the cube.
140 */
141} format_t;
142
143/* Reads a cube from buf in the specified format, and return it. 98/* Reads a cube from buf in the specified format, and return it.
144 * Supported formats: H48. 99 * Supported formats: "H48".
145 */ 100 */
146cube_t readcube(format_t format, char *buf); 101cube_t readcube(char *format, char *buf);
147 102
148/* Write the given cube to buf in the specified format. 103/* Write the given cube to buf in the specified format.
149 * Supported formats: H48, SRC, AVX. 104 * Supported formats: "H48", "SRC", "AVX".
150 */ 105 */
151void writecube(format_t format, cube_t cube, char *buf); 106void writecube(char *format, cube_t cube, char *buf);
152
153/* Utilities for reading and writing moves */
154int readmoves(char *buf, move_t *moves);
155void writemoves(move_t *moves, int n, char *buf);
156trans_t readtrans(char *buf);
157void writetrans(trans_t trans, char *buf);
158 107
159/****************************************************************************** 108/******************************************************************************
160Coordinates 109Coordinates
161 110
162The coordinate functions compute one aspect of the cube (for example, 111TODO description
163the edge orientation) and they return it as an integer. They are used
164for example to build pruning tables for various solving methods.
165******************************************************************************/ 112******************************************************************************/
166 113
167int16_t coord_eo(cube_t); /* Edge orientation */ 114int64_t coord_eo(cube_t);
168 115
169/****************************************************************************** 116/******************************************************************************
170Solvers 117Solvers
171 118
172All solvers work at fixed depth, i.e. they will only find solutions of the 119The solutions are returned as a newline-separated list of characters.
173specified length. Iterating over the possible lengths, if desired, is left as
174an implementation detail for the user of this library.
175
176The solutions are returned as a list of moves, which can then be converted to
177a string using writemoves().
178 120
179Unless specified otherwise, all the solutions are not trivially simplifiable. 121Unless specified otherwise, all the solutions are not trivially simplifiable.
180This means that sequences like U U2 or R L R will not appear in any solution. 122This means that sequences like U U2 or R L R will not appear in any solution.
@@ -188,6 +130,7 @@ TODO NISS / INVERSE / LINEAR as a mask?
188 130
189All solvers take at least the following parameters, satisfying the conditions 131All solvers take at least the following parameters, satisfying the conditions
190in square brackets: 132in square brackets:
133TODO more!
191 - cube_t cube [issolvable(cube)]: The cube to solve. 134 - cube_t cube [issolvable(cube)]: The cube to solve.
192 - uint8_t depth [depth <= 20]: The lenght of the solution. 135 - uint8_t depth [depth <= 20]: The lenght of the solution.
193 - int maxsols: The maximum number of solutions to find. The solver 136 - int maxsols: The maximum number of solutions to find. The solver
@@ -201,12 +144,12 @@ in square brackets:
201Some solvers take other parameters. See below for details. 144Some solvers take other parameters. See below for details.
202******************************************************************************/ 145******************************************************************************/
203 146
147/* TODO
204int solve_generic( 148int solve_generic(
205 cube_t cube, 149 cube_t cube,
206 uint8_t depth, 150 uint8_t depth,
207 int maxsols, 151 int maxsols,
208 move_t *ret 152 uint8_t *ret, // TODO change to char
209 int (*estimate)(cube_t), 153 int (*estimate)(cube_t)
210); 154);
211 155*/
212int solve_light(cube_t, int

Generated with cgit - Back to sebastiano.tronto.net