puzzlekit 0.4.0__cp310-abi3-win_amd64.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.
Files changed (218) hide show
  1. puzzlekit/__init__.py +12 -0
  2. puzzlekit/_adapters/__init__.py +1 -0
  3. puzzlekit/_adapters/adapter.py +101 -0
  4. puzzlekit/_adapters/aquarium.py +76 -0
  5. puzzlekit/_adapters/balloon.py +79 -0
  6. puzzlekit/_adapters/bdwalk.py +43 -0
  7. puzzlekit/_adapters/bosanowa.py +57 -0
  8. puzzlekit/_adapters/castle.py +72 -0
  9. puzzlekit/_adapters/circlesquare.py +29 -0
  10. puzzlekit/_adapters/cluepartitions.py +39 -0
  11. puzzlekit/_adapters/codecs.py +188 -0
  12. puzzlekit/_adapters/compass.py +70 -0
  13. puzzlekit/_adapters/connection.py +49 -0
  14. puzzlekit/_adapters/coral.py +26 -0
  15. puzzlekit/_adapters/creek.py +60 -0
  16. puzzlekit/_adapters/cts.py +47 -0
  17. puzzlekit/_adapters/dbchoco.py +53 -0
  18. puzzlekit/_adapters/diagonal.py +84 -0
  19. puzzlekit/_adapters/doubleback.py +47 -0
  20. puzzlekit/_adapters/extended.py +198 -0
  21. puzzlekit/_adapters/geradeweg.py +42 -0
  22. puzzlekit/_adapters/grid.py +96 -0
  23. puzzlekit/_adapters/guidearrow.py +72 -0
  24. puzzlekit/_adapters/hashi.py +60 -0
  25. puzzlekit/_adapters/hebi.py +54 -0
  26. puzzlekit/_adapters/herugolf.py +66 -0
  27. puzzlekit/_adapters/isowatari.py +59 -0
  28. puzzlekit/_adapters/japanesesums.py +68 -0
  29. puzzlekit/_adapters/kakuro.py +70 -0
  30. puzzlekit/_adapters/keywest.py +58 -0
  31. puzzlekit/_adapters/kouchoku.py +55 -0
  32. puzzlekit/_adapters/kropki.py +38 -0
  33. puzzlekit/_adapters/longest.py +46 -0
  34. puzzlekit/_adapters/model.py +15 -0
  35. puzzlekit/_adapters/moonsun.py +32 -0
  36. puzzlekit/_adapters/nanameguri.py +52 -0
  37. puzzlekit/_adapters/narrow.py +24 -0
  38. puzzlekit/_adapters/ncells.py +42 -0
  39. puzzlekit/_adapters/nonogram.py +71 -0
  40. puzzlekit/_adapters/number10.py +40 -0
  41. puzzlekit/_adapters/number_regions.py +67 -0
  42. puzzlekit/_adapters/numcity.py +52 -0
  43. puzzlekit/_adapters/nurimaze.py +69 -0
  44. puzzlekit/_adapters/outside_numbers.py +92 -0
  45. puzzlekit/_adapters/packed.py +82 -0
  46. puzzlekit/_adapters/paintarea.py +63 -0
  47. puzzlekit/_adapters/partition.py +82 -0
  48. puzzlekit/_adapters/pencils.py +85 -0
  49. puzzlekit/_adapters/polyominous.py +111 -0
  50. puzzlekit/_adapters/regions.py +176 -0
  51. puzzlekit/_adapters/ringring.py +47 -0
  52. puzzlekit/_adapters/ripple.py +59 -0
  53. puzzlekit/_adapters/roomloops.py +54 -0
  54. puzzlekit/_adapters/roomnumbers.py +59 -0
  55. puzzlekit/_adapters/sashigane.py +57 -0
  56. puzzlekit/_adapters/sendai.py +35 -0
  57. puzzlekit/_adapters/shading.py +256 -0
  58. puzzlekit/_adapters/shugaku.py +72 -0
  59. puzzlekit/_adapters/simplegako.py +43 -0
  60. puzzlekit/_adapters/slashpack.py +46 -0
  61. puzzlekit/_adapters/soulmates.py +49 -0
  62. puzzlekit/_adapters/statuepark.py +49 -0
  63. puzzlekit/_adapters/sukoro.py +50 -0
  64. puzzlekit/_adapters/tapa.py +83 -0
  65. puzzlekit/_adapters/tents.py +61 -0
  66. puzzlekit/_adapters/walks.py +69 -0
  67. puzzlekit/_adapters/yajikazu.py +48 -0
  68. puzzlekit/_adapters/yajilin.py +159 -0
  69. puzzlekit/_adapters/yajisoko.py +40 -0
  70. puzzlekit/_cspuz.pyd +0 -0
  71. puzzlekit/api.py +45 -0
  72. puzzlekit/core/__init__.py +0 -0
  73. puzzlekit/core/result.py +60 -0
  74. puzzlekit/puzzles/__init__.py +1 -0
  75. puzzlekit/puzzles/akari.py +4 -0
  76. puzzlekit/puzzles/akichi.py +4 -0
  77. puzzlekit/puzzles/aqre.py +4 -0
  78. puzzlekit/puzzles/aquapelago.py +4 -0
  79. puzzlekit/puzzles/aquarium.py +4 -0
  80. puzzlekit/puzzles/araf.py +4 -0
  81. puzzlekit/puzzles/archipelago.py +4 -0
  82. puzzlekit/puzzles/ayeheya.py +4 -0
  83. puzzlekit/puzzles/balloon.py +4 -0
  84. puzzlekit/puzzles/barns.py +44 -0
  85. puzzlekit/puzzles/bdwalk.py +4 -0
  86. puzzlekit/puzzles/bosanowa.py +4 -0
  87. puzzlekit/puzzles/bramble.py +4 -0
  88. puzzlekit/puzzles/canal.py +4 -0
  89. puzzlekit/puzzles/castle.py +4 -0
  90. puzzlekit/puzzles/cave.py +4 -0
  91. puzzlekit/puzzles/cbanana.py +4 -0
  92. puzzlekit/puzzles/chainedb.py +4 -0
  93. puzzlekit/puzzles/chocona.py +4 -0
  94. puzzlekit/puzzles/circlesquare.py +4 -0
  95. puzzlekit/puzzles/cityspace.py +4 -0
  96. puzzlekit/puzzles/cocktail.py +4 -0
  97. puzzlekit/puzzles/coffeemilk.py +4 -0
  98. puzzlekit/puzzles/compass.py +4 -0
  99. puzzlekit/puzzles/context.py +4 -0
  100. puzzlekit/puzzles/coral.py +4 -0
  101. puzzlekit/puzzles/country.py +4 -0
  102. puzzlekit/puzzles/creek.py +4 -0
  103. puzzlekit/puzzles/cts.py +4 -0
  104. puzzlekit/puzzles/dbchoco.py +4 -0
  105. puzzlekit/puzzles/detour.py +37 -0
  106. puzzlekit/puzzles/disco.py +4 -0
  107. puzzlekit/puzzles/dominion.py +4 -0
  108. puzzlekit/puzzles/doppelblock.py +4 -0
  109. puzzlekit/puzzles/doubleback.py +4 -0
  110. puzzlekit/puzzles/easyasabc.py +4 -0
  111. puzzlekit/puzzles/energywalk.py +4 -0
  112. puzzlekit/puzzles/fillmat.py +4 -0
  113. puzzlekit/puzzles/fillomino.py +4 -0
  114. puzzlekit/puzzles/firefly.py +48 -0
  115. puzzlekit/puzzles/firewalk.py +4 -0
  116. puzzlekit/puzzles/fivecells.py +4 -0
  117. puzzlekit/puzzles/forestwalk.py +4 -0
  118. puzzlekit/puzzles/fourcells.py +4 -0
  119. puzzlekit/puzzles/geradeweg.py +4 -0
  120. puzzlekit/puzzles/gokigen.py +4 -0
  121. puzzlekit/puzzles/guidearrow.py +4 -0
  122. puzzlekit/puzzles/hashi.py +4 -0
  123. puzzlekit/puzzles/hebi.py +4 -0
  124. puzzlekit/puzzles/herugolf.py +4 -0
  125. puzzlekit/puzzles/heteromino.py +4 -0
  126. puzzlekit/puzzles/heyawake.py +4 -0
  127. puzzlekit/puzzles/hitori.py +4 -0
  128. puzzlekit/puzzles/icewalk.py +4 -0
  129. puzzlekit/puzzles/invlitso.py +4 -0
  130. puzzlekit/puzzles/isowatari.py +4 -0
  131. puzzlekit/puzzles/japanesesums.py +4 -0
  132. puzzlekit/puzzles/kakuro.py +4 -0
  133. puzzlekit/puzzles/keywest.py +4 -0
  134. puzzlekit/puzzles/koburin.py +39 -0
  135. puzzlekit/puzzles/kouchoku.py +4 -0
  136. puzzlekit/puzzles/kropki.py +4 -0
  137. puzzlekit/puzzles/kurarin.py +28 -0
  138. puzzlekit/puzzles/kuromasu.py +4 -0
  139. puzzlekit/puzzles/kurotto.py +4 -0
  140. puzzlekit/puzzles/lapaz.py +33 -0
  141. puzzlekit/puzzles/lightshadow.py +40 -0
  142. puzzlekit/puzzles/lither.py +24 -0
  143. puzzlekit/puzzles/lits.py +4 -0
  144. puzzlekit/puzzles/lohkous.py +52 -0
  145. puzzlekit/puzzles/longest.py +4 -0
  146. puzzlekit/puzzles/loopsp.py +60 -0
  147. puzzlekit/puzzles/masyu.py +4 -0
  148. puzzlekit/puzzles/mines.py +4 -0
  149. puzzlekit/puzzles/mintonette.py +4 -0
  150. puzzlekit/puzzles/moonsun.py +4 -0
  151. puzzlekit/puzzles/morningwalk.py +4 -0
  152. puzzlekit/puzzles/nagenawa.py +4 -0
  153. puzzlekit/puzzles/nanameguri.py +4 -0
  154. puzzlekit/puzzles/nanro.py +4 -0
  155. puzzlekit/puzzles/narrow.py +4 -0
  156. puzzlekit/puzzles/nikoji.py +4 -0
  157. puzzlekit/puzzles/nonogram.py +4 -0
  158. puzzlekit/puzzles/norinori.py +4 -0
  159. puzzlekit/puzzles/norinuri.py +4 -0
  160. puzzlekit/puzzles/nothing.py +23 -0
  161. puzzlekit/puzzles/nothree.py +52 -0
  162. puzzlekit/puzzles/numcity.py +4 -0
  163. puzzlekit/puzzles/nurikabe.py +4 -0
  164. puzzlekit/puzzles/nuriloop.py +32 -0
  165. puzzlekit/puzzles/nurimaze.py +4 -0
  166. puzzlekit/puzzles/nurimisaki.py +4 -0
  167. puzzlekit/puzzles/nuritwin.py +4 -0
  168. puzzlekit/puzzles/paintarea.py +4 -0
  169. puzzlekit/puzzles/pencils.py +4 -0
  170. puzzlekit/puzzles/pentominous.py +4 -0
  171. puzzlekit/puzzles/putteria.py +4 -0
  172. puzzlekit/puzzles/reflect.py +52 -0
  173. puzzlekit/puzzles/ringring.py +4 -0
  174. puzzlekit/puzzles/ripple.py +4 -0
  175. puzzlekit/puzzles/roma.py +4 -0
  176. puzzlekit/puzzles/sansaroad.py +4 -0
  177. puzzlekit/puzzles/sashigane.py +4 -0
  178. puzzlekit/puzzles/sendai.py +4 -0
  179. puzzlekit/puzzles/shakashaka.py +4 -0
  180. puzzlekit/puzzles/shikaku.py +4 -0
  181. puzzlekit/puzzles/shimaguni.py +4 -0
  182. puzzlekit/puzzles/shugaku.py +4 -0
  183. puzzlekit/puzzles/simplegako.py +4 -0
  184. puzzlekit/puzzles/simpleloop.py +4 -0
  185. puzzlekit/puzzles/skyscrapers.py +4 -0
  186. puzzlekit/puzzles/slashpack.py +4 -0
  187. puzzlekit/puzzles/slitherlink.py +4 -0
  188. puzzlekit/puzzles/smullyan.py +4 -0
  189. puzzlekit/puzzles/snake.py +51 -0
  190. puzzlekit/puzzles/soulmates.py +4 -0
  191. puzzlekit/puzzles/squarejam.py +4 -0
  192. puzzlekit/puzzles/starbattle.py +4 -0
  193. puzzlekit/puzzles/statuepark.py +4 -0
  194. puzzlekit/puzzles/stostone.py +4 -0
  195. puzzlekit/puzzles/sudoku.py +4 -0
  196. puzzlekit/puzzles/sukoro.py +4 -0
  197. puzzlekit/puzzles/tapa.py +4 -0
  198. puzzlekit/puzzles/tasquare.py +4 -0
  199. puzzlekit/puzzles/tents.py +4 -0
  200. puzzlekit/puzzles/tetrochain.py +32 -0
  201. puzzlekit/puzzles/tetrochaink.py +44 -0
  202. puzzlekit/puzzles/tetroctb.py +4 -0
  203. puzzlekit/puzzles/tetrominous.py +4 -0
  204. puzzlekit/puzzles/tilecity.py +4 -0
  205. puzzlekit/puzzles/tontonbeya.py +4 -0
  206. puzzlekit/puzzles/waterwalk.py +4 -0
  207. puzzlekit/puzzles/yajikazu.py +4 -0
  208. puzzlekit/puzzles/yajilin.py +4 -0
  209. puzzlekit/puzzles/yajilin_regions.py +46 -0
  210. puzzlekit/puzzles/yajisoko.py +4 -0
  211. puzzlekit/puzzles/yinyang.py +4 -0
  212. puzzlekit/registry.py +154 -0
  213. puzzlekit-0.4.0.dist-info/METADATA +211 -0
  214. puzzlekit-0.4.0.dist-info/RECORD +218 -0
  215. puzzlekit-0.4.0.dist-info/WHEEL +5 -0
  216. puzzlekit-0.4.0.dist-info/licenses/LICENSE +21 -0
  217. puzzlekit-0.4.0.dist-info/licenses/LICENSE-cspuz +76 -0
  218. puzzlekit-0.4.0.dist-info/top_level.txt +1 -0
puzzlekit/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ """Solve puzzle URLs with cspuz and export verified pzpr states."""
2
+ from importlib.metadata import PackageNotFoundError, version
3
+
4
+ from puzzlekit.api import solve, solve_url, supported_puzzles
5
+ from puzzlekit.core.result import PuzzleResult
6
+
7
+ __all__ = ['solve', 'solve_url', 'supported_puzzles', 'PuzzleResult']
8
+
9
+ try:
10
+ __version__ = version('puzzlekit')
11
+ except PackageNotFoundError:
12
+ __version__ = '0+unknown'
@@ -0,0 +1 @@
1
+ """Shared internal URL and FileIO adapter implementations."""
@@ -0,0 +1,101 @@
1
+ """Connect a puzzle's registered identity to its shared adapter."""
2
+ from dataclasses import dataclass
3
+
4
+ from . import balloon, bdwalk, bosanowa, castle, compass, cts, guidearrow, coral, aquarium, yajikazu, creek, simplegako, circlesquare, cluepartitions, connection, dbchoco, diagonal, doubleback, extended, geradeweg, hashi, hebi, herugolf, isowatari, japanesesums, keywest, moonsun, nanameguri, narrow, ncells, nonogram, nurimaze, packed, paintarea, partition, regions, ripple, ringring, roomloops, roomnumbers, sashigane, sendai, shading, shugaku, slashpack, soulmates, statuepark, sukoro, tapa, tents, yajilin, yajisoko
5
+ from . import kouchoku, longest, numcity, pencils
6
+
7
+ _DIRECT_FAMILIES = {
8
+ 'longest': longest,
9
+ 'kouchoku': kouchoku,
10
+ 'pencils': pencils,
11
+ 'numcity': numcity,
12
+ 'nurimaze': nurimaze,
13
+ 'connection': connection,
14
+ 'slashpack': slashpack,
15
+ 'soulmates': soulmates,
16
+ 'herugolf': herugolf,
17
+ 'castle': castle,
18
+ 'narrow': narrow,
19
+ 'sendai': sendai,
20
+ 'hebi': hebi,
21
+ 'bdwalk': bdwalk,
22
+ 'bosanowa': bosanowa,
23
+ 'isowatari': isowatari,
24
+ 'statuepark': statuepark,
25
+ 'nanameguri': nanameguri,
26
+ 'japanesesums': japanesesums,
27
+ 'keywest': keywest,
28
+ 'compass': compass,
29
+ 'tents': tents,
30
+ 'shugaku': shugaku,
31
+ 'yajisoko': yajisoko,
32
+ 'balloon': balloon,
33
+ 'cts': cts,
34
+ 'guidearrow': guidearrow,
35
+ 'coral': coral,
36
+ 'aquarium': aquarium,
37
+ 'yajikazu': yajikazu,
38
+ 'creek': creek,
39
+ 'simplegako': simplegako,
40
+ 'circlesquare': circlesquare,
41
+ 'cluepartitions': cluepartitions,
42
+ 'dbchoco': dbchoco,
43
+ 'ringring': ringring,
44
+ 'sashigane': sashigane,
45
+ 'sukoro': sukoro,
46
+ 'diagonal': diagonal,
47
+ 'doubleback': doubleback,
48
+ 'moonsun': moonsun,
49
+ 'hashi': hashi,
50
+ 'nonogram': nonogram,
51
+ 'ncells': ncells,
52
+ 'paintarea': paintarea,
53
+ 'geradeweg': geradeweg,
54
+ 'roomloops': roomloops,
55
+ 'roomnumbers': roomnumbers,
56
+ 'ripple': ripple,
57
+ 'packed': packed,
58
+ 'partition': partition,
59
+ 'tapa': tapa,
60
+ }
61
+
62
+
63
+ @dataclass(frozen=True)
64
+ class Adapter:
65
+ name: str
66
+ aliases: tuple[str, ...]
67
+ family: str
68
+
69
+ def parse(self, source):
70
+ if self.family == 'shading':
71
+ puzzle = shading.decode_shading(source)
72
+ shading.check_backend_clues(puzzle)
73
+ url = shading.encode_shading(puzzle)
74
+ elif self.family == 'extended':
75
+ puzzle = extended.decode_extended(source)
76
+ if puzzle.puzzle_type == 'shikaku':
77
+ shading.check_backend_clues(puzzle)
78
+ extended.check_backend_rules(puzzle)
79
+ url = extended.encode_extended(puzzle)
80
+ elif self.family == 'regions':
81
+ puzzle = regions.decode_regions(source)
82
+ regions.check_backend_clues(puzzle)
83
+ url = regions.encode_regions(puzzle)
84
+ elif self.family in _DIRECT_FAMILIES:
85
+ module = _DIRECT_FAMILIES[self.family]
86
+ puzzle = module.decode(source)
87
+ url = module.encode(puzzle)
88
+ else:
89
+ puzzle = yajilin.decode(source)
90
+ yajilin.check_backend_rules(puzzle)
91
+ url = yajilin.encode(puzzle)
92
+ backend_url = (extended.backend_url(url) if self.family == 'extended' else
93
+ hashi.backend_url(url) if self.family == 'hashi' else url)
94
+ return puzzle, url, backend_url
95
+
96
+ def fileio(self, puzzle, board, status):
97
+ module = {
98
+ 'shading': shading, 'extended': extended, 'regions': regions,
99
+ 'yajilin': yajilin, **_DIRECT_FAMILIES,
100
+ }[self.family]
101
+ return module.fileio(puzzle, module.answer(puzzle, board, status))
@@ -0,0 +1,76 @@
1
+ """Aquarium room borders, outside clues, and water marks."""
2
+ from puzzlekit._adapters.codecs import BorderCodec
3
+ from puzzlekit._adapters.model import Puzzle
4
+ from puzzlekit._adapters.shading import puzzle_path
5
+
6
+
7
+ def decode(source):
8
+ parts = puzzle_path(source).split('/')
9
+ flag = len(parts) == 6 and parts[1] == 'r'
10
+ if flag:
11
+ parts.pop(1)
12
+ if len(parts) != 5 or parts[0] != 'aquarium' or not parts[1].isdigit() or not parts[2].isdigit():
13
+ raise ValueError('invalid Aquarium path or rule flag')
14
+ w, h = int(parts[1]), int(parts[2])
15
+ if w < 2 or h < 2:
16
+ raise ValueError('cspuz Aquarium requires at least two rows and columns')
17
+ border_text, body = parts[3:]
18
+ length = (h * (w - 1) + 4) // 5 + ((h - 1) * w + 4) // 5
19
+ if len(border_text) != length or any(c not in '0123456789abcdefghijklmnopqrstuv' for c in border_text):
20
+ raise ValueError('invalid Aquarium borders')
21
+ borders, _ = BorderCodec().decode(border_text, h, w)
22
+ values, pos, i = {}, 0, 0
23
+ while i < len(body):
24
+ ch = body[i]
25
+ if 'g' <= ch <= 'z':
26
+ pos += ord(ch) - ord('g') + 1
27
+ i += 1
28
+ else:
29
+ n = 2 if ch == '-' else 0
30
+ digits = body[i + 1:i + 1 + n] if n else ch
31
+ if len(digits) != (n or 1) or any(c not in '0123456789abcdef' for c in digits):
32
+ raise ValueError('invalid Aquarium outside clue')
33
+ if pos >= w + h:
34
+ raise ValueError('too many Aquarium outside clues')
35
+ values[pos] = int(digits, 16)
36
+ pos += 1
37
+ i += n + 1
38
+ if pos > w + h:
39
+ raise ValueError('too many Aquarium outside clues')
40
+ if pos != w + h:
41
+ raise ValueError('incomplete Aquarium outside clues')
42
+ if not any(n > 0 for n in values.values()):
43
+ raise ValueError('Aquarium needs a positive outside clue to exclude empty water')
44
+ return Puzzle('aquarium', h, w, values, borders, rule_flag='r' if flag else '', body=body)
45
+
46
+
47
+ def encode(p):
48
+ flag = 'r/' if p.rule_flag == 'r' else ''
49
+ borders = BorderCodec().encode(p.borders, p.rows, p.cols)
50
+ return f'https://puzz.link/p?aquarium/{flag}{p.cols}/{p.rows}/{borders}/{p.body}'
51
+
52
+
53
+ def answer(p, board, status):
54
+ result = [[None] * p.cols for _ in range(p.rows)]
55
+ if status != 'no_solution':
56
+ for item in board['data']:
57
+ if item['color'] != 'green': continue
58
+ y, x, kind = item['y'], item['x'], item['item']
59
+ if kind not in ('fill', 'dot') or y % 2 != 1 or x % 2 != 1 or not (3 <= y < 2*p.rows+3 and 3 <= x < 2*p.cols+3):
60
+ raise RuntimeError('invalid Aquarium answer')
61
+ result[(y - 3)//2][(x - 3)//2] = '#' if kind == 'fill' else '+'
62
+ return result
63
+
64
+
65
+ def fileio(p, answers):
66
+ def row(values): return ' '.join(str(x) for x in values) + ' \n'
67
+ h, w = p.rows, p.cols
68
+ out = [f'pzprv3\naquarium\n{h}\n{w}\n']
69
+ if p.rule_flag == 'r': out.append('r\n')
70
+ out.extend(row([int(r * (w - 1) + c in p.borders) for c in range(w - 1)]) for r in range(h))
71
+ n = h * (w - 1)
72
+ out.extend(row([int(n + r * w + c in p.borders) for c in range(w)]) for r in range(h - 1))
73
+ out.append(row(['.'] + [p.cells.get(c, '.') for c in range(w)]))
74
+ for r in range(h):
75
+ out.append(row([p.cells.get(w+r, '.')] + [x or '.' for x in answers[r]]))
76
+ return ''.join(out)
@@ -0,0 +1,79 @@
1
+ """Balloon Box room partitions and connecting lines."""
2
+ from puzzlekit._adapters import shading
3
+ from puzzlekit._adapters.model import Puzzle
4
+
5
+
6
+ def decode(source):
7
+ parts = shading.puzzle_path(source).split('/')
8
+ if len(parts) > 4 and parts[-1] == '' and parts[-2].endswith('.'):
9
+ parts.pop()
10
+ flag = len(parts) == 5 and parts[1] == 'a'
11
+ if flag:
12
+ parts.pop(1)
13
+ if len(parts) != 4 or parts[0] != 'balloon' or not all(v.isdigit() for v in parts[1:3]):
14
+ raise ValueError('invalid Balloon Box path')
15
+ w, h = map(int, parts[1:3])
16
+ if min(w, h) < 2:
17
+ raise ValueError('cspuz Balloon Box requires at least two rows and columns')
18
+ body = parts[3]
19
+ count = (h*w + 4) // 5
20
+ bits = body[:count]
21
+ if len(bits) != count or any(c not in '0123456789abcdefghijklmnopqrstuv' for c in bits):
22
+ raise ValueError('invalid Balloon Box region cells')
23
+ values = [bool(int(c, 32) & (1 << (4-j))) for c in bits for j in range(5)]
24
+ if any(values[h*w:]):
25
+ raise ValueError('region cells exceed grid')
26
+ holes = {divmod(i, w): True for i, v in enumerate(values[:h*w]) if v}
27
+ cells = shading.decode_shading(f'nurikabe/{w}/{h}/{body[count:]}').cells
28
+ if not cells or any(isinstance(v, int) and v >= 4096 for v in cells.values()):
29
+ raise ValueError('Balloon Box requires clues below 4096 or ?')
30
+ if any(k in holes for k in cells):
31
+ raise ValueError('number clues cannot overlap region cells')
32
+ return Puzzle('balloon', h, w, cells=cells, holes=holes, body=body, rule_flag='a' if flag else '')
33
+
34
+
35
+ def encode(p):
36
+ flag = 'a/' if p.rule_flag else ''
37
+ return f'https://puzz.link/p?balloon/{flag}{p.cols}/{p.rows}/{p.body}' + ('/' if p.body.endswith('.') else '')
38
+
39
+
40
+ def answer(p, board, status):
41
+ vertical = [[[0, 0] for _ in range(p.cols-1)] for _ in range(p.rows)]
42
+ horizontal = [[[0, 0] for _ in range(p.cols)] for _ in range(p.rows-1)]
43
+ if status != 'no_solution':
44
+ for item in board['data']:
45
+ if item['color'] != 'green':
46
+ continue
47
+ y, x, kind = item['y'], item['x'], item['item']
48
+ if y % 2 == 1 and x % 2 == 0:
49
+ r, c, target = y//2, x//2-1, vertical
50
+ a, b = (r,c), (r,c+1)
51
+ elif y % 2 == 0 and x % 2 == 1:
52
+ r, c, target = y//2-1, x//2, horizontal
53
+ a, b = (r,c), (r+1,c)
54
+ else:
55
+ raise RuntimeError('invalid Balloon Box answer coordinate')
56
+ if kind == 'boldWall':
57
+ target[r][c][0] = 1
58
+ elif kind == 'line':
59
+ target[r][c][1] = 1
60
+ elif kind == 'cross':
61
+ if a in p.holes and b in p.holes:
62
+ target[r][c][0] = -1
63
+ else:
64
+ target[r][c][1] = -1
65
+ else:
66
+ raise RuntimeError('invalid Balloon Box answer')
67
+ return vertical, horizontal
68
+
69
+
70
+ def fileio(p, ans):
71
+ def row(values): return ' '.join(str(v) for v in values) + ' \n'
72
+ out = [f'pzprv3\nballoon\n{p.rows}\n{p.cols}\n']
73
+ if p.rule_flag:
74
+ out.append('a\n')
75
+ out.extend(row(['#' if (r,c) in p.holes else '-' if p.cells.get((r,c)) == '?' else p.cells.get((r,c), '.') for c in range(p.cols)]) for r in range(p.rows))
76
+ for i in (0, 1):
77
+ for lines in ans:
78
+ out.extend(row([v[i] for v in line]) for line in lines)
79
+ return ''.join(out)
@@ -0,0 +1,43 @@
1
+ """Building Walk start/goal, floor clues, and path."""
2
+ from puzzlekit._adapters import packed, shading
3
+ from puzzlekit._adapters.model import Puzzle
4
+
5
+
6
+ def decode(source):
7
+ parts = shading.puzzle_path(source).split('/')
8
+ if len(parts) == 6 and parts[-1] == '' and parts[-2].endswith('.'):
9
+ parts.pop()
10
+ if len(parts) != 5 or parts[:2] != ['bdwalk', 'm'] or not all(v.isdigit() for v in parts[2:4]):
11
+ raise ValueError('cspuz Building Walk requires the m rule variant')
12
+ w, h = map(int, parts[2:4])
13
+ body = parts[4]
14
+ if min(w, h) < 2 or len(body) < 4 or any(ch not in '123456789abcdef' for ch in body[:4]):
15
+ raise ValueError('invalid Building Walk dimensions or endpoints')
16
+ x1, y1, x2, y2 = (int(ch, 16) for ch in body[:4])
17
+ if not (x1 <= w and x2 <= w and y1 <= h and y2 <= h) or (x1, y1) == (x2, y2):
18
+ raise ValueError('invalid Building Walk endpoints')
19
+ cells = shading.decode_shading(f'nurikabe/{w}/{h}/{body[4:]}').cells
20
+ if any(isinstance(v, int) and v >= 4096 for v in cells.values()):
21
+ raise ValueError('Building Walk clues must be below 4095')
22
+ cells = {k: 'U' if v == 0 else 'D' if v == 1 else '-' if v == '?' else v - 1 for k, v in cells.items()}
23
+ if not any(isinstance(v, int) for v in cells.values()):
24
+ raise ValueError('Building Walk requires a numbered floor')
25
+ return Puzzle('bdwalk', h, w, cells=cells, body=body, holes={'start': (x1, y1), 'goal': (x2, y2)})
26
+
27
+
28
+ def encode(p):
29
+ return f'https://puzz.link/p?bdwalk/m/{p.cols}/{p.rows}/{p.body}' + ('/' if p.body.endswith('.') else '')
30
+
31
+
32
+ answer = packed.answer
33
+
34
+
35
+ def fileio(p, ans):
36
+ def row(values): return ' '.join(str(v) for v in values) + ' \n'
37
+ x1, y1 = p.holes['start']
38
+ x2, y2 = p.holes['goal']
39
+ out = [f'pzprv3\nbdwalk\n{p.rows}\n{p.cols}\nm\n{2*x1-1} {2*y1-1} {2*x2-1} {2*y2-1}\n']
40
+ out.extend(row([p.cells.get((r, c), '.') for c in range(p.cols)]) for r in range(p.rows))
41
+ for lines in ans:
42
+ out.extend(row([1 if v is True else -1 if v is False else 0 for v in line]) for line in lines)
43
+ return ''.join(out)
@@ -0,0 +1,57 @@
1
+ """Bosanowa playable cells, number clues, and answers."""
2
+ from puzzlekit._adapters import shading
3
+ from puzzlekit._adapters.model import Puzzle
4
+
5
+
6
+ def decode(source):
7
+ parts = shading.puzzle_path(source).split('/')
8
+ if len(parts) != 4 or parts[0] != 'bosanowa' or not all(v.isdigit() for v in parts[1:3]):
9
+ raise ValueError('invalid Bosanowa path')
10
+ w, h = map(int, parts[1:3])
11
+ if min(w, h) < 2:
12
+ raise ValueError('cspuz Bosanowa requires at least two rows and columns')
13
+ body = parts[3]
14
+ count = (h * w + 4) // 5
15
+ bits = body[:count]
16
+ if len(bits) != count or any(c not in '0123456789abcdefghijklmnopqrstuv' for c in bits):
17
+ raise ValueError('invalid Bosanowa board')
18
+ blocked = [bool(int(c, 32) & (1 << (4 - j))) for c in bits for j in range(5)]
19
+ if any(blocked[h * w:]):
20
+ raise ValueError('Bosanowa board exceeds grid')
21
+ cells = shading.decode_shading(f'nurikabe/{w}/{h}/{body[count:]}').cells
22
+ if not cells or any(v == '?' or v == 0 or v >= 4096 for v in cells.values()):
23
+ raise ValueError('Bosanowa requires positive clues below 4096')
24
+ if any(blocked[r * w + c] for r, c in cells):
25
+ raise ValueError('Bosanowa clues must be on playable cells')
26
+ return Puzzle('bosanowa', h, w, cells=cells, body=body,
27
+ holes={divmod(i, w): True for i, v in enumerate(blocked[:h * w]) if v})
28
+
29
+
30
+ def encode(p):
31
+ return f'https://puzz.link/p?bosanowa/{p.cols}/{p.rows}/{p.body}'
32
+
33
+
34
+ def answer(p, board, status):
35
+ result = [[None] * p.cols for _ in range(p.rows)]
36
+ if status != 'no_solution':
37
+ for item in board['data']:
38
+ if item['color'] != 'green':
39
+ continue
40
+ y, x, kind = item['y'], item['x'], item['item']
41
+ if y % 2 != 1 or x % 2 != 1 or not (0 <= y // 2 < p.rows and 0 <= x // 2 < p.cols):
42
+ raise RuntimeError('invalid Bosanowa answer coordinate')
43
+ if not isinstance(kind, dict) or kind.get('kind') != 'text' or not kind.get('data', '').isdigit():
44
+ raise RuntimeError('invalid Bosanowa answer')
45
+ result[y // 2][x // 2] = kind['data']
46
+ return result
47
+
48
+
49
+ def fileio(p, answers):
50
+ def row(values): return ' '.join(str(v) for v in values) + ' \n'
51
+ h, w = p.rows, p.cols
52
+ out = [f'pzprv3\nbosanowa\n{h}\n{w}\n']
53
+ out.extend(row(['.' if (r, c) in p.holes else p.cells.get((r, c), '0') for c in range(w)]) for r in range(h))
54
+ out.extend(row(['.' if (r, c) in p.holes or (r, c) in p.cells else answers[r][c] or '0' for c in range(w)]) for r in range(h))
55
+ out.extend(row(['.'] * (w - 1)) for _ in range(h))
56
+ out.extend(row(['.'] * w) for _ in range(h - 1))
57
+ return ''.join(out)
@@ -0,0 +1,72 @@
1
+ """Castle Wall colored arrow clues and loop edges."""
2
+ from puzzlekit._adapters import packed, shading
3
+ from puzzlekit._adapters.model import Puzzle
4
+
5
+
6
+ def decode(source):
7
+ parts = shading.puzzle_path(source).split('/')
8
+ if len(parts) == 5 and parts[-1] == '' and parts[-2].endswith('.'):
9
+ parts.pop()
10
+ if len(parts) != 4 or parts[0] != 'castle' or not all(v.isdigit() for v in parts[1:3]):
11
+ raise ValueError('invalid Castle Wall path')
12
+ w, h = map(int, parts[1:3])
13
+ if min(w, h) < 2:
14
+ raise ValueError('cspuz Castle Wall requires at least two rows and columns')
15
+ body, cells, i, pos = parts[3], {}, 0, 0
16
+ while i < len(body):
17
+ ch = body[i]
18
+ if 'a' <= ch <= 'z':
19
+ pos += ord(ch) - ord('a') + 1
20
+ i += 1
21
+ continue
22
+ if ch not in '012' or pos >= w * h or i + 2 >= len(body):
23
+ raise ValueError('invalid Castle Wall clue')
24
+ side = int(ch)
25
+ digit = body[i + 1]
26
+ if digit not in '0123456789':
27
+ raise ValueError('invalid Castle Wall arrow')
28
+ d = int(digit)
29
+ length = 1 if d < 5 else 2
30
+ digits = body[i + 2:i + 2 + length]
31
+ if digits == '.' and length == 1:
32
+ value = '?'
33
+ elif len(digits) == length and all(x in '0123456789abcdef' for x in digits):
34
+ value = int(digits, 16)
35
+ else:
36
+ raise ValueError('invalid Castle Wall arrow number')
37
+ if d % 5 == 0 and value != '?':
38
+ raise ValueError('numbered Castle Wall clues require an arrow')
39
+ cells[divmod(pos, w)] = (side, d % 5, value)
40
+ pos += 1
41
+ i += 2 + length
42
+ if pos > h * w:
43
+ raise ValueError('clues exceed grid')
44
+ if not any(side == 1 or direction and isinstance(value, int) and value > 0
45
+ for side, direction, value in cells.values()):
46
+ raise ValueError('Castle Wall requires an inside clue or positive arrow to exclude an empty loop')
47
+ return Puzzle('castle', h, w, cells=cells, body=body)
48
+
49
+
50
+ def encode(p):
51
+ return f'https://puzz.link/p?castle/{p.cols}/{p.rows}/{p.body}' + ('/' if p.body.endswith('.') else '')
52
+
53
+
54
+ answer = packed.answer
55
+
56
+
57
+ def fileio(p, ans):
58
+ def row(values): return ' '.join(str(v) for v in values) + ' \n'
59
+ out = [f'pzprv3\ncastle\n{p.rows}\n{p.cols}\n']
60
+ for r in range(p.rows):
61
+ line = []
62
+ for c in range(p.cols):
63
+ clue = p.cells.get((r, c))
64
+ if clue is None:
65
+ line.append('0,-1,0')
66
+ else:
67
+ side, direction, value = clue
68
+ line.append(f'{direction},{"-" if value == "?" else value},{side}')
69
+ out.append(row(line))
70
+ for lines in ans:
71
+ out.extend(row([1 if v is True else -1 if v is False else 0 for v in line]) for line in lines)
72
+ return ''.join(out)
@@ -0,0 +1,29 @@
1
+ """Circles and Squares color clues and shading marks."""
2
+ from puzzlekit._adapters import packed, shading
3
+
4
+
5
+ def decode(source):
6
+ parts = shading.puzzle_path(source).split('/')
7
+ if len(parts) != 4 or parts[0] != 'circlesquare':
8
+ raise ValueError('invalid Circles and Squares path')
9
+ p = packed.decode('/'.join(['yinyang', *parts[1:]]))
10
+ p.puzzle_type = 'circlesquare'
11
+ if 2 not in p.cells.values() and p.rows == p.cols:
12
+ raise ValueError('cspuz may count an all-white answer')
13
+ return p
14
+
15
+
16
+ def encode(p):
17
+ return f'https://puzz.link/p?circlesquare/{p.cols}/{p.rows}/{p.body}'
18
+
19
+
20
+ def answer(p, board, status):
21
+ result = shading.answer(p, board, status)
22
+ if status != 'no_solution':
23
+ for (r, c), clue in p.cells.items():
24
+ result[r][c] = 'white' if clue == 1 else 'black'
25
+ return result
26
+
27
+
28
+ def fileio(p, ans):
29
+ return shading.fileio(p, ans)
@@ -0,0 +1,39 @@
1
+ """Number-clued partition puzzles using shared pzpr border marks."""
2
+ from puzzlekit._adapters import number10, partition, shading
3
+ from puzzlekit._adapters.model import Puzzle
4
+
5
+ TOKENS = {str(i): i for i in range(1, 5)} | {'.': '?'}
6
+
7
+
8
+ def decode(source):
9
+ parts = shading.puzzle_path(source).split('/')
10
+ if len(parts) == 5 and parts[-1] == '' and parts[-2].endswith('.'):
11
+ parts.pop()
12
+ if len(parts) != 4 or parts[0] not in {'fillmat', 'nikoji'} or not parts[1].isdigit() or not parts[2].isdigit():
13
+ raise ValueError('invalid partition puzzle path')
14
+ pid, w, h, body = parts[0], int(parts[1]), int(parts[2]), parts[3]
15
+ if w < 2 or h < 2:
16
+ raise ValueError('cspuz requires at least two rows and columns')
17
+ if pid == 'fillmat':
18
+ cells = number10.decode(body, h, w, TOKENS)
19
+ else:
20
+ cells = shading.decode_shading(f'nurikabe/{w}/{h}/{body}').cells
21
+ if not cells or any(v == '?' or v == 0 or v >= 4096 for v in cells.values()):
22
+ raise ValueError('cspuz NIKOJI requires positive clues up to 4095')
23
+ return Puzzle(pid, h, w, cells)
24
+
25
+
26
+ def encode(p):
27
+ if p.puzzle_type == 'fillmat':
28
+ body = number10.encode(p.cells, p.rows, p.cols, {v: k for k, v in TOKENS.items()})
29
+ else:
30
+ body = shading.encode_shading(Puzzle('nurikabe', p.rows, p.cols, p.cells)).split('?', 1)[1].split('/', 3)[3].rstrip('/')
31
+ return f'https://puzz.link/p?{p.puzzle_type}/{p.cols}/{p.rows}/{body}' + ('/' if body.endswith('.') else '')
32
+
33
+
34
+ def answer(p, board, status):
35
+ return partition.answer(p, board, status)
36
+
37
+
38
+ def fileio(p, ans):
39
+ return partition.fileio(p, ans)