h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

coordinate.h (1672B)


      1 STATIC_INLINE int64_t coord_h48(
      2     cube_t, const uint32_t [static COCSEP_TABLESIZE], uint8_t);
      3 STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t);
      4 STATIC_INLINE cube_t invcoord_h48(
      5     int64_t, const cube_t [static COCSEP_CLASSES], uint8_t);
      6 
      7 STATIC_INLINE int64_t
      8 coord_h48(
      9 	cube_t c,
     10 	const uint32_t cocsepdata[static COCSEP_TABLESIZE],
     11 	uint8_t h
     12 )
     13 {
     14 	int64_t cocsep, coclass;
     15 	uint32_t data;
     16 	uint8_t ttrep;
     17 
     18 	DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n");
     19 
     20 	cocsep = coord_cocsep(c);
     21 	data = cocsepdata[cocsep];
     22 	coclass = (int64_t)COCLASS(data);
     23 	ttrep = (int64_t)TTREP(data);
     24 
     25 	return coord_h48_edges(c, coclass, ttrep, h);
     26 }
     27 
     28 STATIC_INLINE int64_t
     29 coord_h48_edges(cube_t c, int64_t coclass, uint8_t ttrep, uint8_t h)
     30 {
     31 	cube_t d;
     32 	int64_t esep, eo, edges;
     33 
     34 	d = transform_edges(c, ttrep);
     35 	esep = coord_esep(d);
     36 	eo = coord_eo(d);
     37 	edges = (esep << 11) + eo;
     38 
     39 	return (coclass * H48_ESIZE(11) + edges) >> (11 - (int64_t)h);
     40 }
     41 
     42 /*
     43 This function does not necessarily return a cube whose coordinate is
     44 the given value, because it works up to symmetry. This means that the
     45 returned cube is a transformed cube of one that gives the correct value.
     46 */
     47 STATIC_INLINE cube_t
     48 invcoord_h48(
     49 	int64_t i,
     50 	const cube_t crep[static COCSEP_CLASSES],
     51 	uint8_t h
     52 )
     53 {
     54 	cube_t ret;
     55 	int64_t hh, coclass, ee, esep, eo;
     56 
     57 	DBG_ASSERT(h <= 11, ZERO_CUBE,
     58 	    "invcoord_h48: h must be between 0 and 11\n");
     59 
     60 	hh = (int64_t)h;
     61 	coclass = i / H48_ESIZE(h);
     62 	ee = i % H48_ESIZE(h);
     63 	esep = ee >> hh;
     64 	eo = (ee & ((1 << hh) - 1)) << (11 - hh);
     65 
     66 	ret = invcoord_esep(esep);
     67 	copy_corners(&ret, crep[coclass]);
     68 	set_eo(&ret, eo);
     69 
     70 	return ret;
     71 }