diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-09 20:23:58 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-09 20:23:58 +0200 |
| commit | 1cecea625ed405c7203d1977e687da36d835fc9a (patch) | |
| tree | d7d9f365199978358d959c424e0a1208bb37b979 /src | |
| parent | 0b1930307f41db3ea7552d6b2f4666b33c64d26a (diff) | |
| download | nissy-core-1cecea625ed405c7203d1977e687da36d835fc9a.tar.gz nissy-core-1cecea625ed405c7203d1977e687da36d835fc9a.zip | |
Cleanup cube.h
Diffstat (limited to 'src')
| -rw-r--r-- | src/cube.h | 129 | ||||
| -rw-r--r-- | src/cube_generic.h | 4 |
2 files changed, 9 insertions, 124 deletions
| @@ -1,139 +1,27 @@ | |||
| 1 | /****************************************************************************** | 1 | /* TODO: change cube to const char [static 22], or const char * */ |
| 2 | Cube type definition | 2 | /* TODO: return error code */ |
| 3 | /* TODO: implement all of this, or move the implementation to cube_public.h */ | ||
| 4 | /* TODO: document in a separate file, possibly leave here 1-line comments */ | ||
| 3 | 5 | ||
| 4 | Each piece is represented by an (unsigned) 8-bit integer. The 4 | 6 | cube_t compose(cube_t cube, cube_t perm); |
| 5 | least-significant bits determine which piece it is, the other 4 determine | 7 | cube_t inverse(cube_t cube); |
| 6 | the orientation. | 8 | cube_t solvedcube(void); |
| 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 | /* Apply the second cube on the first as a move sequence */ | ||
| 29 | cube_t compose(cube_t, cube_t); | ||
| 30 | |||
| 31 | /* Invert the cube */ | ||
| 32 | cube_t inverse(cube_t); | ||
| 33 | |||
| 34 | /* Check if a cube represent a valid state (possibly unsolvable) */ | ||
| 35 | |||
| 36 | /* TODO comment on these and the format for moves and trans */ | ||
| 37 | /* For trans, only one trans is supported */ | ||
| 38 | cube_t applymoves(cube_t, const char *); | 9 | cube_t applymoves(cube_t, const char *); |
| 39 | cube_t applytrans(cube_t, const char *); | 10 | cube_t applytrans(cube_t, const char *); |
| 40 | |||
| 41 | /****************************************************************************** | ||
| 42 | Read / write utilities | ||
| 43 | |||
| 44 | Reading and writing is not done directly via stdin / stdout, but via an | ||
| 45 | array of char (called buf in the prototypes below). | ||
| 46 | |||
| 47 | Multiple representations of the cube as text are supported: | ||
| 48 | |||
| 49 | - H48: a human-readable format. | ||
| 50 | Each edge is represented by two letters denoting the sides it | ||
| 51 | belongs to and one number denoting its orientation (0 oriented, 1 | ||
| 52 | mis-oriented). Similarly, each corner is represented by three letters and | ||
| 53 | a number (0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise). | ||
| 54 | |||
| 55 | The solved cube looks like this: | ||
| 56 | |||
| 57 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 | ||
| 58 | UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 59 | |||
| 60 | The cube after the moves R'U'F looks like this: | ||
| 61 | |||
| 62 | FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 | ||
| 63 | UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 | ||
| 64 | |||
| 65 | Whitespace (including newlines) between pieces is ignored when reading the | ||
| 66 | cube. A single whitespace character is added between pieces when writing. | ||
| 67 | |||
| 68 | - SRC: format used to generate code for internal use. | ||
| 69 | If OUT is the output in SRC format, one can use `cube_t cube = OUT` to | ||
| 70 | declare a new cube object. | ||
| 71 | |||
| 72 | - LST: a format for internal use and generating code. | ||
| 73 | The cube is printed as a comma-separated list of 20 integers, as they appear | ||
| 74 | in cube_t. Corners come first, followed by edge (unlike H48). | ||
| 75 | ******************************************************************************/ | ||
| 76 | |||
| 77 | cube_t readcube(const char *format, const char *buf); | 11 | cube_t readcube(const char *format, const char *buf); |
| 78 | void writecube(const char *format, cube_t cube, char *buf); | 12 | void writecube(const char *format, cube_t cube, char *buf); |
| 79 | |||
| 80 | /****************************************************************************** | ||
| 81 | Solvers | ||
| 82 | |||
| 83 | The solutions are returned as a newline-separated list of characters. Moves | ||
| 84 | are separated by single spaces. | ||
| 85 | |||
| 86 | Unless specified otherwise, all the solutions are not trivially simplifiable. | ||
| 87 | This means that sequences like U U2 or R L R will not appear in any solution. | ||
| 88 | Moreover, two consecutive parallel moves are always going to be sorted in | ||
| 89 | increasing order. For example, L R2 may never appear in a solution, but R2 L | ||
| 90 | could. | ||
| 91 | ******************************************************************************/ | ||
| 92 | |||
| 93 | int64_t solve( | 13 | int64_t solve( |
| 94 | /* The cube to solve. Must be solvable. */ | ||
| 95 | cube_t cube, | 14 | cube_t cube, |
| 96 | |||
| 97 | /* Supported solvers: | ||
| 98 | * "optimal" - currently the same as "simple" | ||
| 99 | * "simple" - a simple, slow solver without tables | ||
| 100 | */ | ||
| 101 | const char *solver, | 15 | const char *solver, |
| 102 | |||
| 103 | /* Some solvers accept extra options,like "!filter". */ | ||
| 104 | const char *options, | 16 | const char *options, |
| 105 | |||
| 106 | /* Can be "normal", "inverse", "mixed" or "linear". */ | ||
| 107 | const char *nisstype, | 17 | const char *nisstype, |
| 108 | |||
| 109 | /* The minimum number of moves. Must be >= 0. */ | ||
| 110 | int8_t minmoves, | 18 | int8_t minmoves, |
| 111 | |||
| 112 | /* The maximum number of moves. If negative, the maximum length | ||
| 113 | * is unlimited. | ||
| 114 | */ | ||
| 115 | int8_t maxmoves, | 19 | int8_t maxmoves, |
| 116 | |||
| 117 | /* The maximum number of solutions. */ | ||
| 118 | int64_t maxsols, | 20 | int64_t maxsols, |
| 119 | |||
| 120 | /* All solutions at most "optimal" moves from the shortest solution | ||
| 121 | * (respecting minmoves) are found. If negative, it is ignored. | ||
| 122 | */ | ||
| 123 | int8_t optimal, | 21 | int8_t optimal, |
| 124 | |||
| 125 | /* Some solvers require extra data to function properly (for example, | ||
| 126 | * pruning tables). This data can be generated with gendata(). | ||
| 127 | */ | ||
| 128 | const void *data, | 22 | const void *data, |
| 129 | |||
| 130 | /* The solutions (return parameter) */ | ||
| 131 | char *solutions | 23 | char *solutions |
| 132 | ); | 24 | ); |
| 133 | |||
| 134 | /* Solving n cubes optimally, one solutions per cube. Options are similar | ||
| 135 | * to solve(). | ||
| 136 | */ | ||
| 137 | void multisolve( | 25 | void multisolve( |
| 138 | int n, | 26 | int n, |
| 139 | cube_t *cube, | 27 | cube_t *cube, |
| @@ -141,7 +29,4 @@ void multisolve( | |||
| 141 | const void *data, | 29 | const void *data, |
| 142 | char *sols | 30 | char *sols |
| 143 | ); | 31 | ); |
| 144 | |||
| 145 | /* Returns the number of bytes written to data, -1 in case of error. | ||
| 146 | * TODO: write down how much memory every solver requires. */ | ||
| 147 | int64_t gendata(const char *solver, const char *options, void *data); | 32 | int64_t gendata(const char *solver, const char *options, void *data); |
diff --git a/src/cube_generic.h b/src/cube_generic.h index 844b328..6b675ee 100644 --- a/src/cube_generic.h +++ b/src/cube_generic.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #define _move(M, c) compose(c, _move_cube_ ## M) | 1 | #define _move(M, c) compose(c, _move_cube_ ## M) |
| 2 | #define _premove(M, c) compose(_move_cube_ ## M, c) | 2 | #define _premove(M, c) compose(_move_cube_ ## M, c) |
| 3 | 3 | ||
| 4 | _static cube_t solvedcube(); | 4 | _static cube_t solvedcube(void); |
| 5 | _static bool isconsistent(cube_t); | 5 | _static bool isconsistent(cube_t); |
| 6 | _static bool issolvable(cube_t); | 6 | _static bool issolvable(cube_t); |
| 7 | _static bool issolved(cube_t); | 7 | _static bool issolved(cube_t); |
| @@ -16,7 +16,7 @@ _static cube_t transform_corners(cube_t, uint8_t); | |||
| 16 | _static cube_t transform(cube_t, uint8_t); | 16 | _static cube_t transform(cube_t, uint8_t); |
| 17 | 17 | ||
| 18 | _static cube_t | 18 | _static cube_t |
| 19 | solvedcube() | 19 | solvedcube(void) |
| 20 | { | 20 | { |
| 21 | return solved; | 21 | return solved; |
| 22 | } | 22 | } |
