aboutsummaryrefslogtreecommitdiff
path: root/src/solver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/solver.c')
-rw-r--r--src/solver.c100
1 files changed, 86 insertions, 14 deletions
diff --git a/src/solver.c b/src/solver.c
index d918a54..c61aec4 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -463,11 +463,11 @@ int dr_scram_spam(int scram[], int dr_list[][30], int fb, int rl, int ud,
463/* DR finish */ 463/* DR finish */
464/*************/ 464/*************/
465void dr_finish_dfs(int cp, int ep8, int ep4, int sol[][30], int *sol_count, 465void dr_finish_dfs(int cp, int ep8, int ep4, int sol[][30], int *sol_count,
466 int ep8_t_table[factorial8][19], 466 int ep8_t_table[factorial8][19],
467 int ep4_t_table[factorial4][19], 467 int ep4_t_table[factorial4][19],
468 int cp_p_table[factorial8], 468 int cp_p_table[factorial8],
469 int ep8_p_table[factorial8], 469 int ep8_p_table[factorial8],
470 int mask, int last1, int last2, int moves, int m, int d) { 470 int mask, int last1, int last2, int moves, int m, int d) {
471 471
472 472
473 if (*sol_count >= m || moves + cp_p_table[cp] > d || 473 if (*sol_count >= m || moves + cp_p_table[cp] > d ||
@@ -717,7 +717,7 @@ void small_optimal_dfs(int eofb, int eorl, int eoud, int ep,
717 } 717 }
718} 718}
719 719
720/* Solves directly using only medium tables. Suitable for short solutions. */ 720/* Solves directly using only medium tables. Suitable for short solutions.
721void medium_optimal_dfs(int eofb, int eorl, int eoud, 721void medium_optimal_dfs(int eofb, int eorl, int eoud,
722 int epose, int eposs, int eposm, int ep, 722 int epose, int eposs, int eposm, int ep,
723 int coud, int cofb, int corl, int cp, 723 int coud, int cofb, int corl, int cp,
@@ -766,6 +766,7 @@ void medium_optimal_dfs(int eofb, int eorl, int eoud,
766 } 766 }
767 } 767 }
768} 768}
769*/
769 770
770/* Uses huge tables */ 771/* Uses huge tables */
771int optimal_dfs(int ep, int cp, int eo, int co, int emslices, 772int optimal_dfs(int ep, int cp, int eo, int co, int emslices,
@@ -836,14 +837,6 @@ int solve_scram(int scram[], int sol[][30], int m, int b, int optimal) {
836 if (n >= m || b <= 10) 837 if (n >= m || b <= 10)
837 return n; 838 return n;
838 839
839 /* Then we try a slightly larger optimal solver */
840 /*
841 int max_medium = 11;
842 init_directdr_pruning_tables();
843 for (int i = 0; i <= min(b, max_medium); i++)
844 medium_optimal_dfs(eofb, eorl, eoud, epose, eposs, eposm, ep,
845 coud, cofb, corl, cp, sol, &n, 0, 0, 0, m, i);
846 */
847 840
848 /* If we found at least a solution, we return */ 841 /* If we found at least a solution, we return */
849 if (n > 0) 842 if (n > 0)
@@ -891,3 +884,82 @@ int solve_scram(int scram[], int sol[][30], int m, int b, int optimal) {
891 } 884 }
892 return best > b ? 0 : 1; 885 return best > b ? 0 : 1;
893} 886}
887
888/* Given eofb, coud, ep and cp it finds a scramble that reaches that state.
889 * It uses a simple 3-step solver to find a preliminary "solution", and then
890 * gives this solutions as a scramble to a better solver (see above). */
891int reach_state(int eofb, int coud, int ep, int cp, int sol[][30]) {
892
893 int fake_count = 0, fake_scram[30];
894 int eo_list[2][30], dr_list[2][30], finish_list[2][30];
895
896 /* Convert ep to array */
897 int ep_arr[12];
898 ep_int_to_array(ep, ep_arr);
899
900 /* Find EO */
901 init_small_pruning_tables();
902 for (int d = 0; d < 10; d++) {
903 niss_eo_dfs(eofb, fake_scram, eo_list, &fake_count, eofb_transition_table,
904 eofb_pruning_table, 0, 0, 0, 1, d, 0, 0, 0);
905 if (fake_count) {
906 fake_count = 0;
907 break;
908 }
909 }
910
911 /* Apply moves found, find epose */
912 for (int i = 0; eo_list[0][i]; i++) {
913 coud = coud_transition_table[coud][eo_list[0][i]];
914 cp = cp_transition_table[cp][eo_list[0][i]];
915 apply_move_ep_array(eo_list[0][i], ep_arr);
916 }
917 int epose = epose_array_to_int(ep_arr);
918
919 /* Find DR */
920 init_drfromeo_pruning_tables();
921 for (int d = 0; d < 16; d++) {
922 niss_dr_from_eo_dfs(coud, epose, fake_scram, fake_scram, dr_list,
923 &fake_count, coud_transition_table,
924 epose_transition_table,
925 coud_epose_from_eofb_pruning_table, move_mask_eofb,
926 0, 0, 0, 0, 0, 1, d, 0, 0, 0);
927 if (fake_count) {
928 fake_count = 0;
929 break;
930 }
931 }
932
933 /* Apply moves found, find epud and epe */
934 for (int i = 0; dr_list[0][i]; i++) {
935 cp = cp_transition_table[cp][dr_list[0][i]];
936 apply_move_ep_array(dr_list[0][i], ep_arr);
937 }
938 int epud = epud_array_to_int(ep_arr);
939 int epe = epe_array_to_int(ep_arr);
940
941 /* Find finish */
942 init_small_pruning_tables();
943 for (int d = 0; d < 16; d++) {
944 dr_finish_dfs(cp, epud, epe, finish_list, &fake_count,
945 epud_transition_table, epe_transition_table,
946 cp_drud_pruning_table, epud_pruning_table, move_mask_drud,
947 0, 0, 0, 1, d);
948 if (fake_count) {
949 fake_count = 0;
950 break;
951 }
952 }
953
954 int scram[50];
955
956 /* Debug */
957 /*print_moves(eo_list[0]); printf("\n");
958 print_moves(dr_list[0]); printf("\n");
959 print_moves(finish_list[0]); printf("\n");*/
960
961 copy_moves(eo_list[0], scram);
962 append_moves(dr_list[0], scram);
963 append_moves(finish_list[0], scram);
964 return solve_scram(scram, sol, 1, 25, 0);
965}

Generated with cgit - Back to sebastiano.tronto.net