Enhance postcard puzzles and narration
This commit is contained in:
@@ -1,34 +1,32 @@
|
||||
// Freeze the boards so future generator changes cannot change saved puzzles.
|
||||
// Freeze new 7x7 boards. Existing v1 completions are preserved separately.
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
|
||||
void main() {
|
||||
final lines = <String>[
|
||||
'// Generated by tool/author_postcard_puzzles.dart. Stable v1 save identities.',
|
||||
'// Generated by tool/author_postcard_puzzles.dart. Stable v2 identities.',
|
||||
'const postcardPatterns = <(String, List<int>)>[',
|
||||
];
|
||||
final seen = <String>{};
|
||||
for (var i = 0; i < 42; i++) {
|
||||
final difficulty = i < 6 || i % 3 == 0
|
||||
? Difficulty.easy
|
||||
: i % 3 == 1 || i < 18
|
||||
? Difficulty.medium
|
||||
: Difficulty.hard;
|
||||
var seed = 830000 + i * 1000;
|
||||
Puzzle p;
|
||||
do {
|
||||
p = Puzzle.generate(BigInt.from(seed++), difficulty);
|
||||
} while (!seen.add(p.solution.join()));
|
||||
if (p.countSolutions() != 1 ||
|
||||
!LogicSolver(
|
||||
p.solution.length,
|
||||
p.constraints,
|
||||
).analyze(p.initial).solved) {
|
||||
throw StateError('Invalid postcard board $i');
|
||||
final random = JavaRandom(BigInt.from(490018 + 7919 * i));
|
||||
final p = Puzzle(7, List.generate(49, (_) => random.next(1)));
|
||||
if (!seen.add(p.solution.join())) throw StateError('Duplicate board');
|
||||
for (var j = 0; j < 49; j++) {
|
||||
p.given[j] = true;
|
||||
}
|
||||
final order = List.generate(49, (j) => j);
|
||||
random.shuffle(order);
|
||||
for (final j in order) {
|
||||
p.given[j] = false;
|
||||
if (p.countSolutions() != 1 ||
|
||||
!LogicSolver(49, p.constraints).analyze(p.initial).solved) {
|
||||
p.given[j] = true;
|
||||
}
|
||||
}
|
||||
lines.add(
|
||||
" ('${p.solution.join()}', ${[for (var j = 0; j < 25; j++)
|
||||
" ('${p.solution.join()}', ${[for (var j = 0; j < 49; j++)
|
||||
if (p.given[j]) j]}),",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user