cubetypes.h (9175B)
1 #ifndef CUBETYPES_H 2 #define CUBETYPES_H 3 4 #include <stdbool.h> 5 #include <inttypes.h> 6 #include <pthread.h> 7 8 #define NMOVES 55 /* Actually 54, but one is NULLMOVE */ 9 #define NTRANS 48 10 #define NROTATIONS 24 11 #define entry_group_t uint8_t /* For pruning tables */ 12 13 /* Enums *********************************************************************/ 14 15 typedef enum 16 center 17 { 18 U_center, D_center, 19 R_center, L_center, 20 F_center, B_center 21 } Center; 22 23 typedef enum 24 corner 25 { 26 UFR, UFL, UBL, UBR, 27 DFR, DFL, DBL, DBR 28 } Corner; 29 30 typedef enum 31 edge 32 { 33 UF, UL, UB, UR, 34 DF, DL, DB, DR, 35 FR, FL, BL, BR 36 } Edge; 37 38 typedef enum 39 move 40 { 41 NULLMOVE, 42 U, U2, U3, D, D2, D3, 43 R, R2, R3, L, L2, L3, 44 F, F2, F3, B, B2, B3, 45 Uw, Uw2, Uw3, Dw, Dw2, Dw3, 46 Rw, Rw2, Rw3, Lw, Lw2, Lw3, 47 Fw, Fw2, Fw3, Bw, Bw2, Bw3, 48 M, M2, M3, 49 S, S2, S3, 50 E, E2, E3, 51 x, x2, x3, 52 y, y2, y3, 53 z, z2, z3, 54 } Move; 55 56 typedef enum 57 trans 58 { 59 uf, ur, ub, ul, 60 df, dr, db, dl, 61 rf, rd, rb, ru, 62 lf, ld, lb, lu, 63 fu, fr, fd, fl, 64 bu, br, bd, bl, 65 uf_mirror, ur_mirror, ub_mirror, ul_mirror, 66 df_mirror, dr_mirror, db_mirror, dl_mirror, 67 rf_mirror, rd_mirror, rb_mirror, ru_mirror, 68 lf_mirror, ld_mirror, lb_mirror, lu_mirror, 69 fu_mirror, fr_mirror, fd_mirror, fl_mirror, 70 bu_mirror, br_mirror, bd_mirror, bl_mirror, 71 } Trans; 72 73 typedef enum 74 niss_type 75 { 76 NORMAL, LINEAR, NISS 77 } NissType; 78 79 80 /* Typedefs ******************************************************************/ 81 82 typedef struct alg Alg; 83 typedef struct alglist AlgList; 84 typedef struct alglistnode AlgListNode; 85 typedef struct block Block; 86 typedef struct command Command; 87 typedef struct commandargs CommandArgs; 88 typedef struct coordinate Coordinate; 89 typedef struct cube Cube; 90 typedef struct cubearray CubeArray; 91 typedef struct dfsarg DfsArg; 92 typedef struct estimatedata EstimateData; 93 typedef struct moveset Moveset; 94 typedef struct piecefilter PieceFilter; 95 typedef struct prunedata PruneData; 96 typedef struct solveoptions SolveOptions; 97 typedef struct step Step; 98 typedef struct symdata SymData; 99 typedef struct threaddatasolve ThreadDataSolve; 100 typedef struct threaddatagenpt ThreadDataGenpt; 101 102 typedef Cube (*AntiIndexer) (uint64_t); 103 typedef bool (*Checker) (Cube); 104 typedef uint64_t (*CoordMover) (Move, uint64_t); 105 typedef uint64_t (*CoordTransformer) (Trans, uint64_t); 106 typedef int (*Estimator) (DfsArg *); 107 typedef bool (*Validator) (Alg *); 108 typedef void (*Exec) (CommandArgs *); 109 typedef uint64_t (*Indexer) (Cube); 110 typedef CommandArgs * (*ArgParser) (int, char **); 111 typedef int (*TransDetector) (Cube, Trans *); 112 typedef int (*TransFinder) (uint64_t, Trans *); 113 114 115 /* Structs *******************************************************************/ 116 117 struct 118 alg 119 { 120 Move * move; 121 bool * inv; 122 int len; 123 int allocated; 124 }; 125 126 struct 127 alglist 128 { 129 AlgListNode * first; 130 AlgListNode * last; 131 int len; 132 }; 133 134 struct 135 alglistnode 136 { 137 Alg * alg; 138 AlgListNode * next; 139 }; 140 141 struct 142 block 143 { 144 bool edge[12]; 145 bool corner[8]; 146 bool center[6]; 147 }; 148 149 struct 150 command 151 { 152 char * name; 153 char * usage; 154 char * description; 155 ArgParser parse_args; 156 Exec exec; 157 }; 158 159 struct 160 commandargs 161 { 162 bool success; 163 Alg * scramble; 164 SolveOptions * opts; 165 Step * step; 166 Command * command; /* For help */ 167 int n; 168 char scrtype[20]; 169 bool scrstdin; 170 bool header; 171 PruneData * pd; 172 }; 173 174 struct 175 coordinate 176 { 177 Indexer index; 178 uint64_t max; 179 CoordMover move; 180 CoordTransformer transform; 181 SymData * sd; 182 TransFinder tfind; /* TODO: should be easy to remove */ 183 Coordinate * base; /* TODO: part of refactor */ 184 }; 185 186 struct 187 cube 188 { 189 int epose; 190 int eposs; 191 int eposm; 192 int eofb; 193 int eorl; 194 int eoud; 195 int cp; 196 int coud; 197 int cofb; 198 int corl; 199 int cpos; 200 }; 201 202 struct 203 cubearray 204 { 205 int * ep; 206 int * eofb; 207 int * eorl; 208 int * eoud; 209 int * cp; 210 int * coud; 211 int * corl; 212 int * cofb; 213 int * cpos; 214 }; 215 216 struct 217 dfsarg 218 { 219 Step * step; 220 SolveOptions * opts; 221 Trans t; 222 Cube cube; 223 Cube inverse; 224 int d; 225 uint64_t badmoves; 226 uint64_t badmovesinv; 227 bool niss; 228 Move last1; 229 Move last2; 230 Move last1inv; 231 Move last2inv; 232 EstimateData * ed; 233 AlgList * sols; 234 pthread_mutex_t * sols_mutex; 235 Alg * current_alg; 236 }; 237 238 struct 239 estimatedata 240 { 241 int corners; 242 int normal_ud; 243 int normal_fb; 244 int normal_rl; 245 int inverse_ud; 246 int inverse_fb; 247 int inverse_rl; 248 int oldret; 249 }; 250 251 struct 252 moveset 253 { 254 bool (*allowed)(Move); 255 bool (*allowed_next)(Move, Move, Move); 256 Move sorted_moves[NMOVES+1]; 257 uint64_t mask[NMOVES][NMOVES]; 258 }; 259 260 struct 261 piecefilter 262 { 263 bool epose; 264 bool eposs; 265 bool eposm; 266 bool eofb; 267 bool eorl; 268 bool eoud; 269 bool cp; 270 bool coud; 271 bool cofb; 272 bool corl; 273 bool cpos; 274 }; 275 276 struct 277 prunedata 278 { 279 char * filename; 280 entry_group_t * ptable; 281 bool generated; 282 uint64_t n; 283 Coordinate * coord; 284 Moveset * moveset; 285 bool compact; 286 int base; 287 uint64_t count[16]; 288 PruneData * fallback; 289 uint64_t fbmod; 290 }; 291 292 struct 293 solveoptions 294 { 295 int min_moves; 296 int max_moves; 297 int max_solutions; 298 int nthreads; 299 int optimal; 300 NissType nisstype; 301 bool verbose; 302 bool all; 303 bool print_number; 304 bool count_only; 305 }; 306 307 struct 308 step 309 { 310 char * shortname; 311 char * name; 312 bool final; 313 Checker is_done; 314 Estimator estimate; 315 Checker ready; 316 char * ready_msg; 317 Validator is_valid; 318 Moveset * moveset; 319 Trans pre_trans; 320 TransDetector detect; 321 int ntables; 322 PruneData * tables[10]; 323 }; 324 325 struct 326 symdata 327 { 328 char * filename; 329 bool generated; 330 Coordinate * coord; 331 Coordinate * sym_coord; 332 int ntrans; 333 Trans * trans; 334 uint64_t * class; 335 uint64_t * unsym; 336 Trans * transtorep; 337 uint64_t * selfsim; 338 CoordTransformer transform; /* TODO: remove, use that of base coord */ 339 }; 340 341 struct 342 threaddatasolve 343 { 344 int thid; 345 Trans t; 346 Cube cube; 347 Step * step; 348 int depth; 349 SolveOptions * opts; 350 AlgList * start; 351 AlgListNode ** node; 352 AlgList * sols; 353 pthread_mutex_t * start_mutex; 354 pthread_mutex_t * sols_mutex; 355 }; 356 357 struct 358 threaddatagenpt 359 { 360 int thid; 361 int nthreads; 362 PruneData * pd; 363 int d; 364 int nchunks; 365 pthread_mutex_t ** mutex; 366 pthread_mutex_t * upmutex; 367 }; 368 369 #endif