multi-puzzle-solver 0.9.0__py3-none-any.whl → 0.9.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multi-puzzle-solver
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: Efficient solvers for numerous popular and esoteric logic puzzles using CP-SAT
5
5
  Author: Ar-Kareem
6
6
  Project-URL: Homepage, https://github.com/Ar-Kareem/puzzle_solver
@@ -89,134 +89,143 @@ These are all the puzzles that are implemented in this repo. <br> Click on any o
89
89
  <tr>
90
90
  <td align="center">
91
91
  <a href="#nonograms-puzzle-type-1"><b>Nonograms</b><br><br>
92
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/nonogram_solved.png" alt="Nonograms" height="120">
92
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/nonogram_solved.png" alt="Nonograms" width="200">
93
93
  </a>
94
94
  </td>
95
95
  <td align="center">
96
96
  <a href="#sudoku-puzzle-type-2"><b>Sudoku</b><br><br>
97
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/sudoku_solved.png" alt="Sudoku" height="120">
97
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/sudoku_solved.png" alt="Sudoku" width="200">
98
98
  </a>
99
99
  </td>
100
100
  <td align="center">
101
101
  <a href="#minesweeper-puzzle-type-3"><b>Minesweeper</b><br><br>
102
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/minesweeper_pre.png" alt="Minesweeper" height="120">
102
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/minesweeper_pre.png" alt="Minesweeper" width="200">
103
103
  </a>
104
104
  </td>
105
105
  <td align="center">
106
106
  <a href="#dominosa-puzzle-type-4"><b>Dominosa</b><br><br>
107
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/dominosa_solved.png" alt="Dominosa" height="120">
107
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/dominosa_solved.png" alt="Dominosa" width="200">
108
108
  </a>
109
109
  </td>
110
110
  <td align="center">
111
111
  <a href="#light-up-puzzle-type-5"><b>Light Up</b><br><br>
112
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/lightup_solved.png" alt="Light Up" height="120">
112
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/lightup_solved.png" alt="Light Up" width="200">
113
113
  </a>
114
114
  </td>
115
115
  </tr>
116
116
  <tr>
117
117
  <td align="center">
118
118
  <a href="#tents-puzzle-type-6"><b>Tents</b><br><br>
119
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/tents_solved.png" alt="Tents" height="120">
119
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/tents_solved.png" alt="Tents" width="200">
120
120
  </a>
121
121
  </td>
122
122
  <td align="center">
123
123
  <a href="#filling-puzzle-type-7"><b>Filling</b><br><br>
124
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/filling_solved.png" alt="Filling" height="120">
124
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/filling_solved.png" alt="Filling" width="200">
125
125
  </a>
126
126
  </td>
127
127
  <td align="center">
128
128
  <a href="#keen-puzzle-type-8"><b>Keen</b><br><br>
129
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/keen_solved.png" alt="Keen" height="120">
129
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/keen_solved.png" alt="Keen" width="200">
130
130
  </a>
131
131
  </td>
132
132
  <td align="center">
133
133
  <a href="#towers-puzzle-type-9"><b>Towers</b><br><br>
134
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/towers_solved.png" alt="Towers" height="120">
134
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/towers_solved.png" alt="Towers" width="200">
135
135
  </a>
136
136
  </td>
137
137
  <td align="center">
138
138
  <a href="#singles-puzzle-type-10"><b>Singles</b><br><br>
139
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/singles_solved.png" alt="Singles" height="120">
139
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/singles_solved.png" alt="Singles" width="200">
140
140
  </a>
141
141
  </td>
142
142
  </tr>
143
143
  <tr>
144
144
  <td align="center">
145
145
  <a href="#magnets-puzzle-type-11"><b>Magnets</b><br><br>
146
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/magnets_solved.png" alt="Magnets" height="120">
146
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/magnets_solved.png" alt="Magnets" width="200">
147
147
  </a>
148
148
  </td>
149
149
  <td align="center">
150
150
  <a href="#signpost-puzzle-type-12"><b>Signpost</b><br><br>
151
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/signpost_solved.png" alt="Signpost" height="120">
151
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/signpost_solved.png" alt="Signpost" width="200">
152
152
  </a>
153
153
  </td>
154
154
  <td align="center">
155
155
  <a href="#range-puzzle-type-13"><b>Range</b><br><br>
156
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/range_solved.png" alt="Range" height="120">
156
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/range_solved.png" alt="Range" width="200">
157
157
  </a>
158
158
  </td>
159
159
  <td align="center">
160
160
  <a href="#undead-puzzle-type-14"><b>Undead</b><br><br>
161
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/undead_solved.png" alt="Undead" height="120">
161
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/undead_solved.png" alt="Undead" width="200">
162
162
  </a>
163
163
  </td>
164
164
  <td align="center">
165
165
  <a href="#unruly-puzzle-type-15"><b>Unruly</b><br><br>
166
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/unruly_solved.png" alt="Unruly" height="120">
166
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/unruly_solved.png" alt="Unruly" width="200">
167
167
  </a>
168
168
  </td>
169
169
  </tr>
170
170
  <tr>
171
171
  <td align="center">
172
172
  <a href="#tracks-puzzle-type-16"><b>Tracks</b><br><br>
173
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/tracks_solved.png" alt="Tracks" height="120">
173
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/tracks_solved.png" alt="Tracks" width="200">
174
174
  </a>
175
175
  </td>
176
176
  <td align="center">
177
177
  <a href="#mosaic-puzzle-type-17"><b>Mosaic</b><br><br>
178
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/mosaic_solved.png" alt="Mosaic" height="120">
178
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/mosaic_solved.png" alt="Mosaic" width="200">
179
179
  </a>
180
180
  </td>
181
181
  <td align="center">
182
182
  <a href="#map-puzzle-type-18"><b>Map</b><br><br>
183
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/map_solved.png" alt="Map" height="120">
183
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/map_solved.png" alt="Map" width="200">
184
184
  </a>
185
185
  </td>
186
186
  <td align="center">
187
187
  <a href="#pearl-puzzle-type-19"><b>Pearl</b><br><br>
188
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/pearl_solved.png" alt="Pearl" height="120">
188
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/pearl_solved.png" alt="Pearl" width="200">
189
189
  </a>
190
190
  </td>
191
191
  <td align="center">
192
192
  <a href="#bridges-puzzle-type-20"><b>Bridges</b><br><br>
193
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/bridges_solved.png" alt="Bridges" height="120">
193
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/bridges_solved.png" alt="Bridges" width="200">
194
194
  </a>
195
195
  </td>
196
196
  </tr>
197
197
  <tr>
198
198
  <td align="center">
199
199
  <a href="#inertia-puzzle-type-21"><b>Inertia</b><br><br>
200
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/inertia_unsolved.png" alt="Inertia" height="120">
200
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/inertia_unsolved.png" alt="Inertia" width="200">
201
201
  </a>
202
202
  </td>
203
203
  <td align="center">
204
204
  <a href="#guess-puzzle-type-22"><b>Guess</b><br><br>
205
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/guess_3.png" alt="Guess" height="120">
205
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/guess_3.png" alt="Guess" width="200">
206
206
  </a>
207
207
  </td>
208
208
  <td align="center">
209
209
  <a href="#chess-range-puzzle-type-23"><b>Chess Range</b><br><br>
210
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/chess_range_unsolved.png" alt="Chess range" height="120">
210
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/chess_range_unsolved.png" alt="Chess range" width="200">
211
211
  </a>
212
212
  </td>
213
213
  <td align="center">
214
214
  <a href="#chess-solo-puzzle-type-24"><b>Chess Solo</b><br><br>
215
- <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/chess_solo_unsolved.png" alt="Chess solo" height="120">
215
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/chess_solo_unsolved.png" alt="Chess solo" width="200">
216
216
  </a>
217
217
  </td>
218
218
  <td align="center">
219
-
219
+ <a href="#chess-melee-puzzle-type-25"><b>Chess Melee</b><br><br>
220
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/chess_melee_unsolved.png" alt="Chess melee" width="200">
221
+ </a>
222
+ </td>
223
+ </tr>
224
+ <tr>
225
+ <td align="center">
226
+ <a href="#thermometers-puzzle-type-26"><b>Thermometers</b><br><br>
227
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/thermometers_unsolved.png" alt="Thermometers" width="200">
228
+ </a>
220
229
  </td>
221
230
  </tr>
222
231
  </table>
@@ -258,6 +267,7 @@ These are all the puzzles that are implemented in this repo. <br> Click on any o
258
267
  - [Chess Range (Puzzle Type #23)](#chess-range-puzzle-type-23)
259
268
  - [Chess Solo (Puzzle Type #24)](#chess-solo-puzzle-type-24)
260
269
  - [Chess Melee (Puzzle Type #25)](#chess-melee-puzzle-type-25)
270
+ - [Thermometers (Puzzle Type #26)](#thermometers-puzzle-type-26)
261
271
  - [Why SAT / CP-SAT?](#why-sat--cp-sat)
262
272
  - [Testing](#testing)
263
273
  - [Contributing](#contributing)
@@ -2021,6 +2031,7 @@ Code to utilize this package and solve the puzzle:
2021
2031
  (Note that this puzzle does not typically have a unique solution. Thus, we specify here that we only want the first valid solution that the solver finds.)
2022
2032
 
2023
2033
  ```python
2034
+ from puzzle_solver import chess_solo_solver as solver
2024
2035
  # algebraic notation
2025
2036
  board = ['Kc6', 'Rc5', 'Rc4', 'Pb3', 'Bd3', 'Pd2', 'Pe3', 'Nf2', 'Ng2', 'Qg3', 'Pg6']
2026
2037
  binst = solver.Board(board)
@@ -2071,6 +2082,7 @@ Code to utilize this package and solve the puzzle:
2071
2082
  (Note that this puzzle does not typically have a unique solution. Thus, we specify here that we only want the first valid solution that the solver finds.)
2072
2083
 
2073
2084
  ```python
2085
+ from puzzle_solver import chess_melee_solver as solver
2074
2086
  # algebraic notation
2075
2087
  board = ['Pb7', 'Nc7', 'Bc6', 'Ne6', 'Pb5', 'Rc4', 'Qb3', 'Rf7', 'Rb6', 'Pe5', 'Nc3', 'Pd3', 'Nf3']
2076
2088
  colors = ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'W', 'W']
@@ -2095,6 +2107,82 @@ Time taken: 6.24 seconds
2095
2107
 
2096
2108
  ---
2097
2109
 
2110
+ ## Thermometers (Puzzle Type #26)
2111
+
2112
+ * [**Play online**](https://www.puzzle-thermometers.com/)
2113
+
2114
+ * [**Solver Code**][26]
2115
+
2116
+ <details>
2117
+ <summary><strong>Rules</strong></summary>
2118
+
2119
+ You have to fill some thermometers with mercury starting from the bulb and going toward the end without gaps.
2120
+ The numbers outside the grid show the number of filled cells horizontally and vertically.
2121
+
2122
+ </details>
2123
+
2124
+ **Unsolved puzzle**
2125
+
2126
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/thermometers_unsolved.png" alt="Thermometers unsolved" width="500">
2127
+
2128
+ Code to utilize this package and solve the puzzle:
2129
+
2130
+ (Note that this puzzle does not typically have a unique solution. Thus, we specify here that we only want the first valid solution that the solver finds.)
2131
+
2132
+ ```python
2133
+ from puzzle_solver import thermometers_solver as solver
2134
+ board = np.array([
2135
+ ['R', 'R', 'D', 'R', 'D', 'R', 'X', 'D', 'L', 'X', 'L', 'L', 'L', 'L', 'L'],
2136
+ ['D', 'D', 'D', 'U', 'X', 'U', 'X', 'R', 'R', 'R', 'R', 'D', 'D', 'R', 'U'],
2137
+ ['D', 'D', 'D', 'U', 'X', 'U', 'U', 'R', 'R', 'R', 'X', 'D', 'D', 'D', 'D'],
2138
+ ['X', 'D', 'D', 'U', 'U', 'U', 'L', 'U', 'R', 'R', 'D', 'X', 'D', 'X', 'X'],
2139
+ ['X', 'D', 'D', 'U', 'U', 'R', 'R', 'R', 'R', 'X', 'R', 'X', 'D', 'R', 'X'],
2140
+ ['U', 'D', 'D', 'U', 'U', 'R', 'X', 'R', 'R', 'R', 'R', 'D', 'D', 'R', 'D'],
2141
+ ['U', 'D', 'D', 'R', 'R', 'X', 'R', 'R', 'R', 'R', 'D', 'D', 'R', 'X', 'D'],
2142
+ ['U', 'D', 'D', 'U', 'X', 'L', 'X', 'L', 'R', 'X', 'X', 'R', 'X', 'X', 'L'],
2143
+ ['U', 'D', 'D', 'R', 'X', 'U', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'],
2144
+ ['X', 'D', 'X', 'U', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'D', 'U'],
2145
+ ['U', 'D', 'X', 'U', 'R', 'R', 'X', 'R', 'R', 'R', 'R', 'X', 'X', 'L', 'U'],
2146
+ ['U', 'R', 'U', 'U', 'R', 'X', 'R', 'X', 'R', 'X', 'R', 'R', 'R', 'R', 'U'],
2147
+ ['U', 'R', 'X', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'X', 'X', 'L'],
2148
+ ['U', 'U', 'R', 'R', 'X', 'D', 'R', 'R', 'D', 'R', 'X', 'X', 'L', 'L', 'U'],
2149
+ ['U', 'U', 'U', 'L', 'L', 'R', 'X', 'X', 'L', 'U', 'R', 'R', 'R', 'U', 'U'],
2150
+ ])
2151
+ top = np.array([7, 4, 12, 8, 4, 6, 5, 7, 5, 4, 8, 9, 13, 8, 12])
2152
+ side = np.array([8, 10, 9, 10, 6, 10, 4, 6, 6, 10, 5, 7, 6, 6, 9])
2153
+ binst = solver.Board(board=board, top=top, side=side)
2154
+ solutions = binst.solve_and_print()
2155
+ ```
2156
+ **Script Output**
2157
+
2158
+ ```python
2159
+ Solution found
2160
+ [['X' 'X' 'X' ' ' ' ' ' ' ' ' 'X' 'X' ' ' ' ' ' ' 'X' 'X' 'X']
2161
+ ['X' ' ' 'X' ' ' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X']
2162
+ ['X' ' ' 'X' 'X' ' ' 'X' 'X' 'X' ' ' ' ' ' ' 'X' 'X' ' ' 'X']
2163
+ [' ' ' ' 'X' 'X' ' ' 'X' 'X' 'X' 'X' 'X' 'X' ' ' 'X' ' ' 'X']
2164
+ [' ' ' ' 'X' 'X' ' ' ' ' ' ' ' ' ' ' ' ' 'X' ' ' 'X' 'X' 'X']
2165
+ [' ' ' ' 'X' 'X' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X']
2166
+ [' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X' 'X' ' ' 'X']
2167
+ [' ' ' ' 'X' ' ' ' ' ' ' 'X' 'X' ' ' ' ' ' ' 'X' 'X' ' ' 'X']
2168
+ [' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X']
2169
+ [' ' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' ' ' 'X']
2170
+ [' ' ' ' ' ' 'X' 'X' 'X' 'X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X']
2171
+ ['X' ' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X']
2172
+ ['X' 'X' 'X' 'X' 'X' 'X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2173
+ ['X' 'X' 'X' ' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ' 'X' 'X' ' ']
2174
+ ['X' 'X' 'X' 'X' 'X' ' ' ' ' ' ' ' ' ' ' 'X' 'X' 'X' 'X' ' ']]
2175
+ Solutions found: 1
2176
+ status: OPTIMAL
2177
+ Time taken: 0.01 seconds
2178
+ ```
2179
+
2180
+ **Solved puzzle**
2181
+
2182
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/thermometers_solved.png" alt="Thermometers solved" width="500">
2183
+
2184
+ ---
2185
+
2098
2186
  ---
2099
2187
 
2100
2188
  ## Why SAT / CP-SAT?
@@ -2170,3 +2258,5 @@ Issues and PRs welcome!
2170
2258
  [17]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/mosaic "puzzle_solver/src/puzzle_solver/puzzles/mosaic at master · Ar-Kareem/puzzle_solver · GitHub"
2171
2259
  [23]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/chess_range "puzzle_solver/src/puzzle_solver/puzzles/chess_range at master · Ar-Kareem/puzzle_solver · GitHub"
2172
2260
  [24]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/chess_range#chess-solo-puzzle-type-24 "puzzle_solver/src/puzzle_solver/puzzles/chess_range at master · Ar-Kareem/puzzle_solver · GitHub"
2261
+ [25]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/chess_range#chess-melee-puzzle-type-25 "puzzle_solver/src/puzzle_solver/puzzles/chess_range at master · Ar-Kareem/puzzle_solver · GitHub"
2262
+ [26]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/thermometers "puzzle_solver/src/puzzle_solver/puzzles/thermometers at master · Ar-Kareem/puzzle_solver · GitHub"
@@ -1,4 +1,4 @@
1
- puzzle_solver/__init__.py,sha256=bPtr98uTvRDOU7v5H1iXRfEHuZa5qSE3coOgZjT8Ea4,1813
1
+ puzzle_solver/__init__.py,sha256=5mfy5LbHdS064RgwFi88S3-ccHJSuSIOw8ONWwW9n5E,1896
2
2
  puzzle_solver/core/utils.py,sha256=3LlBDuie_G0uSlzibpQS2ULmEYSZmpJXh1kawj7rjkg,3396
3
3
  puzzle_solver/core/utils_ortools.py,sha256=qLTIzmITqmgGZvg8XpYAZ4c-lhD5sEDQfS8ECdQ_dkM,3005
4
4
  puzzle_solver/puzzles/bridges/bridges.py,sha256=zUT0TMIu8l982fqDMJfsTnTgqm48nG0iH8flsGT45_E,5489
@@ -25,11 +25,12 @@ puzzle_solver/puzzles/signpost/signpost.py,sha256=D19ua8rVwO6sgXq4nVLkZfEyz8hqc6
25
25
  puzzle_solver/puzzles/singles/singles.py,sha256=kwMENfqQ-OP3YIz5baY6LRcvYCsNfhImEXN00lwazKM,5658
26
26
  puzzle_solver/puzzles/sudoku/sudoku.py,sha256=M_pry7XyKKzlfCF5rFi02lyOrj5GWZzXnDAxmD3NXvI,3588
27
27
  puzzle_solver/puzzles/tents/tents.py,sha256=iyVK2WXfIT5j_9qqlQg0WmwvixwXlZSsHGK3XA-KpII,6283
28
+ puzzle_solver/puzzles/thermometers/thermometers.py,sha256=nsvJZkm7G8FALT27bpaB0lv5E_AWawqmvapQI8QcYXw,4015
28
29
  puzzle_solver/puzzles/towers/towers.py,sha256=QvL0Pp-Z2ewCeq9ZkNrh8MShKOh-Y52sFBSudve68wk,6496
29
30
  puzzle_solver/puzzles/tracks/tracks.py,sha256=VnAtxBkuUTHJYNXr1JGg0yYzJj3kRMBi8Nz7NHKS94A,9089
30
31
  puzzle_solver/puzzles/undead/undead.py,sha256=ygNugW5SOlYLy6d740gZ2IW9UJQ3SAr9vuMm0ZFr2nY,6630
31
32
  puzzle_solver/puzzles/unruly/unruly.py,sha256=sDF0oKT50G-NshyW2DYrvAgD9q9Ku9ANUyNhGSAu7cQ,3827
32
- multi_puzzle_solver-0.9.0.dist-info/METADATA,sha256=vN-LmOU4spC46p31NuuT1stsyR6fGzqm1E77gt8hECc,104532
33
- multi_puzzle_solver-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- multi_puzzle_solver-0.9.0.dist-info/top_level.txt,sha256=exwVUQa-anK9vYrpKzBPvH8bX43iElWI4VeNiAyBGJY,14
35
- multi_puzzle_solver-0.9.0.dist-info/RECORD,,
33
+ multi_puzzle_solver-0.9.2.dist-info/METADATA,sha256=0yrFGQEnj6iuXxSuR9BA8aGHT8WTcaW6xcQeElkZK0E,109184
34
+ multi_puzzle_solver-0.9.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ multi_puzzle_solver-0.9.2.dist-info/top_level.txt,sha256=exwVUQa-anK9vYrpKzBPvH8bX43iElWI4VeNiAyBGJY,14
36
+ multi_puzzle_solver-0.9.2.dist-info/RECORD,,
puzzle_solver/__init__.py CHANGED
@@ -19,6 +19,7 @@ from puzzle_solver.puzzles.signpost import signpost as signpost_solver
19
19
  from puzzle_solver.puzzles.singles import singles as singles_solver
20
20
  from puzzle_solver.puzzles.sudoku import sudoku as sudoku_solver
21
21
  from puzzle_solver.puzzles.tents import tents as tents_solver
22
+ from puzzle_solver.puzzles.thermometers import thermometers as thermometers_solver
22
23
  from puzzle_solver.puzzles.towers import towers as towers_solver
23
24
  from puzzle_solver.puzzles.tracks import tracks as tracks_solver
24
25
  from puzzle_solver.puzzles.undead import undead as undead_solver
@@ -26,4 +27,4 @@ from puzzle_solver.puzzles.unruly import unruly as unruly_solver
26
27
 
27
28
  from puzzle_solver.puzzles.inertia.parse_map.parse_map import main as inertia_image_parser
28
29
 
29
- __version__ = '0.9.0'
30
+ __version__ = '0.9.2'
@@ -0,0 +1,82 @@
1
+ from typing import Optional
2
+
3
+ import numpy as np
4
+ from ortools.sat.python import cp_model
5
+
6
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, Direction, get_opposite_direction, get_next_pos, in_bounds, get_row_pos, get_col_pos
7
+ from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution
8
+
9
+ def get_direction(pos: Pos, board: np.array) -> Optional[Direction]:
10
+ if get_char(board, pos) == 'R':
11
+ return Direction.RIGHT
12
+ elif get_char(board, pos) == 'D':
13
+ return Direction.DOWN
14
+ elif get_char(board, pos) == 'U':
15
+ return Direction.UP
16
+ elif get_char(board, pos) == 'L':
17
+ return Direction.LEFT
18
+ return None
19
+
20
+ def move_backward(pos: Pos, board: np.array) -> Pos:
21
+ for direction in Direction:
22
+ opposite_direction = get_opposite_direction(direction)
23
+ neighbor = get_next_pos(pos, direction)
24
+ if in_bounds(neighbor, board.shape[0], board.shape[1]) and get_direction(neighbor, board) == opposite_direction: # the neighbor is pointing to me
25
+ return neighbor
26
+ return None
27
+
28
+ class Board:
29
+ def __init__(self, board: np.array, top: np.array, side: np.array):
30
+ assert board.ndim == 2, f'board must be 2d, got {board.ndim}'
31
+ self.V = board.shape[0]
32
+ self.H = board.shape[1]
33
+ assert top.ndim == 1 and top.shape[0] == self.H, 'top must be a 1d array of length board width'
34
+ assert side.ndim == 1 and side.shape[0] == self.V, 'side must be a 1d array of length board height'
35
+ assert all((c in ['R', 'D', 'U', 'X', 'L']) for c in np.nditer(board)), 'board must contain only valid characters: R, D, U, X, L'
36
+ self.board = board
37
+ self.top = top
38
+ self.side = side
39
+ self.tip: set[Pos] = {pos for pos in get_all_pos(self.V, self.H) if get_char(self.board, pos) == 'X'}
40
+
41
+ self.model = cp_model.CpModel()
42
+ self.model_vars: dict[Pos, cp_model.IntVar] = {}
43
+
44
+ self.create_vars()
45
+ self.add_all_constraints()
46
+
47
+ def create_vars(self):
48
+ for pos in get_all_pos(self.V, self.H):
49
+ self.model_vars[pos] = self.model.NewBoolVar(f'{pos}')
50
+
51
+ def add_all_constraints(self):
52
+ visited: set[Pos] = set()
53
+ for cur_pos in self.tip:
54
+ visited.add(cur_pos)
55
+ while cur_pos is not None:
56
+ backward_pos = move_backward(cur_pos, self.board)
57
+ if backward_pos is None:
58
+ break
59
+ self.model.Add(self.model_vars[backward_pos] == 1).OnlyEnforceIf(self.model_vars[cur_pos])
60
+ cur_pos = backward_pos
61
+ visited.add(cur_pos)
62
+ assert len(visited) == self.V * self.H, f'all positions must be visited, got {len(visited)}. missing {set(get_all_pos(self.V, self.H)) - visited}'
63
+ for row in range(self.V):
64
+ self.model.Add(sum([self.model_vars[pos] for pos in get_row_pos(row, self.H)]) == self.side[row])
65
+ for col in range(self.H):
66
+ self.model.Add(sum([self.model_vars[pos] for pos in get_col_pos(col, self.V)]) == self.top[col])
67
+
68
+ def solve_and_print(self, verbose: bool = True):
69
+ def board_to_solution(board: Board, solver: cp_model.CpSolverSolutionCallback) -> SingleSolution:
70
+ assignment: dict[Pos, int] = {}
71
+ for pos, var in board.model_vars.items():
72
+ assignment[pos] = solver.value(var)
73
+ return SingleSolution(assignment=assignment)
74
+ def callback(single_res: SingleSolution):
75
+ print("Solution found")
76
+ res = np.full((self.V, self.H), ' ', dtype=object)
77
+ for pos in get_all_pos(self.V, self.H):
78
+ c = get_char(self.board, pos)
79
+ c = 'X' if single_res.assignment[pos] == 1 else ' '
80
+ set_char(res, pos, c)
81
+ print(res)
82
+ return generic_solve_all(self, board_to_solution, callback=callback if verbose else None, verbose=verbose)