diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
| commit | 3568412f8f230774d0d11d7ed1c897424f95d3ef (patch) | |
| tree | 77223792d8c925a9b1fc32b3f4341e943b5f8209 /old/2021-06-02-cleanedup/cube.h | |
| parent | 67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff) | |
| download | nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip | |
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'old/2021-06-02-cleanedup/cube.h')
| -rw-r--r-- | old/2021-06-02-cleanedup/cube.h | 179 |
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 | |||
| 15 | typedef enum center Center; | ||
| 16 | typedef enum corner Corner; | ||
| 17 | typedef enum edge Edge; | ||
| 18 | typedef enum move Move; | ||
| 19 | typedef enum trans Trans; | ||
| 20 | |||
| 21 | typedef struct nissmove * Alg; | ||
| 22 | typedef struct alglist AlgList; | ||
| 23 | typedef struct alglistnode AlgListNode; | ||
| 24 | typedef struct block Block; | ||
| 25 | typedef struct cube Cube; | ||
| 26 | typedef struct nissmove NissMove; | ||
| 27 | typedef struct solveoptions SolveOptions; | ||
| 28 | typedef struct step Step; | ||
| 29 | |||
| 30 | /* Type specifications *******************************************************/ | ||
| 31 | |||
| 32 | enum | ||
| 33 | center | ||
| 34 | { | ||
| 35 | U_center, D_center, | ||
| 36 | R_center, L_center, | ||
| 37 | F_center, B_center | ||
| 38 | }; | ||
| 39 | |||
| 40 | enum | ||
| 41 | corner | ||
| 42 | { | ||
| 43 | UFR, UFL, UBL, UBR, | ||
| 44 | DFR, DFL, DBL, DBR | ||
| 45 | }; | ||
| 46 | |||
| 47 | enum | ||
| 48 | edge | ||
| 49 | { | ||
| 50 | UF, UL, UB, UR, | ||
| 51 | DF, DL, DB, DR, | ||
| 52 | FR, FL, BL, BR | ||
| 53 | }; | ||
| 54 | |||
| 55 | enum | ||
| 56 | move | ||
| 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 | |||
| 73 | enum | ||
| 74 | trans | ||
| 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 | |||
| 85 | struct | ||
| 86 | alglist | ||
| 87 | { | ||
| 88 | AlgListNode *first; | ||
| 89 | AlgListNode *last; | ||
| 90 | int len; | ||
| 91 | }; | ||
| 92 | |||
| 93 | struct | ||
| 94 | alglistnode | ||
| 95 | { | ||
| 96 | Alg alg; | ||
| 97 | AlgListNode *next; | ||
| 98 | }; | ||
| 99 | |||
| 100 | struct | ||
| 101 | block | ||
| 102 | { | ||
| 103 | bool edge[12]; | ||
| 104 | bool corner[8]; | ||
| 105 | bool center[6]; | ||
| 106 | }; | ||
| 107 | |||
| 108 | struct | ||
| 109 | cube | ||
| 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 | |||
| 124 | struct | ||
| 125 | nissmove | ||
| 126 | { | ||
| 127 | Move m; | ||
| 128 | bool inverse; | ||
| 129 | }; | ||
| 130 | |||
| 131 | struct | ||
| 132 | solveoptions | ||
| 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 | |||
| 144 | struct | ||
| 145 | step | ||
| 146 | { | ||
| 147 | int (*f)(Cube); | ||
| 148 | bool (*ready)(Cube); | ||
| 149 | }; | ||
| 150 | |||
| 151 | /* Public functions **********************************************************/ | ||
| 152 | |||
| 153 | Cube apply_alg(Alg alg, Cube cube); | ||
| 154 | Cube apply_move(Move m, Cube cube); | ||
| 155 | Cube apply_trans(Trans t, Cube cube); | ||
| 156 | bool block_solved(Cube cube, Block); | ||
| 157 | Center center_at(Cube cube, Center c); | ||
| 158 | Cube compose(Cube c2, Cube c1); /* Use c2 as an alg on c1 */ | ||
| 159 | Corner corner_at(Cube cube, Corner c); | ||
| 160 | Edge edge_at(Cube cube, Edge e); | ||
| 161 | bool equal(Cube c1, Cube c2); | ||
| 162 | Cube inverse_cube(Cube cube); | ||
| 163 | Move inverse_move(Move m); | ||
| 164 | Trans inverse_trans(Trans t); | ||
| 165 | bool is_solved(Cube cube, bool reorient); | ||
| 166 | int piece_orientation(Cube cube, int piece, char *orientation); | ||
| 167 | void print_cube(Cube cube); | ||
| 168 | AlgList * solve(Cube cube, Step step, SolveOptions opts); | ||
| 169 | |||
| 170 | void concat(Alg src1, Alg src2, Alg dest); | ||
| 171 | void copy_alg(Alg src, Alg dest); | ||
| 172 | void invert_alg(Alg src, Alg dest); | ||
| 173 | int len(Alg alg); | ||
| 174 | Alg new_alg(char *str); | ||
| 175 | void print_alg(Alg alg); | ||
| 176 | void remove_last_moves(Alg alg, int k); | ||
| 177 | void transform_alg(Trans t, Alg alg); | ||
| 178 | |||
| 179 | void init(); | ||
