aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/solvers/coord/solve.h80
-rw-r--r--src/solvers/solutions.h1
2 files changed, 58 insertions, 23 deletions
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h
index 6ddb9dd..9170cca 100644
--- a/src/solvers/coord/solve.h
+++ b/src/solvers/coord/solve.h
@@ -66,47 +66,83 @@ solve_coord_dfs_stop(const dfsarg_solve_coord_t arg[static 1])
66STATIC bool 66STATIC bool
67coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) 67coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1])
68{ 68{
69 uint8_t f, nn, ni, th; 69 uint8_t flag, nn, ni, swbound_n, swbound_i;
70 70
71 f = arg->nissflag; 71 flag = arg->nissflag;
72 nn = arg->solution_moves->nmoves; 72 nn = arg->solution_moves->nmoves;
73 ni = arg->solution_moves->npremoves; 73 ni = arg->solution_moves->npremoves;
74 th = DIV_ROUND_UP(arg->target_depth, 2); 74 swbound_n = arg->target_depth / 2;
75 swbound_i = DIV_ROUND_UP(arg->target_depth, 2) - 1;
75 76
77 /* If only inverse moves are allowed */
78 if (flag == NISSY_NISSFLAG_INVERSE)
79 return false;
80
81 /* It's the first move */
76 if (nn + ni == 0) 82 if (nn + ni == 0)
77 return f & (NISSY_NISSFLAG_NORMAL | NISSY_NISSFLAG_MIXED); 83 return true;
84
85 if (arg->lastisnormal) {
86 /* Can continue if we have already switched */
87 if (ni > 0)
88 return true;
78 89
79 /* TODO logic here can probably be simplified */ 90 /* Check that we have enough moves left to switch */
80 if (arg->lastisnormal) 91 return flag & NISSY_NISSFLAG_NORMAL || nn < swbound_n;
81 return (f & NISSY_NISSFLAG_NORMAL) || 92 } else {
82 ((f & NISSY_NISSFLAG_MIXED) && (ni > 0 || nn <= th)); 93 /* Forbid switching multiple times */
94 if (nn > 0)
95 return false;
96
97 /* Some coordinates are not allowed to switch */
98 if (!coord_can_switch(arg->coord, arg->coord_data,
99 ni, arg->solution_moves->premoves))
100 return false;
83 101
84 return (f & NISSY_NISSFLAG_MIXED) && nn == 0 && ni < th && 102 /* Only switch before half solution is found */
85 coord_can_switch(arg->coord, arg->coord_data, 103 return ni <= swbound_i;
86 ni, arg->solution_moves->premoves); 104 }
87} 105}
88 106
89STATIC bool 107STATIC bool
90coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) 108coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1])
91{ 109{
92 uint8_t f, nn, ni, th; 110 uint8_t flag, nn, ni, swbound_n, swbound_i;
93 111
94 f = arg->nissflag; 112 flag = arg->nissflag;
95 nn = arg->solution_moves->nmoves; 113 nn = arg->solution_moves->nmoves;
96 ni = arg->solution_moves->npremoves; 114 ni = arg->solution_moves->npremoves;
97 th = DIV_ROUND_UP(arg->target_depth, 2); 115 swbound_n = arg->target_depth / 2;
116 swbound_i = DIV_ROUND_UP(arg->target_depth, 2) - 1;
98 117
118 /* If only normal moves are allowed */
119 if (flag == NISSY_NISSFLAG_NORMAL)
120 return false;
121
122 /* It's the first move */
99 if (nn + ni == 0) 123 if (nn + ni == 0)
100 return f & (NISSY_NISSFLAG_INVERSE | NISSY_NISSFLAG_MIXED); 124 return true;
125
126 if (!arg->lastisnormal) {
127 /* Can continue if we have already switched */
128 if (nn > 0)
129 return true;
101 130
102 /* TODO logic here can probably be simplified */ 131 /* Check that we have enough moves left to switch */
103 if (!arg->lastisnormal) 132 return flag & NISSY_NISSFLAG_INVERSE || ni < swbound_i;
104 return (f & NISSY_NISSFLAG_INVERSE) || 133 } else {
105 ((f & NISSY_NISSFLAG_MIXED) && (nn > 0 || ni < th)); 134 /* Forbid switching multiple times */
135 if (ni > 0)
136 return false;
137
138 /* Some coordinates are not allowed to switch */
139 if (!coord_can_switch(arg->coord, arg->coord_data,
140 nn, arg->solution_moves->moves))
141 return false;
106 142
107 return (f & NISSY_NISSFLAG_MIXED) && ni == 0 && nn <= th && 143 /* Only switch before half solution is found */
108 coord_can_switch(arg->coord, arg->coord_data, 144 return nn <= swbound_n;
109 nn, arg->solution_moves->moves); 145 }
110} 146}
111 147
112STATIC int64_t 148STATIC int64_t
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h
index 0eb3a7f..00ed84c 100644
--- a/src/solvers/solutions.h
+++ b/src/solvers/solutions.h
@@ -233,7 +233,6 @@ appendsolution(
233 list->shortest_sol = MIN( 233 list->shortest_sol = MIN(
234 list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); 234 list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves);
235 r++; 235 r++;
236
237 } 236 }
238 237
239 list->buf[list->used] = '\0'; 238 list->buf[list->used] = '\0';

Generated with cgit - Back to sebastiano.tronto.net