aboutsummaryrefslogtreecommitdiff
path: root/cube.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cube.h177
1 files changed, 159 insertions, 18 deletions
diff --git a/cube.h b/cube.h
index 56118c2..3f9b509 100644
--- a/cube.h
+++ b/cube.h
@@ -1,36 +1,177 @@
1/******************************************************************************
2Cube type definition
3
4Each piece is represented by an (unsigned) 8-bit integer. The 4
5least-significant bits determine which piece it is, the other 4 determine
6the orientation.
7
8Edges are numbered as follows (see also cube.c):
9UF=0 UB=1 DB=2 DF=3 UR=4 UL=5 DL=6 DR=7 FR=8 FL=9 BL=10 BR=11
10
11Corners are numbered as follows:
12UFR=0 UBL=1 DFL=2 DBR=3 UFL=4 UBR=5 DFR=6 DBL=7
13
14The orientation of the edges is with respect to F/B, the orientation of
15corners is with respect to U/D.
16
17The permutation of the center pieces is not stored. This means that the
18cube is assumed to be in a fixed orientation.
19
20TODO: encode centers?
21
22The exact cube type structure depends on your system's configuration. If
23you operate on the cube only via the functions provided below, you don't
24need to worry about this.
25******************************************************************************/
26
1#ifdef CUBE_AVX2 27#ifdef CUBE_AVX2
2typedef __m256i cube_t; 28typedef __m256i cube_t;
3#else 29#else
4typedef struct { 30typedef struct {
5 uint8_t c[8]; 31 uint8_t c[8]; /* Corners */
6 uint8_t e[12]; 32 uint8_t e[12]; /* Edges */
7} cube_t; 33} cube_t;
8#endif 34#endif
9 35
10typedef uint8_t move_t; 36/* Returns a copy of the solved cube */
11typedef uint8_t trans_t;
12
13int readmoves(char *, move_t *);
14void writemoves(move_t *, int, char *);
15trans_t readtrans(char *);
16void writetrans(trans_t, char *);
17
18typedef enum {AVX, H48, SRC} format_t;
19cube_t readcube(format_t, char *); /* Supports: H48 */
20void writecube(format_t, cube_t, char *); /* Supports: AVX, H48, SRC */
21
22cube_t solvedcube(void); 37cube_t solvedcube(void);
38
39/* Basic checks on the cube */
23bool issolvable(cube_t); 40bool issolvable(cube_t);
24bool equal(cube_t, cube_t); 41bool equal(cube_t, cube_t);
25bool issolved(cube_t); 42bool issolved(cube_t);
43
44/* Apply the second cube on the first as a move sequence */
45cube_t compose(cube_t, cube_t);
46
47/* Invert the cube */
48cube_t inverse(cube_t);
49
50/* All functions can return an error value, use iserror() to check this */
26bool iserror(cube_t); 51bool iserror(cube_t);
27 52
53/******************************************************************************
54Moves and transformations
55
56Moves and transformations are represented each as an (unsigned) 8 bit integer.
57
58Moves are numbered as follows:
59U=0 U2=1 U'=2 D=3 D2=4 D'=5
60R=6 R2=7 R'=8 L=9 L2=10 L'=11
61F=12 F2=13 F'=14 B=15 B2=16 B'=17
62
63TODO: NISS
64
65TODO: Extend the moveset?
66
67Transformations can be either simple rotations or a rotation composed
68with a mirroring. A composed rotation + mirror is obtained by applying
69the corresponding rotation to the solved cube mirrored along the M plane.
70
71For example, to apply the transformation RBm (mirrored RB) to a cube C:
72 1. Apply a mirror along the M plane to the solved cube
73 2. Rotate the mirrored cube with z' y2
74 3. Apply the cube C to the transformed solved cube
75 4. Apply the transformations of step 1a and 1b in reverse
76
77See cube.c for a full list of transformations.
78******************************************************************************/
79
80typedef uint8_t move_t;
81typedef uint8_t trans_t;
82
83/* Apply a move or a transformation on the cube */
28cube_t move(cube_t, move_t); 84cube_t move(cube_t, move_t);
29cube_t inverse(cube_t);
30cube_t compose(cube_t, cube_t);
31cube_t transform(cube_t, trans_t); 85cube_t transform(cube_t, trans_t);
32 86
33int16_t coord_eo(cube_t); 87/******************************************************************************
88Read / write utilities
89
90Reading and writing is not done directly via stdin / stdout, but via an
91array of char (called buf in the prototypes below).
92
93Multiple representations of the cube as text are supported, although
94not all of them are supported for both reading and writing. See below
95for details. More formats may be supported in the future.
96
97Moves are read using the standard notation. Each move (U, D, R, L, F,
98B) can be followed by a modifier (1, 2, 3, '). Whitespace (spaces, tabs,
99newlines) are ignored. Parantheses and other notation is not supported.
100TODO: parantheses for NISS
101
102For how transformations are read or written, see cube.c.
103******************************************************************************/
104
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.
144 * Supported formats: H48.
145 */
146cube_t readcube(format_t format, char *buf);
147
148/* Write the given cube to buf in the specified format.
149 * Supported formats: H48, SRC, AVX.
150 */
151void writecube(format_t 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
159/******************************************************************************
160Coordinates
161
162The coordinate functions compute one aspect of the cube (for example,
163the edge orientation) and they return it as an integer. They are used
164for example to build pruning tables for various solving methods.
165******************************************************************************/
166
167int16_t coord_eo(cube_t); /* Edge orientation */
168
169/******************************************************************************
170Solvers
171
172Solvers return -1 in case of error, the number of solutions otherwise
173
174TODO
175******************************************************************************/
34 176
35/* Solvers return -1 in case of error, the number of solutions otherwise */
36int solve_generic(cube_t, int (*)(cube_t), uint8_t, int, move_t *); 177int solve_generic(cube_t, int (*)(cube_t), uint8_t, int, move_t *);

Generated with cgit - Back to sebastiano.tronto.net