nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

oriented_cube.h (1839B)


      1 STATIC oriented_cube_t solvedcube(void);
      2 
      3 STATIC oriented_cube_t move_extended(oriented_cube_t, uint8_t);
      4 STATIC oriented_cube_t applymoves(oriented_cube_t, const char *);
      5 
      6 /* This is used only in tests, use SOLVED_ORIENTED_CUBE everywhere else */
      7 STATIC oriented_cube_t
      8 solvedcube(void)
      9 {
     10 	return SOLVED_ORIENTED_CUBE;
     11 }
     12 
     13 STATIC oriented_cube_t
     14 compose_oriented(oriented_cube_t c, oriented_cube_t d)
     15 {
     16 	int i;
     17 	cube_t transformed_d;
     18 	oriented_cube_t ret;
     19 
     20 	transformed_d = transform(d.cube, orientation_trans[c.orientation]);
     21 
     22 	ret.cube = compose(c.cube, transformed_d);
     23 	ret.orientation = c.orientation;
     24 
     25 	for (i = 0; orientation_moves[d.orientation][i] != UINT8_MAX; i++)
     26 		ret = move_extended(ret, orientation_moves[d.orientation][i]);
     27 
     28 	return ret;
     29 }
     30 
     31 STATIC oriented_cube_t
     32 move_extended(oriented_cube_t c, uint8_t m)
     33 {
     34 	int i;
     35 	equivalent_moves_t eqm;
     36 	oriented_cube_t ret;
     37 
     38 	eqm = equivalent_moves_table[m];
     39 	ret = c;
     40 
     41 	for (i = 0; eqm.move[i] != UINT8_MAX; i++)
     42 		ret.cube = move(
     43 		    ret.cube, reorient_move(eqm.move[i], ret.orientation));
     44 
     45 	for (i = 0; eqm.rotation[i] != UINT8_MAX; i++)
     46 		ret.orientation = orientation_transition_table[
     47 		    ret.orientation][eqm.rotation[i]];
     48 
     49 	return ret;
     50 }
     51 
     52 STATIC oriented_cube_t
     53 applymoves(oriented_cube_t cube, const char *buf)
     54 {
     55 	int count;
     56 	uint8_t m;
     57 	oriented_cube_t c, cinv;
     58 
     59 	DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE,
     60 	    "move error: inconsistent cube\n");
     61 
     62 	c = cube;
     63 	cinv = SOLVED_ORIENTED_CUBE;
     64 	FOREACH_READMOVE(buf, m, count, -1, ZERO_ORIENTED_CUBE,
     65 		if (!VAR_IN_PARENTHESES)
     66 			c = move_extended(c, m);
     67 		else
     68 			cinv = move_extended(cinv, m);
     69 	)
     70 
     71 	if (cinv.orientation != ORIENTATION_UF) {
     72 		LOG("Error applying moves: NISS part must not move centers\n");
     73 		return ZERO_ORIENTED_CUBE;
     74 	}
     75 
     76 	cinv.cube = inverse(cinv.cube);
     77 	return compose_oriented(cinv, c);
     78 }