diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-05-10 08:55:03 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-05-10 08:55:03 +0200 |
| commit | 75966319fd5891c2c1bd35b1f7c93eab172fd28e (patch) | |
| tree | 850a69906c7140be36670f2014e78ff91a96ab33 /cube.h | |
| parent | 15a072db18e441db5aa9e5339341fa1a466b504a (diff) | |
| download | nissy-core-75966319fd5891c2c1bd35b1f7c93eab172fd28e.tar.gz nissy-core-75966319fd5891c2c1bd35b1f7c93eab172fd28e.zip | |
Moved to src/
Diffstat (limited to 'cube.h')
| -rw-r--r-- | cube.h | 164 |
1 files changed, 0 insertions, 164 deletions
| @@ -1,164 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | Cube type definition | ||
| 3 | |||
| 4 | Each piece is represented by an (unsigned) 8-bit integer. The 4 | ||
| 5 | least-significant bits determine which piece it is, the other 4 determine | ||
| 6 | the orientation. | ||
| 7 | |||
| 8 | Edges are numbered as follows (see also cube.c): | ||
| 9 | UF=0 UB=1 DB=2 DF=3 UR=4 UL=5 DL=6 DR=7 FR=8 FL=9 BL=10 BR=11 | ||
| 10 | |||
| 11 | Corners are numbered as follows: | ||
| 12 | UFR=0 UBL=1 DFL=2 DBR=3 UFL=4 UBR=5 DFR=6 DBL=7 | ||
| 13 | |||
| 14 | The orientation of the edges is with respect to F/B, the orientation of | ||
| 15 | corners is with respect to U/D. | ||
| 16 | |||
| 17 | The permutation of the center pieces is not stored. This means that the | ||
| 18 | cube is assumed to be in a fixed orientation. | ||
| 19 | |||
| 20 | TODO: define EO and CO better, explain how to use them | ||
| 21 | TODO: encode centers? | ||
| 22 | |||
| 23 | The exact cube type structure depends on your system's configuration. If | ||
| 24 | you operate on the cube only via the functions provided below, you don't | ||
| 25 | need to worry about this. | ||
| 26 | ******************************************************************************/ | ||
| 27 | |||
| 28 | typedef struct { | ||
| 29 | uint8_t corner[8]; | ||
| 30 | uint8_t edge[12]; | ||
| 31 | } cube_t; | ||
| 32 | |||
| 33 | /* Returns a copy of the solved cube */ | ||
| 34 | cube_t solvedcube(void); | ||
| 35 | |||
| 36 | /* Basic checks on the cube */ | ||
| 37 | bool isconsistent(cube_t); | ||
| 38 | bool issolvable(cube_t); | ||
| 39 | bool issolved(cube_t); | ||
| 40 | bool equal(cube_t, cube_t); | ||
| 41 | |||
| 42 | /* All functions can return an error value, use iserror() to check this */ | ||
| 43 | bool iserror(cube_t); | ||
| 44 | |||
| 45 | /* Apply the second cube on the first as a move sequence */ | ||
| 46 | cube_t compose(cube_t, cube_t); | ||
| 47 | |||
| 48 | /* Invert the cube */ | ||
| 49 | cube_t inverse(cube_t); | ||
| 50 | |||
| 51 | /* Check if a cube represent a valid state (possibly unsolvable) */ | ||
| 52 | |||
| 53 | /* TODO comment on these and the format for moves and trans */ | ||
| 54 | /* For trans, only one trans is supported */ | ||
| 55 | cube_t applymoves(cube_t, const char *); | ||
| 56 | cube_t applytrans(cube_t, const char *); | ||
| 57 | |||
| 58 | /****************************************************************************** | ||
| 59 | Read / write utilities | ||
| 60 | |||
| 61 | Reading and writing is not done directly via stdin / stdout, but via an | ||
| 62 | array of char (called buf in the prototypes below). | ||
| 63 | |||
| 64 | Multiple representations of the cube as text are supported: | ||
| 65 | |||
| 66 | - H48: a human-readable format. | ||
| 67 | Each edge is represented by two letters denoting the sides it | ||
| 68 | belongs to and one number denoting its orientation (0 oriented, 1 | ||
| 69 | mis-oriented). Similarly, each corner is represented by three letters and | ||
| 70 | a number (0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise). | ||
| 71 | |||
| 72 | The solved cube looks like this: | ||
| 73 | |||
| 74 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 | ||
| 75 | UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 76 | |||
| 77 | The cube after the moves R'U'F looks like this: | ||
| 78 | |||
| 79 | FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 | ||
| 80 | UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 | ||
| 81 | |||
| 82 | Whitespace (including newlines) between pieces is ignored when reading the | ||
| 83 | cube. A single whitespace character is added between pieces when writing. | ||
| 84 | |||
| 85 | - SRC: format used to generate code for internal use. | ||
| 86 | If OUT is the output in SRC format, one can use `cube_t cube = OUT` to | ||
| 87 | declare a new cube object. | ||
| 88 | |||
| 89 | - LST: a format for internal use and generating code. | ||
| 90 | The cube is printed as a comma-separated list of 20 integers, as they appear | ||
| 91 | in cube_t. Corners come first, followed by edge (unlike H48). | ||
| 92 | ******************************************************************************/ | ||
| 93 | |||
| 94 | cube_t readcube(const char *format, const char *buf); | ||
| 95 | void writecube(const char *format, cube_t cube, char *buf); | ||
| 96 | |||
| 97 | /****************************************************************************** | ||
| 98 | Solvers | ||
| 99 | |||
| 100 | The solutions are returned as a newline-separated list of characters. Moves | ||
| 101 | are separated by single spaces. | ||
| 102 | |||
| 103 | Unless specified otherwise, all the solutions are not trivially simplifiable. | ||
| 104 | This means that sequences like U U2 or R L R will not appear in any solution. | ||
| 105 | Moreover, two consecutive parallel moves are always going to be sorted in | ||
| 106 | increasing order. For example, L R2 may never appear in a solution, but R2 L | ||
| 107 | could. | ||
| 108 | ******************************************************************************/ | ||
| 109 | |||
| 110 | int64_t solve( | ||
| 111 | /* The cube to solve. Must be solvable. */ | ||
| 112 | cube_t cube, | ||
| 113 | |||
| 114 | /* Supported solvers: | ||
| 115 | * "optimal" - currently the same as "simple" | ||
| 116 | * "simple" - a simple, slow solver without tables | ||
| 117 | */ | ||
| 118 | const char *solver, | ||
| 119 | |||
| 120 | /* Some solvers accept extra options,like "!filter". */ | ||
| 121 | const char *options, | ||
| 122 | |||
| 123 | /* Can be "normal", "inverse", "mixed" or "linear". */ | ||
| 124 | const char *nisstype, | ||
| 125 | |||
| 126 | /* The minimum number of moves. Must be >= 0. */ | ||
| 127 | int8_t minmoves, | ||
| 128 | |||
| 129 | /* The maximum number of moves. If negative, the maximum length | ||
| 130 | * is unlimited. | ||
| 131 | */ | ||
| 132 | int8_t maxmoves, | ||
| 133 | |||
| 134 | /* The maximum number of solutions. */ | ||
| 135 | int64_t maxsols, | ||
| 136 | |||
| 137 | /* All solutions at most "optimal" moves from the shortest solution | ||
| 138 | * (respecting minmoves) are found. If negative, it is ignored. | ||
| 139 | */ | ||
| 140 | int8_t optimal, | ||
| 141 | |||
| 142 | /* Some solvers require extra data to function properly (for example, | ||
| 143 | * pruning tables). This data can be generated with gendata(). | ||
| 144 | */ | ||
| 145 | const void *data, | ||
| 146 | |||
| 147 | /* The solutions (return parameter) */ | ||
| 148 | char *solutions | ||
| 149 | ); | ||
| 150 | |||
| 151 | /* Solving n cubes optimally, one solutions per cube. Options are similar | ||
| 152 | * to solve(). | ||
| 153 | */ | ||
| 154 | void multisolve( | ||
| 155 | int n, | ||
| 156 | cube_t *cube, | ||
| 157 | const char *solver, | ||
| 158 | const void *data, | ||
| 159 | char *sols | ||
| 160 | ); | ||
| 161 | |||
| 162 | /* Returns the number of bytes written to data, -1 in case of error. | ||
| 163 | * TODO: write down how much memory every solver requires. */ | ||
| 164 | int64_t gendata(const char *solver, void *data); | ||
