aboutsummaryrefslogtreecommitdiff
path: root/old/2021-06-02-cleanedup/cube.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
commit3568412f8f230774d0d11d7ed1c897424f95d3ef (patch)
tree77223792d8c925a9b1fc32b3f4341e943b5f8209 /old/2021-06-02-cleanedup/cube.h
parent67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff)
downloadnissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz
nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to '')
-rw-r--r--old/2021-06-02-cleanedup/cube.h179
1 files changed, 179 insertions, 0 deletions
diff --git a/old/2021-06-02-cleanedup/cube.h b/old/2021-06-02-cleanedup/cube.h
new file mode 100644
index 0000000..f1559a4
--- /dev/null
+++ b/old/2021-06-02-cleanedup/cube.h
@@ -0,0 +1,179 @@
1#include <stdio.h>
2#include <stdbool.h>
3#include <stdint.h>
4#include <stdlib.h>
5#include <string.h>
6
7/* Constants ****************************************************************/
8
9#define NMOVES (z3+1)
10#define NTRANS (mirror+1)
11#define NROTATIONS (NTRANS-1)
12
13/* Typedefs *****************************************************************/
14
15typedef enum center Center;
16typedef enum corner Corner;
17typedef enum edge Edge;
18typedef enum move Move;
19typedef enum trans Trans;
20
21typedef struct nissmove * Alg;
22typedef struct alglist AlgList;
23typedef struct alglistnode AlgListNode;
24typedef struct block Block;
25typedef struct cube Cube;
26typedef struct nissmove NissMove;
27typedef struct solveoptions SolveOptions;
28typedef struct step Step;
29
30/* Type specifications *******************************************************/
31
32enum
33center
34{
35 U_center, D_center,
36 R_center, L_center,
37 F_center, B_center
38};
39
40enum
41corner
42{
43 UFR, UFL, UBL, UBR,
44 DFR, DFL, DBL, DBR
45};
46
47enum
48edge
49{
50 UF, UL, UB, UR,
51 DF, DL, DB, DR,
52 FR, FL, BL, BR
53};
54
55enum
56move
57{
58 NULLMOVE,
59 U, U2, U3, D, D2, D3,
60 R, R2, R3, L, L2, L3,
61 F, F2, F3, B, B2, B3,
62 Uw, Uw2, Uw3, Dw, Dw2, Dw3,
63 Rw, Rw2, Rw3, Lw, Lw2, Lw3,
64 Fw, Fw2, Fw3, Bw, Bw2, Bw3,
65 M, M2, M3,
66 S, S2, S3,
67 E, E2, E3,
68 x, x2, x3,
69 y, y2, y3,
70 z, z2, z3,
71};
72
73enum
74trans
75{
76 uf, ur, ub, ul,
77 df, dr, db, dl,
78 rf, rd, rb, ru,
79 lf, ld, lb, lu,
80 fu, fr, fd, fl,
81 bu, br, bd, bl,
82 mirror, /* R|L */
83};
84
85struct
86alglist
87{
88 AlgListNode *first;
89 AlgListNode *last;
90 int len;
91};
92
93struct
94alglistnode
95{
96 Alg alg;
97 AlgListNode *next;
98};
99
100struct
101block
102{
103 bool edge[12];
104 bool corner[8];
105 bool center[6];
106};
107
108struct
109cube
110{
111 uint16_t epose;
112 uint16_t eposs;
113 uint16_t eposm;
114 uint16_t eofb;
115 uint16_t eorl;
116 uint16_t eoud;
117 uint16_t cp;
118 uint16_t coud;
119 uint16_t cofb;
120 uint16_t corl;
121 uint16_t cpos;
122};
123
124struct
125nissmove
126{
127 Move m;
128 bool inverse;
129};
130
131struct
132solveoptions
133{
134 int min_moves;
135 int max_moves;
136 int max_solutions;
137 bool optimal_only;
138 bool can_niss;
139 bool *moveset;
140 Move *sorted_moves;
141 Trans pre_trans;
142};
143
144struct
145step
146{
147 int (*f)(Cube);
148 bool (*ready)(Cube);
149};
150
151/* Public functions **********************************************************/
152
153Cube apply_alg(Alg alg, Cube cube);
154Cube apply_move(Move m, Cube cube);
155Cube apply_trans(Trans t, Cube cube);
156bool block_solved(Cube cube, Block);
157Center center_at(Cube cube, Center c);
158Cube compose(Cube c2, Cube c1); /* Use c2 as an alg on c1 */
159Corner corner_at(Cube cube, Corner c);
160Edge edge_at(Cube cube, Edge e);
161bool equal(Cube c1, Cube c2);
162Cube inverse_cube(Cube cube);
163Move inverse_move(Move m);
164Trans inverse_trans(Trans t);
165bool is_solved(Cube cube, bool reorient);
166int piece_orientation(Cube cube, int piece, char *orientation);
167void print_cube(Cube cube);
168AlgList * solve(Cube cube, Step step, SolveOptions opts);
169
170void concat(Alg src1, Alg src2, Alg dest);
171void copy_alg(Alg src, Alg dest);
172void invert_alg(Alg src, Alg dest);
173int len(Alg alg);
174Alg new_alg(char *str);
175void print_alg(Alg alg);
176void remove_last_moves(Alg alg, int k);
177void transform_alg(Trans t, Alg alg);
178
179void init();

Generated with cgit - Back to sebastiano.tronto.net