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

commit 7faca28009c5efb0ba2b897b34dbdcac47a1a6f3
parent 17e5a9e1e2b241c67956651f87f40236467fe7d8
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 25 Apr 2025 10:09:22 +0200

NISS

Diffstat:
Msrc/core/constants.h | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Msrc/core/core.h | 1+
Msrc/core/cube.h | 8--------
Msrc/core/moves.h | 84+++++++++++++++++++++++++++----------------------------------------------------
Asrc/core/oriented_cube.h | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/nissy.h | 2++
Msrc/solvers/coord/dr.h | 2+-
Msrc/solvers/coord/dreo.h | 2+-
Msrc/solvers/coord/eo.h | 2+-
Msrc/solvers/coord/types_macros.h | 2+-
Msrc/solvers/h48/solve.h | 31+++++++++++++++----------------
Rtest/030_move/000_nomove_solved.in -> test/030_applymoves/000_nomove_solved.in | 0
Rtest/030_move/000_nomove_solved.out -> test/030_applymoves/000_nomove_solved.out | 0
Rtest/030_move/001_nomove_scrambled.in -> test/030_applymoves/001_nomove_scrambled.in | 0
Rtest/030_move/001_nomove_scrambled.out -> test/030_applymoves/001_nomove_scrambled.out | 0
Rtest/030_move/010_U_solved.in -> test/030_applymoves/010_U_solved.in | 0
Rtest/030_move/010_U_solved.out -> test/030_applymoves/010_U_solved.out | 0
Rtest/030_move/011_U_scrambled.in -> test/030_applymoves/011_U_scrambled.in | 0
Rtest/030_move/011_U_scrambled.out -> test/030_applymoves/011_U_scrambled.out | 0
Rtest/030_move/012_U_inverse.in -> test/030_applymoves/012_U_inverse.in | 0
Rtest/030_move/012_U_inverse.out -> test/030_applymoves/012_U_inverse.out | 0
Rtest/030_move/020_U2_solved.in -> test/030_applymoves/020_U2_solved.in | 0
Rtest/030_move/020_U2_solved.out -> test/030_applymoves/020_U2_solved.out | 0
Rtest/030_move/021_U2_scrambled.in -> test/030_applymoves/021_U2_scrambled.in | 0
Rtest/030_move/021_U2_scrambled.out -> test/030_applymoves/021_U2_scrambled.out | 0
Rtest/030_move/022_U2_inverse.in -> test/030_applymoves/022_U2_inverse.in | 0
Rtest/030_move/022_U2_inverse.out -> test/030_applymoves/022_U2_inverse.out | 0
Rtest/030_move/030_U3_solved.in -> test/030_applymoves/030_U3_solved.in | 0
Rtest/030_move/030_U3_solved.out -> test/030_applymoves/030_U3_solved.out | 0
Rtest/030_move/031_U3_inverse.in -> test/030_applymoves/031_U3_inverse.in | 0
Rtest/030_move/031_U3_inverse.out -> test/030_applymoves/031_U3_inverse.out | 0
Rtest/030_move/032_U3_scrambled.in -> test/030_applymoves/032_U3_scrambled.in | 0
Rtest/030_move/032_U3_scrambled.out -> test/030_applymoves/032_U3_scrambled.out | 0
Rtest/030_move/033_U3_with_prime.in -> test/030_applymoves/033_U3_with_prime.in | 0
Rtest/030_move/033_U3_with_prime.out -> test/030_applymoves/033_U3_with_prime.out | 0
Rtest/030_move/040_D_solved.in -> test/030_applymoves/040_D_solved.in | 0
Rtest/030_move/040_D_solved.out -> test/030_applymoves/040_D_solved.out | 0
Rtest/030_move/050_D2_solved.in -> test/030_applymoves/050_D2_solved.in | 0
Rtest/030_move/050_D2_solved.out -> test/030_applymoves/050_D2_solved.out | 0
Rtest/030_move/060_D3_solved.in -> test/030_applymoves/060_D3_solved.in | 0
Rtest/030_move/060_D3_solved.out -> test/030_applymoves/060_D3_solved.out | 0
Rtest/030_move/070_R_solved.in -> test/030_applymoves/070_R_solved.in | 0
Rtest/030_move/070_R_solved.out -> test/030_applymoves/070_R_solved.out | 0
Rtest/030_move/071_R_scrambled.in -> test/030_applymoves/071_R_scrambled.in | 0
Rtest/030_move/071_R_scrambled.out -> test/030_applymoves/071_R_scrambled.out | 0
Rtest/030_move/080_R2_solved.in -> test/030_applymoves/080_R2_solved.in | 0
Rtest/030_move/080_R2_solved.out -> test/030_applymoves/080_R2_solved.out | 0
Rtest/030_move/090_R3_solved.in -> test/030_applymoves/090_R3_solved.in | 0
Rtest/030_move/090_R3_solved.out -> test/030_applymoves/090_R3_solved.out | 0
Rtest/030_move/100_L_solved.in -> test/030_applymoves/100_L_solved.in | 0
Rtest/030_move/100_L_solved.out -> test/030_applymoves/100_L_solved.out | 0
Rtest/030_move/110_L2_solved.in -> test/030_applymoves/110_L2_solved.in | 0
Rtest/030_move/110_L2_solved.out -> test/030_applymoves/110_L2_solved.out | 0
Rtest/030_move/120_L3_solved.in -> test/030_applymoves/120_L3_solved.in | 0
Rtest/030_move/120_L3_solved.out -> test/030_applymoves/120_L3_solved.out | 0
Rtest/030_move/130_F_solved.in -> test/030_applymoves/130_F_solved.in | 0
Rtest/030_move/130_F_solved.out -> test/030_applymoves/130_F_solved.out | 0
Rtest/030_move/132_F_scrambled.in -> test/030_applymoves/132_F_scrambled.in | 0
Rtest/030_move/132_F_scrambled.out -> test/030_applymoves/132_F_scrambled.out | 0
Rtest/030_move/133_F_scrambled_2.in -> test/030_applymoves/133_F_scrambled_2.in | 0
Rtest/030_move/133_F_scrambled_2.out -> test/030_applymoves/133_F_scrambled_2.out | 0
Rtest/030_move/140_F2_solved.in -> test/030_applymoves/140_F2_solved.in | 0
Rtest/030_move/140_F2_solved.out -> test/030_applymoves/140_F2_solved.out | 0
Rtest/030_move/150_F3_solved.in -> test/030_applymoves/150_F3_solved.in | 0
Rtest/030_move/150_F3_solved.out -> test/030_applymoves/150_F3_solved.out | 0
Rtest/030_move/160_B_solved.in -> test/030_applymoves/160_B_solved.in | 0
Rtest/030_move/160_B_solved.out -> test/030_applymoves/160_B_solved.out | 0
Rtest/030_move/170_B2_solved.in -> test/030_applymoves/170_B2_solved.in | 0
Rtest/030_move/170_B2_solved.out -> test/030_applymoves/170_B2_solved.out | 0
Rtest/030_move/180_B3_solved.in -> test/030_applymoves/180_B3_solved.in | 0
Rtest/030_move/180_B3_solved.out -> test/030_applymoves/180_B3_solved.out | 0
Rtest/030_move/200_scramble_solved.in -> test/030_applymoves/200_scramble_solved.in | 0
Rtest/030_move/200_scramble_solved.out -> test/030_applymoves/200_scramble_solved.out | 0
Rtest/030_move/201_solution_scrambled.in -> test/030_applymoves/201_solution_scrambled.in | 0
Rtest/030_move/201_solution_scrambled.out -> test/030_applymoves/201_solution_scrambled.out | 0
Rtest/030_move/300_multimove_solved.in -> test/030_applymoves/300_multimove_solved.in | 0
Rtest/030_move/300_multimove_solved.out -> test/030_applymoves/300_multimove_solved.out | 0
Rtest/030_move/301_multimove_scrambled.in -> test/030_applymoves/301_multimove_scrambled.in | 0
Rtest/030_move/301_multimove_scrambled.out -> test/030_applymoves/301_multimove_scrambled.out | 0
Rtest/030_move/500_Uw_solved.in -> test/030_applymoves/500_Uw_solved.in | 0
Rtest/030_move/500_Uw_solved.out -> test/030_applymoves/500_Uw_solved.out | 0
Rtest/030_move/501_Uw2_solved.in -> test/030_applymoves/501_Uw2_solved.in | 0
Rtest/030_move/501_Uw2_solved.out -> test/030_applymoves/501_Uw2_solved.out | 0
Rtest/030_move/502_Uw3_solved.in -> test/030_applymoves/502_Uw3_solved.in | 0
Rtest/030_move/502_Uw3_solved.out -> test/030_applymoves/502_Uw3_solved.out | 0
Rtest/030_move/503_Dw_solved.in -> test/030_applymoves/503_Dw_solved.in | 0
Rtest/030_move/503_Dw_solved.out -> test/030_applymoves/503_Dw_solved.out | 0
Rtest/030_move/504_Dw2_solved.in -> test/030_applymoves/504_Dw2_solved.in | 0
Rtest/030_move/504_Dw2_solved.out -> test/030_applymoves/504_Dw2_solved.out | 0
Rtest/030_move/505_Dw3_solved.in -> test/030_applymoves/505_Dw3_solved.in | 0
Rtest/030_move/505_Dw3_solved.out -> test/030_applymoves/505_Dw3_solved.out | 0
Rtest/030_move/506_Rw_solved.in -> test/030_applymoves/506_Rw_solved.in | 0
Rtest/030_move/506_Rw_solved.out -> test/030_applymoves/506_Rw_solved.out | 0
Rtest/030_move/507_Rw2_solved.in -> test/030_applymoves/507_Rw2_solved.in | 0
Rtest/030_move/507_Rw2_solved.out -> test/030_applymoves/507_Rw2_solved.out | 0
Rtest/030_move/508_Rw3_solved.in -> test/030_applymoves/508_Rw3_solved.in | 0
Rtest/030_move/508_Rw3_solved.out -> test/030_applymoves/508_Rw3_solved.out | 0
Rtest/030_move/509_Lw_solved.in -> test/030_applymoves/509_Lw_solved.in | 0
Rtest/030_move/509_Lw_solved.out -> test/030_applymoves/509_Lw_solved.out | 0
Rtest/030_move/510_Lw2_solved.in -> test/030_applymoves/510_Lw2_solved.in | 0
Rtest/030_move/510_Lw2_solved.out -> test/030_applymoves/510_Lw2_solved.out | 0
Rtest/030_move/511_Lw3_solved.in -> test/030_applymoves/511_Lw3_solved.in | 0
Rtest/030_move/511_Lw3_solved.out -> test/030_applymoves/511_Lw3_solved.out | 0
Rtest/030_move/512_Fw_solved.in -> test/030_applymoves/512_Fw_solved.in | 0
Rtest/030_move/512_Fw_solved.out -> test/030_applymoves/512_Fw_solved.out | 0
Rtest/030_move/513_Fw2_solved.in -> test/030_applymoves/513_Fw2_solved.in | 0
Rtest/030_move/513_Fw2_solved.out -> test/030_applymoves/513_Fw2_solved.out | 0
Rtest/030_move/514_Fw3_solved.in -> test/030_applymoves/514_Fw3_solved.in | 0
Rtest/030_move/514_Fw3_solved.out -> test/030_applymoves/514_Fw3_solved.out | 0
Rtest/030_move/515_Bw_solved.in -> test/030_applymoves/515_Bw_solved.in | 0
Rtest/030_move/515_Bw_solved.out -> test/030_applymoves/515_Bw_solved.out | 0
Rtest/030_move/516_Bw2_solved.in -> test/030_applymoves/516_Bw2_solved.in | 0
Rtest/030_move/516_Bw2_solved.out -> test/030_applymoves/516_Bw2_solved.out | 0
Rtest/030_move/517_Bw3_solved.in -> test/030_applymoves/517_Bw3_solved.in | 0
Rtest/030_move/517_Bw3_solved.out -> test/030_applymoves/517_Bw3_solved.out | 0
Rtest/030_move/518_M_solved.in -> test/030_applymoves/518_M_solved.in | 0
Rtest/030_move/518_M_solved.out -> test/030_applymoves/518_M_solved.out | 0
Rtest/030_move/519_M2_solved.in -> test/030_applymoves/519_M2_solved.in | 0
Rtest/030_move/519_M2_solved.out -> test/030_applymoves/519_M2_solved.out | 0
Rtest/030_move/520_M3_solved.in -> test/030_applymoves/520_M3_solved.in | 0
Rtest/030_move/520_M3_solved.out -> test/030_applymoves/520_M3_solved.out | 0
Rtest/030_move/521_S_solved.in -> test/030_applymoves/521_S_solved.in | 0
Rtest/030_move/521_S_solved.out -> test/030_applymoves/521_S_solved.out | 0
Rtest/030_move/522_S2_solved.in -> test/030_applymoves/522_S2_solved.in | 0
Rtest/030_move/522_S2_solved.out -> test/030_applymoves/522_S2_solved.out | 0
Rtest/030_move/523_S3_solved.in -> test/030_applymoves/523_S3_solved.in | 0
Rtest/030_move/523_S3_solved.out -> test/030_applymoves/523_S3_solved.out | 0
Rtest/030_move/524_E_solved.in -> test/030_applymoves/524_E_solved.in | 0
Rtest/030_move/524_E_solved.out -> test/030_applymoves/524_E_solved.out | 0
Rtest/030_move/525_E2_solved.in -> test/030_applymoves/525_E2_solved.in | 0
Rtest/030_move/525_E2_solved.out -> test/030_applymoves/525_E2_solved.out | 0
Rtest/030_move/526_E3_solved.in -> test/030_applymoves/526_E3_solved.in | 0
Rtest/030_move/526_E3_solved.out -> test/030_applymoves/526_E3_solved.out | 0
Rtest/030_move/527_x_solved.in -> test/030_applymoves/527_x_solved.in | 0
Rtest/030_move/527_x_solved.out -> test/030_applymoves/527_x_solved.out | 0
Rtest/030_move/528_x2_solved.in -> test/030_applymoves/528_x2_solved.in | 0
Rtest/030_move/528_x2_solved.out -> test/030_applymoves/528_x2_solved.out | 0
Rtest/030_move/529_x3_solved.in -> test/030_applymoves/529_x3_solved.in | 0
Rtest/030_move/529_x3_solved.out -> test/030_applymoves/529_x3_solved.out | 0
Rtest/030_move/530_y_solved.in -> test/030_applymoves/530_y_solved.in | 0
Rtest/030_move/530_y_solved.out -> test/030_applymoves/530_y_solved.out | 0
Rtest/030_move/531_y2_solved.in -> test/030_applymoves/531_y2_solved.in | 0
Rtest/030_move/531_y2_solved.out -> test/030_applymoves/531_y2_solved.out | 0
Rtest/030_move/532_y3_solved.in -> test/030_applymoves/532_y3_solved.in | 0
Rtest/030_move/532_y3_solved.out -> test/030_applymoves/532_y3_solved.out | 0
Rtest/030_move/533_z_solved.in -> test/030_applymoves/533_z_solved.in | 0
Rtest/030_move/533_z_solved.out -> test/030_applymoves/533_z_solved.out | 0
Rtest/030_move/534_z2_solved.in -> test/030_applymoves/534_z2_solved.in | 0
Rtest/030_move/534_z2_solved.out -> test/030_applymoves/534_z2_solved.out | 0
Rtest/030_move/535_z3_solved.in -> test/030_applymoves/535_z3_solved.in | 0
Rtest/030_move/535_z3_solved.out -> test/030_applymoves/535_z3_solved.out | 0
Rtest/030_move/550_scrambled_random.in -> test/030_applymoves/550_scrambled_random.in | 0
Rtest/030_move/550_scrambled_random.out -> test/030_applymoves/550_scrambled_random.out | 0
Rtest/030_move/559_solved_xzy.in -> test/030_applymoves/559_solved_xzy.in | 0
Rtest/030_move/559_solved_xzy.out -> test/030_applymoves/559_solved_xzy.out | 0
Rtest/030_move/560_solved_RwS.in -> test/030_applymoves/560_solved_RwS.in | 0
Rtest/030_move/560_solved_RwS.out -> test/030_applymoves/560_solved_RwS.out | 0
Rtest/030_move/561_solved_RwSE3.in -> test/030_applymoves/561_solved_RwSE3.in | 0
Rtest/030_move/561_solved_RwSE3.out -> test/030_applymoves/561_solved_RwSE3.out | 0
Rtest/030_move/569_returns_to_noreorient.in -> test/030_applymoves/569_returns_to_noreorient.in | 0
Rtest/030_move/569_returns_to_noreorient.out -> test/030_applymoves/569_returns_to_noreorient.out | 0
Atest/030_applymoves/600_niss_solved.in | 2++
Atest/030_applymoves/600_niss_solved.out | 1+
Atest/030_applymoves/601_niss_solved_widenormal.in | 2++
Atest/030_applymoves/601_niss_solved_widenormal.out | 1+
Atest/030_applymoves/602_scrambled_niss_1x3.in | 2++
Atest/030_applymoves/602_scrambled_niss_1x3.out | 1+
Atest/030_applymoves/603_scrambled_long_niss.in | 3+++
Atest/030_applymoves/603_scrambled_long_niss.out | 1+
Atest/030_applymoves/604_scrambled_niss_extendedmoves.in | 3+++
Atest/030_applymoves/604_scrambled_niss_extendedmoves.out | 1+
Rtest/030_move/move_tests.c -> test/030_applymoves/applymoves_tests.c | 0
Atest/032_countmoves/05_niss.in | 1+
Atest/032_countmoves/05_niss.out | 1+
Mtest/033_inverse_move/inverse_move_tests.c | 12+++++++++---
Atest/051_compose_oriented/00_scrambled_noorient.in | 4++++
Atest/051_compose_oriented/00_scrambled_noorient.out | 1+
Atest/051_compose_oriented/01_Uw_Fw.in | 2++
Atest/051_compose_oriented/01_Uw_Fw.out | 1+
Atest/051_compose_oriented/02_scrambled_scrambled.in | 4++++
Atest/051_compose_oriented/02_scrambled_scrambled.out | 1+
Atest/051_compose_oriented/compose_oriented_tests.c | 24++++++++++++++++++++++++
Mtest/062_transform_move/transform_move_tests.c | 12+++++++++---
Mtest/130_appendsolution/00_empty.in | 2+-
Mtest/130_appendsolution/01_simple_onlynormal_nounniss.in | 2+-
Mtest/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in | 2+-
Mtest/130_appendsolution/03_simple_unniss.in | 4++--
Mtest/130_appendsolution/04_niss_nounniss.in | 4++--
Mtest/130_appendsolution/05_sort_parallel.in | 2+-
Mtest/130_appendsolution/06_unniss_trans_sort.in | 4++--
Mtest/130_appendsolution/07_unniss_cancel_nosol.in | 4++--
Mtest/130_appendsolution/08_unniss_cancel_nosol_v2.in | 4++--
Mtest/130_appendsolution/09_fullinverse_niss.in | 4++--
Atest/130_appendsolution/10_rotated.in | 5+++++
Atest/130_appendsolution/10_rotated.out | 4++++
Mtest/130_appendsolution/appendsolution_tests.c | 21+++++++++++++++------
196 files changed, 301 insertions(+), 129 deletions(-)

diff --git a/src/core/constants.h b/src/core/constants.h @@ -348,22 +348,22 @@ #define NMOVES_EXTENDED (1+MOVE_z3) #define NTRANS (1+TRANS_BLm) -#define MM_ALLMOVES UINT32_C(0x3FFFF) -#define MM_NOHALFTURNS UINT32_C(0x2DB6D) -#define MM_SINGLE(m) (UINT32_C(1) << (uint32_t)(m)) -#define MM_FACE(m) (UINT32_C(7) << (uint32_t)(m)) -#define MM_EO (\ - MM_FACE(MOVE_U) | MM_FACE(MOVE_D) |\ - MM_FACE(MOVE_R) | MM_FACE(MOVE_L) |\ +#define MM_SINGLE(m) (UINT64_C(1) << (uint64_t)(m)) +#define MM18_ALLMOVES UINT64_C(0x3FFFF) +#define MM18_NOHALFTURNS UINT64_C(0x2DB6D) +#define MM18_FACE(m) (UINT64_C(7) << (uint64_t)(m)) +#define MM18_EO (\ + MM18_FACE(MOVE_U) | MM18_FACE(MOVE_D) |\ + MM18_FACE(MOVE_R) | MM18_FACE(MOVE_L) |\ MM_SINGLE(MOVE_F2) | MM_SINGLE(MOVE_B2)) -#define MM_DR (\ - MM_FACE(MOVE_U) | MM_FACE(MOVE_D) |\ +#define MM18_DR (\ + MM18_FACE(MOVE_U) | MM18_FACE(MOVE_D) |\ MM_SINGLE(MOVE_R2) | MM_SINGLE(MOVE_L2) |\ MM_SINGLE(MOVE_F2) | MM_SINGLE(MOVE_B2)) -#define MM_HTR (MM_ALLMOVES & ~MM_NOHALFTURNS) +#define MM18_HTR (MM18_ALLMOVES & ~MM18_NOHALFTURNS) -#define TM_ALLTRANS UINT64_C(0xFFFFFFFFFFFF) #define TM_SINGLE(t) (UINT64_C(1) << (uint64_t)(t)) +#define TM_ALLTRANS UINT64_C(0xFFFFFFFFFFFF) #define TM_UDRLFIX (\ TM_SINGLE(TRANS_UFr) | TM_SINGLE(TRANS_UBr) | TM_SINGLE(TRANS_UFm) | \ TM_SINGLE(TRANS_UBm) | TM_SINGLE(TRANS_DFr) | TM_SINGLE(TRANS_DBr) | \ @@ -423,13 +423,26 @@ #define ORIENTATION_BU UINT8_C(22) #define ORIENTATION_BL UINT8_C(23) -STATIC const uint32_t allowedmask[] = { - UINT32_C(0x3FFF8), - UINT32_C(0x3FFC0), - UINT32_C(0x3FE3F), - UINT32_C(0x3F03F), - UINT32_C(0x38FFF), - UINT32_C(0x00FFF) +/* This is only meant to work for the 18 base moves, for now */ +STATIC const uint64_t allowedmask[] = { + [MOVE_U / 3] = UINT64_C(0x3FFF8), + [MOVE_D / 3] = UINT64_C(0x3FFC0), + [MOVE_R / 3] = UINT64_C(0x3FE3F), + [MOVE_L / 3] = UINT64_C(0x3F03F), + [MOVE_F / 3] = UINT64_C(0x38FFF), + [MOVE_B / 3] = UINT64_C(0x00FFF), + [MOVE_Uw / 3] = 0, + [MOVE_Dw / 3] = 0, + [MOVE_Rw / 3] = 0, + [MOVE_Lw / 3] = 0, + [MOVE_Fw / 3] = 0, + [MOVE_Bw / 3] = 0, + [MOVE_M / 3] = 0, + [MOVE_S / 3] = 0, + [MOVE_E / 3] = 0, + [MOVE_x / 3] = 0, + [MOVE_y / 3] = 0, + [MOVE_z / 3] = 0, }; STATIC const char *cornerstr[] = { @@ -682,6 +695,33 @@ STATIC uint8_t trans_move_table[][3] = { [TRANS_BLm] = { MOVE_B, MOVE_U, MOVE_R }, }; +STATIC uint8_t orientation_moves[][3] = { + [ORIENTATION_UF] = { UINT8_MAX }, + [ORIENTATION_UR] = { MOVE_y, UINT8_MAX }, + [ORIENTATION_UB] = { MOVE_y2, UINT8_MAX }, + [ORIENTATION_UL] = { MOVE_y3, UINT8_MAX }, + [ORIENTATION_DF] = { MOVE_z2, UINT8_MAX }, + [ORIENTATION_DR] = { MOVE_y, MOVE_z2, UINT8_MAX }, + [ORIENTATION_DB] = { MOVE_y2, MOVE_z2, UINT8_MAX }, + [ORIENTATION_DL] = { MOVE_y3, MOVE_z2, UINT8_MAX }, + [ORIENTATION_RF] = { MOVE_z3, UINT8_MAX }, + [ORIENTATION_RD] = { MOVE_z3, MOVE_y, UINT8_MAX }, + [ORIENTATION_RB] = { MOVE_z3, MOVE_y2, UINT8_MAX }, + [ORIENTATION_RU] = { MOVE_z3, MOVE_y3, UINT8_MAX }, + [ORIENTATION_LF] = { MOVE_z, UINT8_MAX }, + [ORIENTATION_LD] = { MOVE_z, MOVE_y3, UINT8_MAX }, + [ORIENTATION_LB] = { MOVE_z, MOVE_y2, UINT8_MAX }, + [ORIENTATION_LU] = { MOVE_z, MOVE_y, UINT8_MAX }, + [ORIENTATION_FD] = { MOVE_x, UINT8_MAX }, + [ORIENTATION_FR] = { MOVE_x, MOVE_y, UINT8_MAX }, + [ORIENTATION_FU] = { MOVE_x, MOVE_y2, UINT8_MAX }, + [ORIENTATION_FL] = { MOVE_x, MOVE_y3, UINT8_MAX }, + [ORIENTATION_BD] = { MOVE_x3, MOVE_y2, UINT8_MAX }, + [ORIENTATION_BR] = { MOVE_x3, MOVE_y, UINT8_MAX }, + [ORIENTATION_BU] = { MOVE_x3, UINT8_MAX }, + [ORIENTATION_BL] = { MOVE_x3, MOVE_y3, UINT8_MAX }, +}; + STATIC uint8_t orientation_transition_table[][3] = { [ORIENTATION_UF] = { ORIENTATION_FD, ORIENTATION_UR, ORIENTATION_LF }, [ORIENTATION_UR] = { ORIENTATION_RD, ORIENTATION_UB, ORIENTATION_FR }, diff --git a/src/core/core.h b/src/core/core.h @@ -3,3 +3,4 @@ #include "cube.h" #include "moves.h" #include "transform.h" +#include "oriented_cube.h" diff --git a/src/core/cube.h b/src/core/cube.h @@ -1,4 +1,3 @@ -STATIC oriented_cube_t solvedcube(void); STATIC cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); STATIC bool isconsistent(oriented_cube_t); STATIC bool issolvable(oriented_cube_t); @@ -20,13 +19,6 @@ STATIC uint8_t b32tocorner(char); STATIC char edgetob32(uint8_t); STATIC char cornertob32(uint8_t); -/* This is used only in tests, use SOLVED_ORIENTED_CUBE everywhere else */ -STATIC oriented_cube_t -solvedcube(void) -{ - return SOLVED_ORIENTED_CUBE; -} - STATIC cube_t cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) { diff --git a/src/core/moves.h b/src/core/moves.h @@ -2,7 +2,8 @@ #define PREMOVE(M, c) compose(MOVE_CUBE_ ## M, c) STATIC uint8_t readmove(char); -STATIC int64_t readmoves(const char *, size_t n, uint8_t [n]); +STATIC int64_t readmoves(const char *, + size_t n, size_t m, uint64_t *, uint64_t *, uint8_t [n], uint8_t [m]); STATIC int64_t countmoves(const char *); STATIC uint8_t readmodifier(char); STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); @@ -21,14 +22,11 @@ STATIC_INLINE uint8_t movefollow(uint8_t); STATIC uint8_t transform_move(uint8_t, uint8_t); STATIC cube_t move(cube_t, uint8_t); -STATIC oriented_cube_t move_extended(oriented_cube_t, uint8_t); STATIC cube_t premove(cube_t, uint8_t); STATIC uint8_t inverse_move(uint8_t); STATIC void sortparallel_moves(size_t n, uint8_t [n]); STATIC bool are_lastmoves_singlecw(size_t n, const uint8_t [n]); -STATIC oriented_cube_t applymoves(oriented_cube_t, const char *); - #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ RET_ERROR, ARG_ACTION) \ const char *VAR_B; \ @@ -118,14 +116,34 @@ readmodifier(char c) } STATIC int64_t -readmoves(const char *buf, size_t n, uint8_t ret[n]) +readmoves( + const char *buf, + size_t nsize, + size_t invsize, + uint64_t *n, + uint64_t *i, + uint8_t normal[nsize], + uint8_t inverse[invsize] +) { -// TODO: modify to accept NISS uint8_t m; uint64_t c; - FOREACH_READMOVE(buf, m, c, n, NISSY_ERROR_INVALID_MOVES, - ret[c] = m; + *n = *i = 0; + FOREACH_READMOVE(buf, m, c, nsize+invsize, NISSY_ERROR_INVALID_MOVES, + if (!VAR_IN_PARENTHESES) { + if (*n >= nsize-1) { + LOG("Error in readmoves: normal buffer\n"); + return NISSY_ERROR_BUFFER_SIZE; + } + normal[(*n)++] = m; + } else { + if (*i >= invsize-1) { + LOG("Error in readmoves: inverse buffer\n"); + return NISSY_ERROR_BUFFER_SIZE; + } + inverse[(*i)++] = m; + } ) return (int64_t)c; @@ -188,9 +206,7 @@ writemoves_error: STATIC_INLINE bool allowednextmove(uint8_t m1, uint8_t m2) { -// TODO: adjust allowedmask -// TODO: movemask is now 64 bits - return allowedmask[movebase(m1)] & (UINT32_C(1) << m2); + return allowedmask[movebase(m1)] & MM_SINGLE(m2); } STATIC bool @@ -226,9 +242,7 @@ isbase(uint8_t move) STATIC_INLINE bool parallel(uint8_t m1, uint8_t m2) { -// TODO add unit tests -//TODO fix the logic (maybe use moveaxis(movefollow)), then remove comment - return moveaxis(m1) == moveaxis(m2); + return moveaxis(movefollow(m1)) == moveaxis(movefollow(m2)); } STATIC_INLINE uint8_t @@ -249,7 +263,6 @@ inverse_reorient_move(uint8_t m, uint8_t or) return transform_move(m, inverse_trans_table[orientation_trans[or]]); } -/* This is currently unused, but it may turn out to be useful at some point */ STATIC_INLINE uint8_t movefollow(uint8_t move) { @@ -351,27 +364,6 @@ transform_move(uint8_t m, uint8_t t) return base + modifier; } -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; -} - /* Applies the INVERSE of m BEFORE the scramble corresponding to c */ STATIC cube_t premove(cube_t c, uint8_t m) @@ -428,15 +420,13 @@ inverse_move(uint8_t m) STATIC void sortparallel_moves(size_t n, uint8_t moves[n]) { -// TODO: fix for wide moves... uint8_t i; if (n < 2) return; for (i = 0; i < n-1; i++) - if (moveaxis(moves[i]) == moveaxis(moves[i+1]) && - movebase(moves[i]) == movebase(moves[i+1]) + 1) + if (parallel(moves[i], moves[i+1]) && moves[i] > moves[i+1]) SWAP(moves[i], moves[i+1]); } @@ -452,19 +442,3 @@ are_lastmoves_singlecw(size_t n, const uint8_t moves[n]) return isbase(moves[n-1]) && (!two || isbase(moves[n-2])); } - -STATIC oriented_cube_t -applymoves(oriented_cube_t cube, const char *buf) -{ - int c; - uint8_t m; - - DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE, - "move error: inconsistent cube\n"); - - FOREACH_READMOVE(buf, m, c, -1, ZERO_ORIENTED_CUBE, - cube = move_extended(cube, m); - ) - - return cube; -} diff --git a/src/core/oriented_cube.h 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); +} diff --git a/src/nissy.h b/src/nissy.h @@ -11,6 +11,8 @@ see the README.md file for more information. Accepted moves are any of the following: U, D, R, L, F, B, Uw, Dw, Rw, Lw, Fw, Bw, M, S, E, x, y, z optionally followed by a 2, a ' or a 3. +The standard NISS notation is also accepted: moves in parentheses () are +inverted and used as premoves. A transformation must be given in the format (rotation|mirrored) (2 letters) diff --git a/src/solvers/coord/dr.h b/src/solvers/coord/dr.h @@ -24,7 +24,7 @@ STATIC coord_t coordinate_dr = { .gendata = coordinate_dr_gendata, .max = DREOESEP_CLASSES * POW_3_7, .trans_mask = TM_UDFIX, - .moves_mask = MM_ALLMOVES, + .moves_mask = MM18_ALLMOVES, .axistrans = { [AXIS_UD] = TRANS_UFr, [AXIS_RL] = TRANS_RFr, diff --git a/src/solvers/coord/dreo.h b/src/solvers/coord/dreo.h @@ -19,7 +19,7 @@ STATIC coord_t coordinate_dreo = { .gendata = coordinate_dreo_gendata, .max = DRESEP_CLASSES * POW_3_7, .trans_mask = TM_UDRLFIX, - .moves_mask = MM_EO, + .moves_mask = MM18_EO, .axistrans = { [AXIS_UD] = TRANS_UFr, [AXIS_RL] = TRANS_RFr, diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h @@ -12,7 +12,7 @@ STATIC coord_t coordinate_eo = { .gendata = coordinate_eo_gendata, .max = POW_2_11, .trans_mask = TM_SINGLE(TRANS_UFr), - .moves_mask = MM_ALLMOVES, + .moves_mask = MM18_ALLMOVES, .axistrans = { [AXIS_UD] = TRANS_FDr, [AXIS_RL] = TRANS_URr, diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h @@ -21,7 +21,7 @@ typedef struct { bool (*isnasty)(uint64_t, const unsigned char *); size_t (*gendata)(unsigned char *); uint64_t max; - uint32_t moves_mask; + uint64_t moves_mask; uint64_t trans_mask; uint8_t axistrans[3]; bool (*is_admissible)(const solution_moves_t[static 1]); diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -25,8 +25,8 @@ typedef struct { const unsigned char *h48data; const unsigned char *h48data_fallback_h0k4; const unsigned char *h48data_fallback_eoesep; - uint32_t movemask_normal; - uint32_t movemask_inverse; + uint64_t movemask_normal; + uint64_t movemask_inverse; int64_t nodes_visited; int64_t table_fallbacks; int64_t table_lookups; @@ -72,7 +72,7 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) arg->solution_settings->optimal) return true; - arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES; + arg->movemask_normal = arg->movemask_inverse = MM18_ALLMOVES; arg->nodes_visited++; /* Preliminary probing using last computed bound, if possible */ @@ -113,7 +113,7 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) if (arg->lb_inverse > target) return true; nh = arg->lb_inverse == target; - arg->movemask_normal = nh * MM_NOHALFTURNS + (1-nh) * MM_ALLMOVES; + arg->movemask_normal = nh * MM18_NOHALFTURNS + (1-nh) * MM18_ALLMOVES; /* Normal probing */ @@ -141,7 +141,7 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) if (arg->lb_normal > target) return true; nh = arg->lb_normal == target; - arg->movemask_inverse = nh * MM_NOHALFTURNS + (1-nh) * MM_ALLMOVES; + arg->movemask_inverse = nh * MM18_NOHALFTURNS + (1-nh) * MM18_ALLMOVES; return false; } @@ -151,7 +151,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) { int64_t ret, n; uint8_t m, nm, lbn, lbi; - uint32_t mm_normal, mm_inverse; + uint64_t mm_normal, mm_inverse; bool ulbi, ulbn; cube_t backup_cube, backup_inverse; @@ -191,7 +191,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) if (popcount_u32(mm_normal) <= popcount_u32(mm_inverse)) { arg->solution_moves->nmoves++; for (m = 0; m < 18; m++) { - if (!(mm_normal & (UINT32_C(1) << (uint32_t)m))) + if (!(mm_normal & MM_SINGLE(m))) continue; arg->solution_moves->moves[ arg->solution_moves->nmoves-1] = m; @@ -209,7 +209,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) } else { arg->solution_moves->npremoves++; for (m = 0; m < 18; m++) { - if(!(mm_inverse & (UINT32_C(1) << (uint32_t)m))) + if(!(mm_inverse & MM_SINGLE(m))) continue; arg->solution_moves->premoves[ arg->solution_moves->npremoves-1] = m; @@ -258,8 +258,8 @@ solve_h48_runthread(void *arg) dfsarg->lb_inverse = 0; dfsarg->use_lb_normal = false; dfsarg->use_lb_inverse = false; - dfsarg->movemask_normal = MM_ALLMOVES; - dfsarg->movemask_inverse = MM_ALLMOVES; + dfsarg->movemask_normal = MM18_ALLMOVES; + dfsarg->movemask_inverse = MM18_ALLMOVES; solve_h48_dfs(dfsarg); } @@ -278,7 +278,7 @@ solve_h48_maketasks( int r; int64_t appret; uint8_t m, t; - uint32_t mm; + uint64_t mm; cube_t backup_cube; solution_moves_t moves; @@ -308,7 +308,7 @@ solve_h48_maketasks( } if (maketasks_arg->nmoves == 0) { - mm = MM_ALLMOVES; + mm = MM18_ALLMOVES; } else { m = maketasks_arg->moves[maketasks_arg->nmoves-1]; mm = allowedmask[movebase(m)]; @@ -317,7 +317,7 @@ solve_h48_maketasks( maketasks_arg->nmoves++; backup_cube = maketasks_arg->cube; for (m = 0; m < 18; m++) { - if (!(mm & (1 << m))) + if (!(mm & MM_SINGLE(m))) continue; maketasks_arg->moves[maketasks_arg->nmoves-1] = m; maketasks_arg->cube = move(backup_cube, m); @@ -330,9 +330,8 @@ solve_h48_maketasks( if (maketasks_arg->nmoves == 1) for (t = 0; t < NTRANS; t++) if (solve_arg->solution_settings->tmask & - (UINT64_C(1) << (uint64_t)t)) - mm &= ~(UINT32_C(1) << - (uint32_t)transform_move(m, t)); + TM_SINGLE(t)) + mm &= ~MM_SINGLE(transform_move(m, t)); } maketasks_arg->nmoves--; maketasks_arg->cube = backup_cube; diff --git a/test/030_move/000_nomove_solved.in b/test/030_applymoves/000_nomove_solved.in diff --git a/test/030_move/000_nomove_solved.out b/test/030_applymoves/000_nomove_solved.out diff --git a/test/030_move/001_nomove_scrambled.in b/test/030_applymoves/001_nomove_scrambled.in diff --git a/test/030_move/001_nomove_scrambled.out b/test/030_applymoves/001_nomove_scrambled.out diff --git a/test/030_move/010_U_solved.in b/test/030_applymoves/010_U_solved.in diff --git a/test/030_move/010_U_solved.out b/test/030_applymoves/010_U_solved.out diff --git a/test/030_move/011_U_scrambled.in b/test/030_applymoves/011_U_scrambled.in diff --git a/test/030_move/011_U_scrambled.out b/test/030_applymoves/011_U_scrambled.out diff --git a/test/030_move/012_U_inverse.in b/test/030_applymoves/012_U_inverse.in diff --git a/test/030_move/012_U_inverse.out b/test/030_applymoves/012_U_inverse.out diff --git a/test/030_move/020_U2_solved.in b/test/030_applymoves/020_U2_solved.in diff --git a/test/030_move/020_U2_solved.out b/test/030_applymoves/020_U2_solved.out diff --git a/test/030_move/021_U2_scrambled.in b/test/030_applymoves/021_U2_scrambled.in diff --git a/test/030_move/021_U2_scrambled.out b/test/030_applymoves/021_U2_scrambled.out diff --git a/test/030_move/022_U2_inverse.in b/test/030_applymoves/022_U2_inverse.in diff --git a/test/030_move/022_U2_inverse.out b/test/030_applymoves/022_U2_inverse.out diff --git a/test/030_move/030_U3_solved.in b/test/030_applymoves/030_U3_solved.in diff --git a/test/030_move/030_U3_solved.out b/test/030_applymoves/030_U3_solved.out diff --git a/test/030_move/031_U3_inverse.in b/test/030_applymoves/031_U3_inverse.in diff --git a/test/030_move/031_U3_inverse.out b/test/030_applymoves/031_U3_inverse.out diff --git a/test/030_move/032_U3_scrambled.in b/test/030_applymoves/032_U3_scrambled.in diff --git a/test/030_move/032_U3_scrambled.out b/test/030_applymoves/032_U3_scrambled.out diff --git a/test/030_move/033_U3_with_prime.in b/test/030_applymoves/033_U3_with_prime.in diff --git a/test/030_move/033_U3_with_prime.out b/test/030_applymoves/033_U3_with_prime.out diff --git a/test/030_move/040_D_solved.in b/test/030_applymoves/040_D_solved.in diff --git a/test/030_move/040_D_solved.out b/test/030_applymoves/040_D_solved.out diff --git a/test/030_move/050_D2_solved.in b/test/030_applymoves/050_D2_solved.in diff --git a/test/030_move/050_D2_solved.out b/test/030_applymoves/050_D2_solved.out diff --git a/test/030_move/060_D3_solved.in b/test/030_applymoves/060_D3_solved.in diff --git a/test/030_move/060_D3_solved.out b/test/030_applymoves/060_D3_solved.out diff --git a/test/030_move/070_R_solved.in b/test/030_applymoves/070_R_solved.in diff --git a/test/030_move/070_R_solved.out b/test/030_applymoves/070_R_solved.out diff --git a/test/030_move/071_R_scrambled.in b/test/030_applymoves/071_R_scrambled.in diff --git a/test/030_move/071_R_scrambled.out b/test/030_applymoves/071_R_scrambled.out diff --git a/test/030_move/080_R2_solved.in b/test/030_applymoves/080_R2_solved.in diff --git a/test/030_move/080_R2_solved.out b/test/030_applymoves/080_R2_solved.out diff --git a/test/030_move/090_R3_solved.in b/test/030_applymoves/090_R3_solved.in diff --git a/test/030_move/090_R3_solved.out b/test/030_applymoves/090_R3_solved.out diff --git a/test/030_move/100_L_solved.in b/test/030_applymoves/100_L_solved.in diff --git a/test/030_move/100_L_solved.out b/test/030_applymoves/100_L_solved.out diff --git a/test/030_move/110_L2_solved.in b/test/030_applymoves/110_L2_solved.in diff --git a/test/030_move/110_L2_solved.out b/test/030_applymoves/110_L2_solved.out diff --git a/test/030_move/120_L3_solved.in b/test/030_applymoves/120_L3_solved.in diff --git a/test/030_move/120_L3_solved.out b/test/030_applymoves/120_L3_solved.out diff --git a/test/030_move/130_F_solved.in b/test/030_applymoves/130_F_solved.in diff --git a/test/030_move/130_F_solved.out b/test/030_applymoves/130_F_solved.out diff --git a/test/030_move/132_F_scrambled.in b/test/030_applymoves/132_F_scrambled.in diff --git a/test/030_move/132_F_scrambled.out b/test/030_applymoves/132_F_scrambled.out diff --git a/test/030_move/133_F_scrambled_2.in b/test/030_applymoves/133_F_scrambled_2.in diff --git a/test/030_move/133_F_scrambled_2.out b/test/030_applymoves/133_F_scrambled_2.out diff --git a/test/030_move/140_F2_solved.in b/test/030_applymoves/140_F2_solved.in diff --git a/test/030_move/140_F2_solved.out b/test/030_applymoves/140_F2_solved.out diff --git a/test/030_move/150_F3_solved.in b/test/030_applymoves/150_F3_solved.in diff --git a/test/030_move/150_F3_solved.out b/test/030_applymoves/150_F3_solved.out diff --git a/test/030_move/160_B_solved.in b/test/030_applymoves/160_B_solved.in diff --git a/test/030_move/160_B_solved.out b/test/030_applymoves/160_B_solved.out diff --git a/test/030_move/170_B2_solved.in b/test/030_applymoves/170_B2_solved.in diff --git a/test/030_move/170_B2_solved.out b/test/030_applymoves/170_B2_solved.out diff --git a/test/030_move/180_B3_solved.in b/test/030_applymoves/180_B3_solved.in diff --git a/test/030_move/180_B3_solved.out b/test/030_applymoves/180_B3_solved.out diff --git a/test/030_move/200_scramble_solved.in b/test/030_applymoves/200_scramble_solved.in diff --git a/test/030_move/200_scramble_solved.out b/test/030_applymoves/200_scramble_solved.out diff --git a/test/030_move/201_solution_scrambled.in b/test/030_applymoves/201_solution_scrambled.in diff --git a/test/030_move/201_solution_scrambled.out b/test/030_applymoves/201_solution_scrambled.out diff --git a/test/030_move/300_multimove_solved.in b/test/030_applymoves/300_multimove_solved.in diff --git a/test/030_move/300_multimove_solved.out b/test/030_applymoves/300_multimove_solved.out diff --git a/test/030_move/301_multimove_scrambled.in b/test/030_applymoves/301_multimove_scrambled.in diff --git a/test/030_move/301_multimove_scrambled.out b/test/030_applymoves/301_multimove_scrambled.out diff --git a/test/030_move/500_Uw_solved.in b/test/030_applymoves/500_Uw_solved.in diff --git a/test/030_move/500_Uw_solved.out b/test/030_applymoves/500_Uw_solved.out diff --git a/test/030_move/501_Uw2_solved.in b/test/030_applymoves/501_Uw2_solved.in diff --git a/test/030_move/501_Uw2_solved.out b/test/030_applymoves/501_Uw2_solved.out diff --git a/test/030_move/502_Uw3_solved.in b/test/030_applymoves/502_Uw3_solved.in diff --git a/test/030_move/502_Uw3_solved.out b/test/030_applymoves/502_Uw3_solved.out diff --git a/test/030_move/503_Dw_solved.in b/test/030_applymoves/503_Dw_solved.in diff --git a/test/030_move/503_Dw_solved.out b/test/030_applymoves/503_Dw_solved.out diff --git a/test/030_move/504_Dw2_solved.in b/test/030_applymoves/504_Dw2_solved.in diff --git a/test/030_move/504_Dw2_solved.out b/test/030_applymoves/504_Dw2_solved.out diff --git a/test/030_move/505_Dw3_solved.in b/test/030_applymoves/505_Dw3_solved.in diff --git a/test/030_move/505_Dw3_solved.out b/test/030_applymoves/505_Dw3_solved.out diff --git a/test/030_move/506_Rw_solved.in b/test/030_applymoves/506_Rw_solved.in diff --git a/test/030_move/506_Rw_solved.out b/test/030_applymoves/506_Rw_solved.out diff --git a/test/030_move/507_Rw2_solved.in b/test/030_applymoves/507_Rw2_solved.in diff --git a/test/030_move/507_Rw2_solved.out b/test/030_applymoves/507_Rw2_solved.out diff --git a/test/030_move/508_Rw3_solved.in b/test/030_applymoves/508_Rw3_solved.in diff --git a/test/030_move/508_Rw3_solved.out b/test/030_applymoves/508_Rw3_solved.out diff --git a/test/030_move/509_Lw_solved.in b/test/030_applymoves/509_Lw_solved.in diff --git a/test/030_move/509_Lw_solved.out b/test/030_applymoves/509_Lw_solved.out diff --git a/test/030_move/510_Lw2_solved.in b/test/030_applymoves/510_Lw2_solved.in diff --git a/test/030_move/510_Lw2_solved.out b/test/030_applymoves/510_Lw2_solved.out diff --git a/test/030_move/511_Lw3_solved.in b/test/030_applymoves/511_Lw3_solved.in diff --git a/test/030_move/511_Lw3_solved.out b/test/030_applymoves/511_Lw3_solved.out diff --git a/test/030_move/512_Fw_solved.in b/test/030_applymoves/512_Fw_solved.in diff --git a/test/030_move/512_Fw_solved.out b/test/030_applymoves/512_Fw_solved.out diff --git a/test/030_move/513_Fw2_solved.in b/test/030_applymoves/513_Fw2_solved.in diff --git a/test/030_move/513_Fw2_solved.out b/test/030_applymoves/513_Fw2_solved.out diff --git a/test/030_move/514_Fw3_solved.in b/test/030_applymoves/514_Fw3_solved.in diff --git a/test/030_move/514_Fw3_solved.out b/test/030_applymoves/514_Fw3_solved.out diff --git a/test/030_move/515_Bw_solved.in b/test/030_applymoves/515_Bw_solved.in diff --git a/test/030_move/515_Bw_solved.out b/test/030_applymoves/515_Bw_solved.out diff --git a/test/030_move/516_Bw2_solved.in b/test/030_applymoves/516_Bw2_solved.in diff --git a/test/030_move/516_Bw2_solved.out b/test/030_applymoves/516_Bw2_solved.out diff --git a/test/030_move/517_Bw3_solved.in b/test/030_applymoves/517_Bw3_solved.in diff --git a/test/030_move/517_Bw3_solved.out b/test/030_applymoves/517_Bw3_solved.out diff --git a/test/030_move/518_M_solved.in b/test/030_applymoves/518_M_solved.in diff --git a/test/030_move/518_M_solved.out b/test/030_applymoves/518_M_solved.out diff --git a/test/030_move/519_M2_solved.in b/test/030_applymoves/519_M2_solved.in diff --git a/test/030_move/519_M2_solved.out b/test/030_applymoves/519_M2_solved.out diff --git a/test/030_move/520_M3_solved.in b/test/030_applymoves/520_M3_solved.in diff --git a/test/030_move/520_M3_solved.out b/test/030_applymoves/520_M3_solved.out diff --git a/test/030_move/521_S_solved.in b/test/030_applymoves/521_S_solved.in diff --git a/test/030_move/521_S_solved.out b/test/030_applymoves/521_S_solved.out diff --git a/test/030_move/522_S2_solved.in b/test/030_applymoves/522_S2_solved.in diff --git a/test/030_move/522_S2_solved.out b/test/030_applymoves/522_S2_solved.out diff --git a/test/030_move/523_S3_solved.in b/test/030_applymoves/523_S3_solved.in diff --git a/test/030_move/523_S3_solved.out b/test/030_applymoves/523_S3_solved.out diff --git a/test/030_move/524_E_solved.in b/test/030_applymoves/524_E_solved.in diff --git a/test/030_move/524_E_solved.out b/test/030_applymoves/524_E_solved.out diff --git a/test/030_move/525_E2_solved.in b/test/030_applymoves/525_E2_solved.in diff --git a/test/030_move/525_E2_solved.out b/test/030_applymoves/525_E2_solved.out diff --git a/test/030_move/526_E3_solved.in b/test/030_applymoves/526_E3_solved.in diff --git a/test/030_move/526_E3_solved.out b/test/030_applymoves/526_E3_solved.out diff --git a/test/030_move/527_x_solved.in b/test/030_applymoves/527_x_solved.in diff --git a/test/030_move/527_x_solved.out b/test/030_applymoves/527_x_solved.out diff --git a/test/030_move/528_x2_solved.in b/test/030_applymoves/528_x2_solved.in diff --git a/test/030_move/528_x2_solved.out b/test/030_applymoves/528_x2_solved.out diff --git a/test/030_move/529_x3_solved.in b/test/030_applymoves/529_x3_solved.in diff --git a/test/030_move/529_x3_solved.out b/test/030_applymoves/529_x3_solved.out diff --git a/test/030_move/530_y_solved.in b/test/030_applymoves/530_y_solved.in diff --git a/test/030_move/530_y_solved.out b/test/030_applymoves/530_y_solved.out diff --git a/test/030_move/531_y2_solved.in b/test/030_applymoves/531_y2_solved.in diff --git a/test/030_move/531_y2_solved.out b/test/030_applymoves/531_y2_solved.out diff --git a/test/030_move/532_y3_solved.in b/test/030_applymoves/532_y3_solved.in diff --git a/test/030_move/532_y3_solved.out b/test/030_applymoves/532_y3_solved.out diff --git a/test/030_move/533_z_solved.in b/test/030_applymoves/533_z_solved.in diff --git a/test/030_move/533_z_solved.out b/test/030_applymoves/533_z_solved.out diff --git a/test/030_move/534_z2_solved.in b/test/030_applymoves/534_z2_solved.in diff --git a/test/030_move/534_z2_solved.out b/test/030_applymoves/534_z2_solved.out diff --git a/test/030_move/535_z3_solved.in b/test/030_applymoves/535_z3_solved.in diff --git a/test/030_move/535_z3_solved.out b/test/030_applymoves/535_z3_solved.out diff --git a/test/030_move/550_scrambled_random.in b/test/030_applymoves/550_scrambled_random.in diff --git a/test/030_move/550_scrambled_random.out b/test/030_applymoves/550_scrambled_random.out diff --git a/test/030_move/559_solved_xzy.in b/test/030_applymoves/559_solved_xzy.in diff --git a/test/030_move/559_solved_xzy.out b/test/030_applymoves/559_solved_xzy.out diff --git a/test/030_move/560_solved_RwS.in b/test/030_applymoves/560_solved_RwS.in diff --git a/test/030_move/560_solved_RwS.out b/test/030_applymoves/560_solved_RwS.out diff --git a/test/030_move/561_solved_RwSE3.in b/test/030_applymoves/561_solved_RwSE3.in diff --git a/test/030_move/561_solved_RwSE3.out b/test/030_applymoves/561_solved_RwSE3.out diff --git a/test/030_move/569_returns_to_noreorient.in b/test/030_applymoves/569_returns_to_noreorient.in diff --git a/test/030_move/569_returns_to_noreorient.out b/test/030_applymoves/569_returns_to_noreorient.out diff --git a/test/030_applymoves/600_niss_solved.in b/test/030_applymoves/600_niss_solved.in @@ -0,0 +1,2 @@ +R U R (F L F) +ABCDEFGH=ABCDEFGHIJKL=A diff --git a/test/030_applymoves/600_niss_solved.out b/test/030_applymoves/600_niss_solved.out @@ -0,0 +1 @@ +DGEAHSFJ=JQCWHDKELIFB=A diff --git a/test/030_applymoves/601_niss_solved_widenormal.in b/test/030_applymoves/601_niss_solved_widenormal.in @@ -0,0 +1,2 @@ +Rw Uw' (F L F) +ABCDEFGH=ABCDEFGHIJKL=A diff --git a/test/030_applymoves/601_niss_solved_widenormal.out b/test/030_applymoves/601_niss_solved_widenormal.out @@ -0,0 +1 @@ +CUWNQRPT=DabWEFIHJQSR=T diff --git a/test/030_applymoves/602_scrambled_niss_1x3.in b/test/030_applymoves/602_scrambled_niss_1x3.in @@ -0,0 +1,2 @@ +R (F) +FECDABGH=EFCDBAGHIJKL=A diff --git a/test/030_applymoves/602_scrambled_niss_1x3.out b/test/030_applymoves/602_scrambled_niss_1x3.out @@ -0,0 +1 @@ +KQMRONLH=EFCZTYGLHQKB=A diff --git a/test/030_applymoves/603_scrambled_long_niss.in b/test/030_applymoves/603_scrambled_long_niss.in @@ -0,0 +1,3 @@ +R U R (B D2 F') +LFWBCAEH=QSabHBIFJWDU=A +// scrambled cube: "R U R F D B2 L F D' B3" diff --git a/test/030_applymoves/603_scrambled_long_niss.out b/test/030_applymoves/603_scrambled_long_niss.out @@ -0,0 +1 @@ +ADXJKNMG=TaYBFJQGUXCL=A diff --git a/test/030_applymoves/604_scrambled_niss_extendedmoves.in b/test/030_applymoves/604_scrambled_niss_extendedmoves.in @@ -0,0 +1,3 @@ +M y2 F E (Bw D2 Fw' z2) +LFWBCAEH=QSabHBIFJWDU=A +// scrambled cube: "R U R F D B2 L F D' B3" diff --git a/test/030_applymoves/604_scrambled_niss_extendedmoves.out b/test/030_applymoves/604_scrambled_niss_extendedmoves.out @@ -0,0 +1 @@ +EPNOACTJ=WXLDQVZCRYaE=V diff --git a/test/030_move/move_tests.c b/test/030_applymoves/applymoves_tests.c diff --git a/test/032_countmoves/05_niss.in b/test/032_countmoves/05_niss.in @@ -0,0 +1 @@ +R2 M Uw (Fw2 M2 y2) diff --git a/test/032_countmoves/05_niss.out b/test/032_countmoves/05_niss.out @@ -0,0 +1 @@ +7 diff --git a/test/033_inverse_move/inverse_move_tests.c b/test/033_inverse_move/inverse_move_tests.c @@ -2,19 +2,25 @@ extern char *movestr[]; -int64_t readmoves(const char *, size_t n, uint8_t [n]); +int64_t readmoves(const char *, size_t n, size_t m, + uint64_t *, uint64_t *, uint8_t [n], uint8_t [m]); uint8_t inverse_move(uint8_t); void run(void) { + uint64_t inv, nor; + int64_t tot; uint8_t moves[2]; char moves_string[STRLENMAX]; fgets(moves_string, STRLENMAX, stdin); - if (readmoves(moves_string, 2, moves) != 1) { - printf("Test error: cannot read moves\n"); + tot = readmoves(moves_string, 2, 0, &nor, &inv, moves, NULL); + if (nor != 1 || tot != 1) { + printf("Test error reading moves\n"); return; } +fprintf(stderr, "Read move %" PRIu8 " = %s\n", moves[0], movestr[moves[0]]); + printf("%s\n", movestr[inverse_move(moves[0])]); } diff --git a/test/051_compose_oriented/00_scrambled_noorient.in b/test/051_compose_oriented/00_scrambled_noorient.in @@ -0,0 +1,4 @@ +CILVXGMR=FKbGIDSXBJAU=A +JLQWSVUH=ZLCUABGIVTKH=A +// Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' +// Followed by R' U' F diff --git a/test/051_compose_oriented/00_scrambled_noorient.out b/test/051_compose_oriented/00_scrambled_noorient.out @@ -0,0 +1 @@ +QFSEDWPR=ZUbYFKSBTWAX=A diff --git a/test/051_compose_oriented/01_Uw_Fw.in b/test/051_compose_oriented/01_Uw_Fw.in @@ -0,0 +1,2 @@ +ABHGEFCD=ABHGEFCDIJKL=B +AXUDJFGK=ABCDEKJHIFGL=Q diff --git a/test/051_compose_oriented/01_Uw_Fw.out b/test/051_compose_oriented/01_Uw_Fw.out @@ -0,0 +1 @@ +MBKGXFQD=ZBHYEFCDQWKL=J diff --git a/test/051_compose_oriented/02_scrambled_scrambled.in b/test/051_compose_oriented/02_scrambled_scrambled.in @@ -0,0 +1,4 @@ +JHFGDMQS=ZaUGRCFHQbTY=W +DCNORMXQ=YbaDFECXWRJA=G +// First cube: "F R Uw Lw' D E2 x y M" +// Second cube: "x R U R' Fw2 Bw y' S3" diff --git a/test/051_compose_oriented/02_scrambled_scrambled.out b/test/051_compose_oriented/02_scrambled_scrambled.out @@ -0,0 +1 @@ +VSMPGQJD=ZRHFLUCKAWYT=Q diff --git a/test/051_compose_oriented/compose_oriented_tests.c b/test/051_compose_oriented/compose_oriented_tests.c @@ -0,0 +1,24 @@ +#include "../test.h" + +oriented_cube_t compose_oriented(oriented_cube_t, oriented_cube_t); + +void run(void) { + char str[STRLENMAX]; + oriented_cube_t c1, c2, c3; + + fgets(str, STRLENMAX, stdin); + c1 = readcube(str); + fgets(str, STRLENMAX, stdin); + c2 = readcube(str); + + c3 = compose_oriented(c1, c2); + + if (iserror(c3)) { + printf("Error composing cubes\n"); + } else if (!issolvable(c3)) { + printf("Composed cube is not solvable\n"); + } else { + writecube(c3, NISSY_SIZE_CUBE, str); + printf("%s\n", str); + } +} diff --git a/test/062_transform_move/transform_move_tests.c b/test/062_transform_move/transform_move_tests.c @@ -4,7 +4,8 @@ cube_t applytrans(cube_t, const char *); uint8_t transform_move(uint8_t, uint8_t); -int64_t readmoves(const char *, size_t n, uint8_t [n]); +int64_t readmoves(const char *, size_t n, size_t m, + uint64_t *, uint64_t *, uint8_t [n], uint8_t [m]); oriented_cube_t move_extended(oriented_cube_t, uint8_t); oriented_cube_t applymoves(oriented_cube_t, const char *); uint8_t readtrans(const char[static NISSY_SIZE_TRANSFORMATION]); @@ -12,14 +13,19 @@ uint8_t readtrans(const char[static NISSY_SIZE_TRANSFORMATION]); void run(void) { char movestr[STRLENMAX], transtr[STRLENMAX], cubestr[STRLENMAX]; uint8_t t, moves[MAXMOVES]; - int i, n; + uint64_t i, n, ninv; + int64_t tot; oriented_cube_t cube; fgets(transtr, STRLENMAX, stdin); fgets(movestr, STRLENMAX, stdin); cube = solvedcube(); - n = readmoves(movestr, MAXMOVES, moves); + tot = readmoves(movestr, MAXMOVES, 0, &n, &ninv, moves, NULL); + if (tot < 0 || ninv != 0) { + printf("Test error reading moves\n"); + return; + } t = readtrans(transtr); for (i = 0; i < n; i++) cube = move_extended(cube, transform_move(moves[i], t)); diff --git a/test/130_appendsolution/00_empty.in b/test/130_appendsolution/00_empty.in @@ -1,5 +1,5 @@ - 0 1 rotation UF +0 diff --git a/test/130_appendsolution/01_simple_onlynormal_nounniss.in b/test/130_appendsolution/01_simple_onlynormal_nounniss.in @@ -1,5 +1,5 @@ U F R D2 B' - 0 1 rotation UF +0 diff --git a/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in b/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in @@ -1,8 +1,8 @@ U F R - 0 4 rotation UF mirrored UR rotation BD mirrored LB +0 diff --git a/test/130_appendsolution/03_simple_unniss.in b/test/130_appendsolution/03_simple_unniss.in @@ -1,5 +1,5 @@ -U F B2 -R' F D +U F B2 (R' F D) 1 1 rotation UF +0 diff --git a/test/130_appendsolution/04_niss_nounniss.in b/test/130_appendsolution/04_niss_nounniss.in @@ -1,5 +1,5 @@ -U F B2 -R' F D +U F B2 (R' F D) 0 1 rotation UF +0 diff --git a/test/130_appendsolution/05_sort_parallel.in b/test/130_appendsolution/05_sort_parallel.in @@ -1,5 +1,5 @@ L R' B2 F - 0 1 rotation UF +0 diff --git a/test/130_appendsolution/06_unniss_trans_sort.in b/test/130_appendsolution/06_unniss_trans_sort.in @@ -1,5 +1,5 @@ -B -R2 F2 +B (R2 F2) 1 1 rotation UR +0 diff --git a/test/130_appendsolution/07_unniss_cancel_nosol.in b/test/130_appendsolution/07_unniss_cancel_nosol.in @@ -1,5 +1,5 @@ -B' F -R2 B2 +B' F (R2 B2) 1 1 rotation UF +0 diff --git a/test/130_appendsolution/08_unniss_cancel_nosol_v2.in b/test/130_appendsolution/08_unniss_cancel_nosol_v2.in @@ -1,5 +1,5 @@ -F' B -R2 F2 +F' B (R2 F2) 1 1 rotation UF +0 diff --git a/test/130_appendsolution/09_fullinverse_niss.in b/test/130_appendsolution/09_fullinverse_niss.in @@ -1,5 +1,5 @@ - -F +(F) 0 1 rotation UF +0 diff --git a/test/130_appendsolution/10_rotated.in b/test/130_appendsolution/10_rotated.in @@ -0,0 +1,5 @@ +U2 F B L' +1 +1 +rotation UF +7 diff --git a/test/130_appendsolution/10_rotated.out b/test/130_appendsolution/10_rotated.out @@ -0,0 +1,4 @@ +D2 R L F' +Number of solutions: 1 +Shortest solution length: 4 +Used bytes: 10 diff --git a/test/130_appendsolution/appendsolution_tests.c b/test/130_appendsolution/appendsolution_tests.c @@ -1,11 +1,11 @@ /* Input format for appendsolution tests: -moves on normal -moves on inverse (without parentheses) +moves on normal (with NISS notation) unniss flag (0=false, 1=true) number of transformations transformations, one per line +the orientation of the cube, as a number from 0 to 23 See below for the output format. */ @@ -13,7 +13,8 @@ See below for the output format. #include "../test.h" uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]); -int64_t readmoves(const char *, size_t n, uint8_t [n]); +int64_t readmoves(const char *, size_t n, size_t m, + uint64_t *, uint64_t *, uint8_t [n], uint8_t [m]); void solution_moves_reset(solution_moves_t [static 1]); bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); int64_t appendsolution(const solution_moves_t [static 1], @@ -22,6 +23,8 @@ int64_t appendsolution(const solution_moves_t [static 1], void run(void) { int i, ntrans; + int64_t tot; + uint64_t nm, np; char str[STRLENMAX], buf[STRLENMAX]; solution_moves_t moves; solution_settings_t settings; @@ -38,9 +41,13 @@ void run(void) { }; fgets(str, STRLENMAX, stdin); - moves.nmoves = (uint8_t)readmoves(str, 20, moves.moves); - fgets(str, STRLENMAX, stdin); - moves.npremoves = (uint8_t)readmoves(str, 20, moves.premoves); + tot = readmoves(str, 20, 20, &nm, &np, moves.moves, moves.premoves); + if (tot < 0) { + printf("Test error reading moves\n"); + return; + } + moves.nmoves = nm; + moves.npremoves = np; fgets(str, STRLENMAX, stdin); settings.unniss = (bool)atoi(str); fgets(str, STRLENMAX, stdin); @@ -49,6 +56,8 @@ void run(void) { fgets(str, STRLENMAX, stdin); settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str); } + fgets(str, STRLENMAX, stdin); + settings.orientation = atoi(str); appendsolution(&moves, &settings, &list, false, "Test");