From 7faca28009c5efb0ba2b897b34dbdcac47a1a6f3 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 25 Apr 2025 10:09:22 +0200 Subject: NISS --- src/core/oriented_cube.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/core/oriented_cube.h (limited to 'src/core/oriented_cube.h') diff --git a/src/core/oriented_cube.h b/src/core/oriented_cube.h new file mode 100644 index 0000000..2c86af0 --- /dev/null +++ b/src/core/oriented_cube.h @@ -0,0 +1,78 @@ +STATIC oriented_cube_t solvedcube(void); + +STATIC oriented_cube_t move_extended(oriented_cube_t, uint8_t); +STATIC oriented_cube_t applymoves(oriented_cube_t, const char *); + +/* This is used only in tests, use SOLVED_ORIENTED_CUBE everywhere else */ +STATIC oriented_cube_t +solvedcube(void) +{ + return SOLVED_ORIENTED_CUBE; +} + +STATIC oriented_cube_t +compose_oriented(oriented_cube_t c, oriented_cube_t d) +{ + int i; + cube_t transformed_d; + oriented_cube_t ret; + + transformed_d = transform(d.cube, orientation_trans[c.orientation]); + + ret.cube = compose(c.cube, transformed_d); + ret.orientation = c.orientation; + + for (i = 0; orientation_moves[d.orientation][i] != UINT8_MAX; i++) + ret = move_extended(ret, orientation_moves[d.orientation][i]); + + return ret; +} + +STATIC oriented_cube_t +move_extended(oriented_cube_t c, uint8_t m) +{ + int i; + equivalent_moves_t eqm; + oriented_cube_t ret; + + eqm = equivalent_moves_table[m]; + ret = c; + + for (i = 0; eqm.move[i] != UINT8_MAX; i++) + ret.cube = move( + ret.cube, reorient_move(eqm.move[i], ret.orientation)); + + for (i = 0; eqm.rotation[i] != UINT8_MAX; i++) + ret.orientation = orientation_transition_table[ + ret.orientation][eqm.rotation[i]]; + + return ret; +} + +STATIC oriented_cube_t +applymoves(oriented_cube_t cube, const char *buf) +{ + int count; + uint8_t m; + oriented_cube_t c, cinv; + + DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE, + "move error: inconsistent cube\n"); + + c = cube; + cinv = SOLVED_ORIENTED_CUBE; + FOREACH_READMOVE(buf, m, count, -1, ZERO_ORIENTED_CUBE, + if (!VAR_IN_PARENTHESES) + c = move_extended(c, m); + else + cinv = move_extended(cinv, m); + ) + + if (cinv.orientation != ORIENTATION_UF) { + LOG("Error applying moves: NISS part must not move centers\n"); + return ZERO_ORIENTED_CUBE; + } + + cinv.cube = inverse(cinv.cube); + return compose_oriented(cinv, c); +} -- cgit v1.3