diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-20 16:47:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-20 16:57:38 +0200 |
| commit | f1575ed335166a0897f2cfd314a0f4bade6a10fc (patch) | |
| tree | 481c5d8ce5d14fe85fcd8f25cfbe4f94a697d5b5 /src | |
| parent | 3485be851f4fff1c9c6fe621f0619d2b4103bc06 (diff) | |
| download | nissy-core-f1575ed335166a0897f2cfd314a0f4bade6a10fc.tar.gz nissy-core-f1575ed335166a0897f2cfd314a0f4bade6a10fc.zip | |
Improve order of moves in NISS solutions
Now the side that has more moves is written first.
For example: write (U L F) B instead of B (U L F)
This also fixes the test on appendsolutions, which used an older version
of the function's signature.
Diffstat (limited to '')
| -rw-r--r-- | src/solvers/solutions.h | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index c9a1313..2340a80 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -6,6 +6,10 @@ STATIC bool solution_moves_equal( | |||
| 6 | const solution_moves_t [static 1], const solution_moves_t [static 1]); | 6 | const solution_moves_t [static 1], const solution_moves_t [static 1]); |
| 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); | 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); |
| 8 | STATIC bool appendchar(solution_list_t [static 1], char); | 8 | STATIC bool appendchar(solution_list_t [static 1], char); |
| 9 | STATIC bool appendnormal( | ||
| 10 | const solution_moves_t [static 1], solution_list_t [static 1]); | ||
| 11 | STATIC bool appendinverse( | ||
| 12 | const solution_moves_t [static 1], solution_list_t [static 1]); | ||
| 9 | STATIC int64_t appendsolution(const solution_moves_t [static 1], | 13 | STATIC int64_t appendsolution(const solution_moves_t [static 1], |
| 10 | const solution_settings_t [static 1], solution_list_t [static 1], bool, | 14 | const solution_settings_t [static 1], solution_list_t [static 1], bool, |
| 11 | const char *); | 15 | const char *); |
| @@ -94,6 +98,47 @@ appendchar(solution_list_t solutions[static 1], char c) | |||
| 94 | return true; | 98 | return true; |
| 95 | } | 99 | } |
| 96 | 100 | ||
| 101 | STATIC bool | ||
| 102 | appendnormal( | ||
| 103 | const solution_moves_t moves[static 1], | ||
| 104 | solution_list_t list[static 1] | ||
| 105 | ) | ||
| 106 | { | ||
| 107 | int64_t strl; | ||
| 108 | |||
| 109 | if (moves->nmoves == 0) | ||
| 110 | return true; | ||
| 111 | |||
| 112 | if ((strl = writemoves(moves->nmoves, moves->moves, | ||
| 113 | list->size - list->used, list->buf + list->used)) < 0) | ||
| 114 | return false; | ||
| 115 | list->used += strl; | ||
| 116 | |||
| 117 | return true; | ||
| 118 | } | ||
| 119 | |||
| 120 | STATIC bool | ||
| 121 | appendinverse( | ||
| 122 | const solution_moves_t moves[static 1], | ||
| 123 | solution_list_t list[static 1] | ||
| 124 | ) | ||
| 125 | { | ||
| 126 | int64_t strl; | ||
| 127 | |||
| 128 | if (moves->npremoves == 0) | ||
| 129 | return true; | ||
| 130 | |||
| 131 | if (!appendchar(list, '(')) | ||
| 132 | return false; | ||
| 133 | |||
| 134 | if ((strl = writemoves(moves->npremoves, moves->premoves, | ||
| 135 | list->size - list->used, list->buf + list->used)) < 0) | ||
| 136 | return false; | ||
| 137 | list->used += strl; | ||
| 138 | |||
| 139 | return appendchar(list, ')'); | ||
| 140 | } | ||
| 141 | |||
| 97 | STATIC int64_t | 142 | STATIC int64_t |
| 98 | appendsolution( | 143 | appendsolution( |
| 99 | const solution_moves_t moves[static 1], | 144 | const solution_moves_t moves[static 1], |
| @@ -103,7 +148,7 @@ appendsolution( | |||
| 103 | const char *solver_name | 148 | const char *solver_name |
| 104 | ) | 149 | ) |
| 105 | { | 150 | { |
| 106 | int64_t r, strl; | 151 | int64_t r; |
| 107 | int i; | 152 | int i; |
| 108 | uint8_t t; | 153 | uint8_t t; |
| 109 | solution_moves_t tsol[NTRANS]; | 154 | solution_moves_t tsol[NTRANS]; |
| @@ -151,28 +196,27 @@ appendsolution( | |||
| 151 | 196 | ||
| 152 | last_start = list->buf + list->used; | 197 | last_start = list->buf + list->used; |
| 153 | 198 | ||
| 154 | /* Write moves on normal */ | 199 | /* Append first the moves on the side that has more */ |
| 155 | strl = writemoves(tsol[r].nmoves, tsol[r].moves, | 200 | /* E.g. write (U L F) B instead of B (U L F) */ |
| 156 | list->size - list->used, list->buf + list->used); | 201 | if (tsol[r].nmoves >= tsol[r].npremoves) { |
| 157 | if (strl < 0) | 202 | if (!appendnormal(&tsol[r], list)) |
| 158 | goto appendsolution_error_buffer; | 203 | goto appendsolution_error_buffer; |
| 159 | list->used += strl; | ||
| 160 | 204 | ||
| 161 | /* Write moves on inverse with NISS notation */ | 205 | if (tsol[r].nmoves > 0 && tsol[r].npremoves > 0) |
| 162 | if (tsol[r].npremoves > 0) { | ||
| 163 | if (strl > 0) | ||
| 164 | if (!appendchar(list, ' ')) | 206 | if (!appendchar(list, ' ')) |
| 165 | goto appendsolution_error_buffer; | 207 | return false; |
| 166 | if (!appendchar(list, '(')) | ||
| 167 | goto appendsolution_error_buffer; | ||
| 168 | 208 | ||
| 169 | strl = writemoves(tsol[r].npremoves, tsol[r].premoves, | 209 | if (!appendinverse(&tsol[r], list)) |
| 170 | list->size - list->used, list->buf + list->used); | ||
| 171 | if (strl < 0) | ||
| 172 | goto appendsolution_error_buffer; | 210 | goto appendsolution_error_buffer; |
| 173 | list->used += strl; | 211 | } else { |
| 212 | if (!appendinverse(&tsol[r], list)) | ||
| 213 | goto appendsolution_error_buffer; | ||
| 214 | |||
| 215 | if (tsol[r].nmoves > 0 && tsol[r].npremoves > 0) | ||
| 216 | if (!appendchar(list, ' ')) | ||
| 217 | return false; | ||
| 174 | 218 | ||
| 175 | if (!appendchar(list, ')')) | 219 | if (!appendnormal(&tsol[r], list)) |
| 176 | goto appendsolution_error_buffer; | 220 | goto appendsolution_error_buffer; |
| 177 | } | 221 | } |
| 178 | 222 | ||
