forked from semiexp/cspuz_core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
305 lines (273 loc) · 13.3 KB
/
Copy pathmod.rs
File metadata and controls
305 lines (273 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
use crate::board::Board;
macro_rules! dispatch_enumerate {
( $mod:ident, $aliases:expr, $puzzle_kind:expr, $url:expr, $num_max_answers:expr ) => {};
( $mod:ident, $aliases:expr, $puzzle_kind:expr, $url:expr, $num_max_answers:expr, $enumerate:ident ) => {
for alias in $aliases {
if $puzzle_kind == alias {
return Some(super::$mod::enumerate($url, $num_max_answers));
}
}
};
}
macro_rules! dispatch_enumerate_list {
( $ret:expr, $en_name:expr, $ja_name:expr ) => {};
( $ret:expr, $en_name:expr, $ja_name:expr, $enumerable:ident) => {
$ret.push((String::from($en_name), String::from($ja_name)));
};
}
macro_rules! puzzle_list {
( $mod_name:ident, $( ($mod:ident, $aliases: expr, $en_name:expr, $ja_name:expr $(, $enumerable:ident )? ) ),* $(,)? ) => {
$(
pub mod $mod;
)*
mod $mod_name {
pub fn dispatch(puzzle_kind: &str, url: &str) -> Option<Result<super::Board, &'static str>> {
$(
for alias in $aliases {
if puzzle_kind == alias {
return Some(super::$mod::solve(url));
}
}
)*
None
}
#[allow(unused)]
pub fn dispatch_enumerate(
#[allow(unused)]
puzzle_kind: &str,
#[allow(unused)]
url: &str,
#[allow(unused)]
num_max_answers: usize,
) -> Option<Result<(super::Board, Vec<super::Board>), &'static str>> {
$(
dispatch_enumerate!($mod, $aliases, puzzle_kind, url, num_max_answers $(, $enumerable)?);
)*
None
}
pub fn list_puzzles() -> Vec<(String, String)> {
vec![
$(
(String::from($en_name), String::from($ja_name)),
)*
]
}
#[allow(unused)]
pub fn list_puzzles_with_key() -> Vec<(String, String, String)> {
vec![
$(
(String::from($aliases[0]), String::from($en_name), String::from($ja_name)),
)*
]
}
#[allow(unused)]
pub fn list_puzzles_enumerate() -> Vec<(String, String)> {
let mut ret = vec![];
$(
dispatch_enumerate_list!(ret, $en_name, $ja_name $(, $enumerable)?);
)*
ret
}
}
};
}
pub mod heyawake_internal;
#[rustfmt::skip]
puzzle_list!(puzz_link,
(akari, ["akari"], "Akari", "美術館"),
(akichiwake, ["akichi"], "Akichiwake", "Akichiwake"),
(aqre, ["aqre"], "Aqre", "Aqre"),
(aquapelago, ["aquapelago"], "Aquapelago", "Aquapelago"),
(aquarium, ["aquarium"], "Aquarium", "アクアプレース"),
(araf, ["araf"], "Araf", "相ダ部屋"),
(archipelago, ["archipelago"], "Archipelago", "Archipelago"),
(ayeheya, ["ayeheya"], "Ekawayeh (Symmetry Heyawake)", "∀人∃HEYA"),
(balloon, ["balloon"], "Balloon Box (Revised)", "風船箱 (改訂版)"),
(barns, ["barns"], "Barns", "バーンズ"),
(battleship, ["battleship"], "Battleship", "Battleship"),
(bdwalk, ["bdwalk"], "Building Walk", "ビルウォーク"),
(bosanowa, ["bosanowa"], "Bosanowa", "ボサノワ"),
(canalview, ["canal"], "Canal View", "Canal View"),
(castle_wall, ["castle"], "Castle Wall", "Castle Wall"),
(cave, ["cave"], "Cave", "バッグ"),
(chainedb, ["chainedb"], "Chained Block", "チェンブロ"),
(chocobanana, ["cbanana"], "Choco Banana", "チョコバナナ"),
(chocona, ["chocona"], "Chocona", "チョコナ"),
(circlesquare, ["circlesquare"], "Circles and Squares", "Circles and Squares"),
(city_space, ["cityspace"], "City Space", "City Space"),
(cocktail, ["cocktail"], "Cocktail Lamp", "カクテルランプ"),
(coffeemilk, ["coffeemilk"], "Coffee Milk", "コーヒー牛乳"),
(compass, ["compass"], "Compass", "Compass"),
(coral, ["coral"], "Coral", "Coral"),
(country_road, ["country"], "Country Road", "カントリーロード"),
(creek, ["creek"], "Creek", "クリーク"),
(cross_the_streams, ["cts"], "Cross the Streams", "Cross the Streams"),
(curvedata, ["curvedata"], "Curve Data", "カーブデータ", enumerable),
(dbchoco, ["dbchoco"], "Double Choco", "ダブルチョコ"),
(dominion, ["dominion"], "Dominion", "ドミニオン"),
(doppelblock, ["doppelblock"], "Doppelblock", "ビトゥイーン・サム"),
(energywalk, ["energywalk"], "Energy Walk", "Energy Walk"),
(evolmino, ["evolmino"], "Evolmino", "シンカミノ"),
(fillomino, ["fillomino"], "Fillomino", "フィルオミノ"),
(firefly, ["firefly"], "Firefly", "ホタルビーム"),
(firewalk, ["firewalk"], "Firewalk", "ファイアウォーク"),
(fivecells, ["fivecells"], "Fivecells", "ファイブセルズ"),
(forestwalk, ["forestwalk"], "Forest Walk", "フォレストウォーク"),
(fourcells, ["fourcells"], "Fourcells", "フォーセルズ"),
(geradeweg, ["geradeweg"], "Geradeweg", "グラーデヴェグ"),
(guidearrow, ["guidearrow"], "Guide Arrow", "ガイドアロー"),
(hashi, ["hashi"], "Hashiwokakero", "橋をかけろ"),
(hebiichigo, ["hebi"], "Hebi-Ichigo", "へびいちご"),
(herugolf, ["herugolf"], "Herugolf", "ヘルゴルフ"),
(heteromino, ["heteromino"], "Heteromino", "ヘテロミノ"),
(heyawake, ["heyawake"], "Heyawake", "へやわけ", enumerable),
(hitori, ["hitori"], "Hitori", "ひとりにしてくれ"),
(icewalk, ["icewalk"], "Ice Walk", "アイスウォーク"),
(inverse_litso, ["invlitso"], "Inverse LITSO", "Inverse LITSO"),
(japanese_sums, ["japanesesums"], "Japanese Sums", "Japanese Sums"),
(kakuro, ["kakuro"], "Kakuro", "カックロ"),
(keywest, ["keywest"], "Key West", "キーウエスト"),
(koburin, ["koburin"], "Koburin", "コブリン"),
(kouchoku, ["kouchoku"], "Kouchoku", "交差は直交に限る"),
(kropki, ["kropki"], "Kropki", "Kropki"),
(kurarin, ["kurarin"], "Kurarin", "クラリン"),
(kurodoko, ["kurodoko"], "Kurodoko", "黒どこ"),
(kurotto, ["kurotto"], "Kurotto", "クロット"),
(lapaz, ["lapaz"], "La Paz", "La Paz"),
(litherslink, ["lither"], "Litherslink", "Litherslink"),
(lits, ["lits"], "LITS", "LITS"),
(lohkous, ["lohkous"], "Lohkous", "Lohkous"),
(loop_special, ["loopsp"], "Loop Special", "環状線スペシャル"),
(masyu, ["masyu", "mashu"], "Masyu", "ましゅ"),
(minesweeper, ["mines"], "Minesweeper", "マインスイーパ"),
(moonsun, ["moonsun"], "Moon or Sun", "月か太陽"),
(morningwalk, ["morningwalk"], "Morning Walk", "Morning Walk"),
(nagenawa, ["nagenawa"], "Nagenawa", "なげなわ"),
(nanro, ["nanro"], "Nanro", "ナンロー"),
(nikoji, ["nikoji"], "NIKOJI", "NIKOJI"),
(nonogram, ["nonogram"], "Nonogram", "お絵かきロジック"),
(norinori, ["norinori"], "Norinori", "のりのり"),
(norinuri, ["norinuri"], "Norinori", "海苔ぬり"),
(nothing, ["nothing"], "All or Nothing", "オールorナッシング"),
(nothree, ["nothree"], "No Three", "ノースリー"),
(numcity, ["numcity"], "Number City", "ナンバーシティー"),
(nurikabe, ["nurikabe"], "Nurikabe", "ぬりかべ", enumerable),
(nurimaze, ["nurimaze"], "Nurimaze", "ぬりめいず"),
(nurimisaki, ["nurimisaki"], "Nurimisaki", "ぬりみさき"),
(nuritwin, ["nuritwin"], "Nuritwin", "ぬりツイン"),
(pencils, ["pencils"], "Pencils", "ペンシルズ"),
(pentominous, ["pentominous"], "Pentominous", "Pentominous"),
(putteria, ["putteria"], "Putteria", "プッテリア"),
(reflect, ["reflect"], "Reflect Link", "リフレクトリンク"),
(ringring, ["ringring"], "Ring-Ring", "リングリング"),
(ripple, ["ripple"], "Ripple Effect", "波及効果"),
(roma, ["roma"], "Roma", "ろーま"),
(sansaroad, ["sansaroad"], "Sansa Road", "サンサロード"),
(sashigane, ["sashigane"], "Sashigane", "さしがね"),
(school_trip, ["shugaku"], "School Trip", "修学旅行の夜"),
(sendai, ["sendai"], "Sendai-Miyagi", "宮城県仙台市"),
(shakashaka, ["shakashaka"], "Shakashaka", "シャカシャカ"),
(shikaku, ["shikaku"], "Shikaku", "四角に切れ"),
(shimaguni, ["shimaguni"], "Shimaguni", "島国"),
(simpleloop, ["simpleloop"], "Simple Loop", "シンプルループ"),
(slalom, ["slalom"], "Slalom", "スラローム"),
(slashpack, ["slashpack"], "Slash Pack", "Slash Pack"),
(slitherlink, ["slither", "slitherlink"], "Slitherlink", "スリザーリンク", enumerable),
(square_jam, ["squarejam"], "Square Jam", "Square Jam"),
(star_battle, ["starbattle"], "Star Battle", "スターバトル"),
(statue_park, ["statuepark"], "Statue Park", "Statue Park"),
(stostone, ["stostone"], "Stostone", "ストストーン"),
(sudoku, ["sudoku"], "Sudoku", "数独"),
(sukoro, ["sukoro"], "Sukoro", "数コロ"),
(tapa, ["tapa"], "Tapa", "Tapa"),
(tasquare, ["tasquare"], "Tasquare", "たすくえあ"),
(tents, ["tents"], "Tents", "Tents"),
(tetrochain_k, ["tetrochaink"], "Tetrochain K", "テトロチェーンK"),
(tetrochain_y, ["tetrochain"], "Tetrochain Y", "テトロチェーンY"),
(tetrominous, ["tetrominous"], "Tetrominous", "Tetrominous"),
(tilecity, ["tilecity"], "Tile City", "タイルシティー"),
(timebomb, ["timebomb"], "Time Bomb", "時限爆弾"),
(tontonbeya, ["tontonbeya"], "Tontonbeya", "とんとんべや"),
(waterwalk, ["waterwalk"], "Water Walk", "ウォーターウォーク"),
(yajikazu, ["yajikazu"], "Yajisan-Kazusan", "やじさんかずさん"),
(yajilin, ["yajilin", "yajirin"], "Yajilin", "ヤジリン"),
(yajilin_regions, ["yajilin-regions"], "Yajilin (Regions)", "ヘヤジリン"),
(yajisoko, ["yajisoko"], "Yajisan-Sokoban", "やじさん倉庫番"),
(yinyang, ["yinyang"], "Yin-Yang", "しろまるくろまる"),
);
#[rustfmt::skip]
puzzle_list!(kudamono,
(akari_regions, ["akari-regional"], "Regional Akari", "Regional Akari"),
(akari_rgb, ["akari-rgb"], "Akari RGB", "Akari RGB"),
(cross_border_parity_loop, ["cross-border-parity-loop"], "Cross Border Parity Loop", "Cross Border Parity Loop"),
(crosswall, ["crosswall"], "Cross Wall", "クロスウォール"),
(hidato, ["hidoku"], "Hidato", "Hidato"),
(knossos, ["knossos"], "Knossos", "Knossos"),
(kropki_pairs, ["kropki-pairs"], "Kropki Pairs", "Kropki Pairs"),
(letter_weights, ["letter-weights"], "Letter Weights", "Letter Weights"),
(milktea, ["milk-tea"], "Milk Tea", "Milk Tea"),
(multiplication_link, ["multiplication-link"], "Multiplication Link", "掛け算リンク"),
(parrot_loop, ["parrot-loop"], "Parrot Loop", "Parrot Loop"),
(seiza, ["seiza"], "Seiza", "星座になれたら"),
(slicy, ["slicy"], "SLICY", "SLICY"),
(sniping_arrow, ["sniping-arrow"], "Sniping Arrow", "スナイピングアロー"),
(soulmates, ["soulmates"], "Soulmates", "ソウルメイツ"),
(spokes, ["spokes"], "Spokes", "Spokes"),
(tamago_town, ["tamago-town"], "Tamago Town", "Tamago Town"),
(tetrochain_ctb, ["tetrochain-ctb"], "Tetrochain CTB", "Tetrochain CTB"),
(the_longest, ["the-longest"], "The Longest", "短辺消失"),
(tricklayer, ["tricklayer"], "Tricklayer", "Tricklayer"),
(windows, ["windows"], "Windows", "Windows"),
);
#[rustfmt::skip]
puzzle_list!(penpa_edit,
(castle_walker, ["castle_walker"], "Castle Walker", "Castle Walker"),
(exercise, ["exercise"], "Exercise", "Exercise"),
(pyramid, ["pyramid"], "Pyramid", "ピラミッド"),
(pyramid_climbers, ["pyramid_climbers"], "Pyramid Climbers", "Pyramid Climbers"),
);
pub mod double_lits;
pub fn dispatch_puzz_link(puzzle_kind: &str, url: &str) -> Option<Result<Board, &'static str>> {
puzz_link::dispatch(puzzle_kind, url)
}
pub fn dispatch_puzz_link_enumerate(
puzzle_kind: &str,
url: &str,
num_max_answers: usize,
) -> Option<Result<(Board, Vec<Board>), &'static str>> {
puzz_link::dispatch_enumerate(puzzle_kind, url, num_max_answers)
}
pub fn dispatch_kudamono(
puzzle_kind: &str,
puzzle_variant: &str,
url: &str,
) -> Option<Result<Board, &'static str>> {
if let Some(res) = kudamono::dispatch(puzzle_kind, url) {
return Some(res);
}
if puzzle_kind == "lits" && puzzle_variant == "double" {
return Some(double_lits::solve(url));
}
None
}
pub fn dispatch_penpa_edit(puzzle_kind: &str, url: &str) -> Option<Result<Board, &'static str>> {
penpa_edit::dispatch(puzzle_kind, url)
}
pub fn list_puzzles_for_solve() -> Vec<(String, String)> {
let mut puzzles = Vec::new();
puzzles.extend(puzz_link::list_puzzles());
puzzles.extend(kudamono::list_puzzles());
puzzles.push(("Double LITS".to_string(), "Double LITS".to_string()));
puzzles.extend(penpa_edit::list_puzzles());
puzzles.sort();
puzzles
}
pub fn list_puzzles_for_enumerate() -> Vec<(String, String)> {
let mut puzzles = Vec::new();
puzzles.extend(puzz_link::list_puzzles_enumerate());
puzzles.sort();
puzzles
}
pub fn list_penpa_edit_puzzles() -> Vec<(String, String, String)> {
penpa_edit::list_puzzles_with_key()
}