diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-14 22:42:08 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-14 22:42:08 +0100 |
| commit | d5e7698d0c7ecb61fe49263982f750c053147089 (patch) | |
| tree | 5a6c16f28bbec007665f4b85e5c96344dd4ed617 /cube.c | |
| parent | e0f38c7e42d9e48ac654f9dcedf8722ff1136106 (diff) | |
| download | nissy-core-d5e7698d0c7ecb61fe49263982f750c053147089.tar.gz nissy-core-d5e7698d0c7ecb61fe49263982f750c053147089.zip | |
Added tests allowednext
Diffstat (limited to 'cube.c')
| -rw-r--r-- | cube.c | 27 |
1 files changed, 12 insertions, 15 deletions
| @@ -3165,19 +3165,19 @@ applymoves(cube_t cube, char *buf) | |||
| 3165 | while (*b == ' ' || *b == '\t' || *b == '\n') | 3165 | while (*b == ' ' || *b == '\t' || *b == '\n') |
| 3166 | b++; | 3166 | b++; |
| 3167 | if (*b == '\0') | 3167 | if (*b == '\0') |
| 3168 | goto readmoves_finish; | 3168 | goto applymoves_finish; |
| 3169 | if ((r = readmove(*b)) == _error) | 3169 | if ((r = readmove(*b)) == _error) |
| 3170 | goto readmoves_error; | 3170 | goto applymoves_error; |
| 3171 | if ((m = readmodifier(*(b+1))) != 0) | 3171 | if ((m = readmodifier(*(b+1))) != 0) |
| 3172 | b++; | 3172 | b++; |
| 3173 | fast = move(fast, r + m); | 3173 | fast = move(fast, r + m); |
| 3174 | } | 3174 | } |
| 3175 | 3175 | ||
| 3176 | readmoves_finish: | 3176 | applymoves_finish: |
| 3177 | return fasttocube(fast); | 3177 | return fasttocube(fast); |
| 3178 | 3178 | ||
| 3179 | readmoves_error: | 3179 | applymoves_error: |
| 3180 | DBG_LOG("readmoves error\n"); | 3180 | DBG_LOG("applymoves error\n"); |
| 3181 | return zero; | 3181 | return zero; |
| 3182 | } | 3182 | } |
| 3183 | 3183 | ||
| @@ -3725,7 +3725,7 @@ int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, | |||
| 3725 | void multisolve(int, cube_t *, char *, void *, char *); | 3725 | void multisolve(int, cube_t *, char *, void *, char *); |
| 3726 | int64_t gendata(char *, void *); | 3726 | int64_t gendata(char *, void *); |
| 3727 | 3727 | ||
| 3728 | _static bool allowednextmove(dfsarg_generic_t, uint8_t); | 3728 | _static bool allowednextmove(uint8_t *, int, uint8_t); |
| 3729 | _static void solve_generic_appendsolution(dfsarg_generic_t); | 3729 | _static void solve_generic_appendsolution(dfsarg_generic_t); |
| 3730 | _static int solve_generic_dfs(dfsarg_generic_t); | 3730 | _static int solve_generic_dfs(dfsarg_generic_t); |
| 3731 | _static int64_t solve_generic(cube_t, char *, int8_t, int8_t, int64_t, int8_t, | 3731 | _static int64_t solve_generic(cube_t, char *, int8_t, int8_t, int64_t, int8_t, |
| @@ -3796,20 +3796,17 @@ gendata(char *solver, void *data) | |||
| 3796 | } | 3796 | } |
| 3797 | 3797 | ||
| 3798 | _static bool | 3798 | _static bool |
| 3799 | allowednextmove(dfsarg_generic_t arg, uint8_t m) | 3799 | allowednextmove(uint8_t *moves, int n, uint8_t m) |
| 3800 | { | 3800 | { |
| 3801 | int n; | ||
| 3802 | uint8_t mbase, l1base, l2base, maxis, l1axis, l2axis; | 3801 | uint8_t mbase, l1base, l2base, maxis, l1axis, l2axis; |
| 3803 | 3802 | ||
| 3804 | n = arg.nmoves; | ||
| 3805 | |||
| 3806 | if (n == 0) | 3803 | if (n == 0) |
| 3807 | return true; | 3804 | return true; |
| 3808 | 3805 | ||
| 3809 | mbase = movebase(m); | 3806 | mbase = movebase(m); |
| 3810 | maxis = moveaxis(m); | 3807 | maxis = moveaxis(m); |
| 3811 | l1base = movebase(arg.moves[n-1]); | 3808 | l1base = movebase(moves[n-1]); |
| 3812 | l1axis = moveaxis(arg.moves[n-1]); | 3809 | l1axis = moveaxis(moves[n-1]); |
| 3813 | 3810 | ||
| 3814 | if (mbase == l1base || (maxis == l1axis && mbase < l1base)) | 3811 | if (mbase == l1base || (maxis == l1axis && mbase < l1base)) |
| 3815 | return false; | 3812 | return false; |
| @@ -3817,8 +3814,8 @@ allowednextmove(dfsarg_generic_t arg, uint8_t m) | |||
| 3817 | if (n == 1) | 3814 | if (n == 1) |
| 3818 | return true; | 3815 | return true; |
| 3819 | 3816 | ||
| 3820 | l2base = movebase(arg.moves[n-2]); | 3817 | l2base = movebase(moves[n-2]); |
| 3821 | l2axis = moveaxis(arg.moves[n-2]); | 3818 | l2axis = moveaxis(moves[n-2]); |
| 3822 | 3819 | ||
| 3823 | return l1axis != l2axis || mbase != l2base; | 3820 | return l1axis != l2axis || mbase != l2base; |
| 3824 | } | 3821 | } |
| @@ -3858,7 +3855,7 @@ solve_generic_dfs(dfsarg_generic_t arg) | |||
| 3858 | memcpy(&nextarg, &arg, sizeof(dfsarg_generic_t)); | 3855 | memcpy(&nextarg, &arg, sizeof(dfsarg_generic_t)); |
| 3859 | nextarg.nmoves = arg.nmoves + 1; | 3856 | nextarg.nmoves = arg.nmoves + 1; |
| 3860 | for (m = 0, ret = 0; m < 18; m++) { | 3857 | for (m = 0, ret = 0; m < 18; m++) { |
| 3861 | if (allowednextmove(arg, m)) { | 3858 | if (allowednextmove(arg.moves, arg.nmoves, m)) { |
| 3862 | nextarg.cube = move(arg.cube, m); | 3859 | nextarg.cube = move(arg.cube, m); |
| 3863 | nextarg.moves[arg.nmoves] = m; | 3860 | nextarg.moves[arg.nmoves] = m; |
| 3864 | ret += solve_generic_dfs(nextarg); | 3861 | ret += solve_generic_dfs(nextarg); |
