diff options
Diffstat (limited to '')
| -rw-r--r-- | src/solver.c | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/src/solver.c b/src/solver.c index 82abd85..48e845f 100644 --- a/src/solver.c +++ b/src/solver.c | |||
| @@ -107,6 +107,88 @@ int eo_scram_spam(int scram[], int eo_list[][30], int fb, int rl, int ud, | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | 109 | ||
| 110 | /******/ | ||
| 111 | /* CO */ | ||
| 112 | /******/ | ||
| 113 | void niss_co_dfs(int co, int scramble[], int co_list[][30], int *co_count, | ||
| 114 | int t_table[pow3to7][19], int p_table[pow3to7], | ||
| 115 | int last1, int last2, int moves, int m, int d, int niss, | ||
| 116 | int can_use_niss, int hide, int ignore) { | ||
| 117 | |||
| 118 | |||
| 119 | if (*co_count >= m || moves > d || | ||
| 120 | ((!can_use_niss || niss) && ((!ignore && moves + p_table[co] > d) || | ||
| 121 | ( ignore && moves + p_table[co] - 2 > d)))) | ||
| 122 | return; | ||
| 123 | |||
| 124 | co_list[*co_count][moves] = 0; | ||
| 125 | |||
| 126 | if (co == 0 || (ignore && ( t_table[t_table[co][F]][B] == 0 || | ||
| 127 | t_table[t_table[co][R]][L] == 0 || | ||
| 128 | t_table[t_table[co][U]][D] == 0 ))) { | ||
| 129 | /* If an early CO is found, or if "case F2 B", or if hide is on. */ | ||
| 130 | if (moves != d || (parallel(last1, last2) && last2 % 3 == 2) || | ||
| 131 | (hide && moves > 0 && | ||
| 132 | (last1 % 3 == 0 || (parallel(last1, last2) && last2 % 3 == 0)))) | ||
| 133 | return; | ||
| 134 | /* Copy moves for the next solution */ | ||
| 135 | if (*co_count < m - 1) | ||
| 136 | copy_moves(co_list[*co_count], co_list[(*co_count)+1]); | ||
| 137 | (*co_count)++; | ||
| 138 | return; | ||
| 139 | } | ||
| 140 | |||
| 141 | for (int i = 1; i < 19; i++) { | ||
| 142 | if (possible_next[last1][last2] & (1 << i)) { | ||
| 143 | co_list[*co_count][moves] = niss ? -i : i; | ||
| 144 | niss_co_dfs(t_table[co][i], scramble, co_list, co_count, t_table, | ||
| 145 | p_table, i, last1, moves+1, m, d, niss, | ||
| 146 | can_use_niss, hide, ignore); | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | if (*co_count >= m) | ||
| 151 | return; | ||
| 152 | co_list[*co_count][moves] = 0; | ||
| 153 | |||
| 154 | /* If not nissing already and we either have not done any move yet or | ||
| 155 | * the last move was F/F' etc, and if I am allowed to niss, try niss! */ | ||
| 156 | if (!niss && (last1 == 0 || t_table[0][last1] != 0) && can_use_niss && | ||
| 157 | !(hide && moves > 0 && | ||
| 158 | (last1 % 3 == 0 || (parallel(last1, last2) && last2 % 3 == 0)))) { | ||
| 159 | int aux[] = {0,0}; | ||
| 160 | niss_co_dfs(premoves_inverse(co_list[*co_count], scramble, aux, t_table), | ||
| 161 | scramble, co_list, co_count, t_table, p_table, | ||
| 162 | 0, 0, moves, m, d, 1, can_use_niss, hide, ignore); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | int co_scram_spam(int scram[], int co_list[][30], int fb, int rl, int ud, | ||
| 167 | int m, int b, int niss, int h, int ignore) { | ||
| 168 | |||
| 169 | init_small_pruning_tables(); | ||
| 170 | |||
| 171 | int n = 0, cofb = 0, corl = 0, coud = 0; | ||
| 172 | for (int i = 0; scram[i]; i++) { | ||
| 173 | cofb = cofb_transition_table[cofb][scram[i]]; | ||
| 174 | corl = corl_transition_table[corl][scram[i]]; | ||
| 175 | coud = coud_transition_table[coud][scram[i]]; | ||
| 176 | } | ||
| 177 | for (int i = 0; i <= b; i++) { | ||
| 178 | if (fb) | ||
| 179 | niss_co_dfs(cofb, scram, co_list, &n, cofb_transition_table, | ||
| 180 | cofb_pruning_table, 0, 0, 0, m, i, 0, niss, h, ignore); | ||
| 181 | if (rl) | ||
| 182 | niss_co_dfs(corl, scram, co_list, &n, corl_transition_table, | ||
| 183 | corl_pruning_table, 0, 0, 0, m, i, 0, niss, h, ignore); | ||
| 184 | if (ud) | ||
| 185 | niss_co_dfs(coud, scram, co_list, &n, coud_transition_table, | ||
| 186 | coud_pruning_table, 0, 0, 0, m, i, 0, niss, h, ignore); | ||
| 187 | } | ||
| 188 | return n; | ||
| 189 | } | ||
| 190 | |||
| 191 | |||
| 110 | /**************/ | 192 | /**************/ |
| 111 | /* DR from EO */ | 193 | /* DR from EO */ |
| 112 | /**************/ | 194 | /**************/ |
| @@ -600,10 +682,20 @@ void dr_corners_dfs(int cp, int sol[][30], int *sol_count, | |||
| 600 | 682 | ||
| 601 | sol[*sol_count][moves] = 0; | 683 | sol[*sol_count][moves] = 0; |
| 602 | 684 | ||
| 603 | if (cp == 0 || (ignore && | 685 | if (cp == 0 || |
| 686 | (ignore && mask == move_mask_drud && | ||
| 604 | (cp_transition_table[cp_transition_table[cp][U]][D3] == 0 || | 687 | (cp_transition_table[cp_transition_table[cp][U]][D3] == 0 || |
| 605 | cp_transition_table[cp_transition_table[cp][U2]][D2] == 0 || | 688 | cp_transition_table[cp_transition_table[cp][U2]][D2] == 0 || |
| 606 | cp_transition_table[cp_transition_table[cp][U3]][D] == 0 ))) { | 689 | cp_transition_table[cp_transition_table[cp][U3]][D] == 0 )) || |
| 690 | (ignore && mask == move_mask_drfb && | ||
| 691 | (cp_transition_table[cp_transition_table[cp][F]][B3] == 0 || | ||
| 692 | cp_transition_table[cp_transition_table[cp][F2]][B2] == 0 || | ||
| 693 | cp_transition_table[cp_transition_table[cp][F3]][B] == 0 )) || | ||
| 694 | (ignore && mask == move_mask_drrl && | ||
| 695 | (cp_transition_table[cp_transition_table[cp][R]][L3] == 0 || | ||
| 696 | cp_transition_table[cp_transition_table[cp][R2]][L2] == 0 || | ||
| 697 | cp_transition_table[cp_transition_table[cp][R3]][L] == 0 )) | ||
| 698 | ) { | ||
| 607 | if (moves != d) | 699 | if (moves != d) |
| 608 | return; | 700 | return; |
| 609 | /* Copy moves for the next solution */ | 701 | /* Copy moves for the next solution */ |
