0718e3f252
- Start the app on a shelf of every installed book instead of the last book's home. Cards show the cover, translated metadata, available languages, restored patterns and either "Continue reading" or a way in. - Keep each book's saved route: the shelf is never written to flutter_screen, so choosing a book resumes its own leaf. - Lay the shelf out responsively: dense single-column cards on phones, a two-column grid from 720 logical pixels, a centred 860 px column on tablets and a chevron that exists in the bundled handwriting font. - Keep Settings reachable from the shelf and let the home page's story library button open the shelf instead of a dialog. - Add tool/shelf_screenshots_test.dart, which renders the shelf at phone and tablet metrics, checks that every card and Settings stay reachable without overflow, and writes artifacts/library/shelf-*.png. - Commit the pending Midnight Invitation package (campaign, notebook, narration and artwork), cast drama and ambience tooling, region selection, phone/tablet integration coverage and related docs. flutter analyze is clean and all 74 widget/domain tests pass.
153 lines
5.3 KiB
Dart
153 lines
5.3 KiB
Dart
// Reproducible constraint authoring for the fixed Halloween picture silhouettes.
|
|
// This never changes the authored pictures or story text.
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'dart:math';
|
|
|
|
import 'package:lumen/domain/puzzle.dart';
|
|
import 'package:lumen/domain/thinking.dart';
|
|
|
|
void main() {
|
|
final file = File('assets/stories/midnight-invitation/campaign.json');
|
|
final data = jsonDecode(file.readAsStringSync()) as Map<String, dynamic>;
|
|
final reports = <Map<String, Object?>>[];
|
|
for (var index = 0; index < (data['levels'] as List).length; index++) {
|
|
final record = data['levels'][index] as Map<String, dynamic>;
|
|
final picture = (record['picture'] as String)
|
|
.split('')
|
|
.map(int.parse)
|
|
.toList();
|
|
final random = Random(0x10312026 + index);
|
|
Puzzle? best;
|
|
ThinkingReport? bestReport;
|
|
var bestScore = double.infinity;
|
|
final trials = index < 2 ? 180 : 1200;
|
|
for (var trial = 0; trial < trials; trial++) {
|
|
final p = Puzzle(7, picture);
|
|
final regionCount = index < 2
|
|
? 0
|
|
: index < 4
|
|
? 2
|
|
: 3;
|
|
while (p.regions.length < regionCount) {
|
|
final height = 3 + random.nextInt(2), width = 3 + random.nextInt(2);
|
|
final r = Region(
|
|
String.fromCharCode(65 + p.regions.length),
|
|
random.nextInt(8 - height),
|
|
random.nextInt(8 - width),
|
|
height,
|
|
width,
|
|
);
|
|
if (p.regions.any(
|
|
(old) =>
|
|
old.top == r.top &&
|
|
old.left == r.left &&
|
|
old.height == r.height &&
|
|
old.width == r.width,
|
|
)) {
|
|
continue;
|
|
}
|
|
if (p.regions.isNotEmpty) {
|
|
final old = p.regions.last;
|
|
final common = List.generate(
|
|
49,
|
|
(i) => i,
|
|
).where((i) => old.contains(i, 7) && r.contains(i, 7)).length;
|
|
if (common < 2 ||
|
|
common >= min(old.height * old.width, r.height * r.width)) {
|
|
continue;
|
|
}
|
|
}
|
|
p.regions.add(r);
|
|
}
|
|
final order = List.generate(49, (i) => i)..shuffle(random);
|
|
for (final cell in order.take(2 + random.nextInt(3))) {
|
|
p.given[cell] = true;
|
|
}
|
|
final solver = LogicSolver(49, p.constraints);
|
|
var analysis = solver.analyze(p.initial);
|
|
while (!analysis.solved && p.given.where((v) => v).length < 8) {
|
|
final candidates = List.generate(
|
|
49,
|
|
(i) => i,
|
|
).where((i) => analysis.cells[i] < 0).toList()..shuffle(random);
|
|
var selected = candidates.first, mostKnown = -1;
|
|
for (final cell in candidates.take(8)) {
|
|
p.given[cell] = true;
|
|
final a = solver.analyze(p.initial);
|
|
final known = a.cells.where((v) => v >= 0).length;
|
|
if (known > mostKnown) {
|
|
selected = cell;
|
|
mostKnown = known;
|
|
}
|
|
p.given[cell] = false;
|
|
}
|
|
p.given[selected] = true;
|
|
analysis = solver.analyze(p.initial);
|
|
}
|
|
if (!analysis.solved) continue;
|
|
for (final cell in order.where((i) => p.given[i])) {
|
|
if (p.given.where((v) => v).length <= (index < 2 ? 2 : 0)) break;
|
|
p.given[cell] = false;
|
|
if (!solver.analyze(p.initial).solved) p.given[cell] = true;
|
|
}
|
|
final singles = solver.analyze(p.initial, useAreas: false);
|
|
if (index >= 2 && (singles.solved || analysis.areaDeductions == 0)) {
|
|
continue;
|
|
}
|
|
final givens = p.given.where((v) => v).length;
|
|
final foothold = singles.cells.where((v) => v >= 0).length - givens;
|
|
if (foothold < 4) continue;
|
|
final report = ThinkingAnalyzer(
|
|
49,
|
|
p.constraints,
|
|
).analyze(p.initial, maxLookahead: 0);
|
|
if (report.status != ThinkingStatus.solved || report.assumptionSteps != 0) {
|
|
continue;
|
|
}
|
|
final targetRounds = index < 2 ? 4.0 : 5.0 + index / 4;
|
|
final targetComparison = index < 2 ? 0 : 2 + index ~/ 3;
|
|
final score =
|
|
(report.rounds.length - targetRounds).abs() * 3 +
|
|
(report.comparisonSteps - targetComparison).abs() * 1.5 +
|
|
givens * 1.2 +
|
|
(index >= 4 ? (foothold - 12).abs() * .15 : 0);
|
|
if (score < bestScore) {
|
|
bestScore = score;
|
|
best = p;
|
|
bestReport = report;
|
|
}
|
|
if (score < 3.5) break;
|
|
}
|
|
if (best == null || bestReport == null) {
|
|
throw StateError('No suitable constraints for ${record['id']}');
|
|
}
|
|
if (best.countSolutions() != 1) {
|
|
throw StateError('Non-unique ${record['id']}');
|
|
}
|
|
record['clues'] = List.generate(
|
|
49,
|
|
(i) => i,
|
|
).where((i) => best!.given[i]).join(',');
|
|
record['areas'] = best.regions
|
|
.map((r) => '${r.top},${r.left},${r.height},${r.width}')
|
|
.join(';');
|
|
reports.add({
|
|
'id': record['id'],
|
|
'givens': record['clues'],
|
|
'areas': record['areas'],
|
|
'report': bestReport.toJson(),
|
|
});
|
|
stdout.writeln(
|
|
'${index + 1}. ${record['id']}: ${bestReport.givens} givens, ${bestReport.rounds.length} rounds, ${bestReport.comparisonSteps} comparisons, no assumptions',
|
|
);
|
|
}
|
|
file.writeAsStringSync(
|
|
'${const JsonEncoder.withIndent(' ').convert(data)}\n',
|
|
);
|
|
File('assets/stories/midnight-invitation/puzzle-report.json')
|
|
.writeAsStringSync(
|
|
'${const JsonEncoder.withIndent(' ').convert(reports)}\n',
|
|
);
|
|
}
|