Enhance postcard puzzles and narration

This commit is contained in:
Hadrian Burkhardt
2026-11-14 08:55:48 +01:00
parent abaab927d9
commit b19295472d
158 changed files with 5257 additions and 1695 deletions
+72 -3
View File
@@ -1,21 +1,90 @@
import 'postcard_patterns.dart';
import 'puzzle.dart';
/// A separate, unvoiced collection; it never changes a book's saved position.
/// A separate collection; it never changes a book's saved position.
class IslandPostcard {
const IslandPostcard(this.id, this.title, this.invitation, this.message);
final String id, title, invitation, message;
String get illustrationAsset => 'assets/postcards/illustrations/$id.png';
static const puzzlesPerOuting = 3;
String puzzleKey(int slot) => 'postcard_v1_${id}_$slot';
String puzzleKey(int slot) => 'postcard_v2_${id}_$slot';
String legacyPuzzleKey(int slot) => 'postcard_v1_${id}_$slot';
Puzzle puzzle(int slot) {
RangeError.checkValidIndex(slot, const [0, 1, 2]);
final index = islandPostcards.indexOf(this);
final (picture, clues) = postcardPatterns[index * puzzlesPerOuting + slot];
final board = Puzzle(5, picture.split('').map(int.parse).toList());
final board = Puzzle(7, picture.split('').map(int.parse).toList());
// Overlapping area clues add another way to reason about the same picture.
// Keep the picture, givens and puzzle key stable for saved games.
final mirror = (index + slot).isOdd;
int left(int column) => mirror ? 3 - column : column;
board.regions.addAll([
Region('A', 0, left(0), 4, 4),
Region('B', 1, left(3), 4, 4),
Region('C', 3, left(1), 4, 4),
]);
for (final clue in clues) {
board.given[clue] = true;
}
// Introduce the pair on the last pattern of later outings. Pick two
// editable, opposite cells far apart so both lanterns invite a deduction.
if (index >= 2 && slot == 2) {
LanternPair? pair;
var greatestDistance = -1;
for (var a = 0; a < 49; a++) {
for (var b = a + 1; b < 49; b++) {
if (board.given[a] ||
board.given[b] ||
board.solution[a] == board.solution[b] ||
a ~/ 7 == b ~/ 7 ||
a % 7 == b % 7) {
continue;
}
final distance = (a ~/ 7 - b ~/ 7).abs() + (a % 7 - b % 7).abs();
if (distance > greatestDistance) {
pair = LanternPair(a, b);
greatestDistance = distance;
}
}
}
if (pair != null) board.lanternPairs.add(pair);
}
// The missing total is exactly one more than the previous row's total.
if (index >= 4 && slot == 1) {
for (var row = 1; row < 7; row++) {
if (board.rows[row] == board.rows[row - 1] + 1) {
board.hiddenRow = row;
break;
}
}
}
if (index >= 3 && slot == 0) {
for (var row = 0; row < 7 && board.mirrorPairs.isEmpty; row++) {
for (var col = 0; col < 3; col++) {
final a = row * 7 + col, b = row * 7 + 6 - col;
if (!board.given[a] &&
!board.given[b] &&
board.solution[a] == board.solution[b]) {
board.mirrorPairs.add(LanternPair(a, b));
break;
}
}
}
}
if (index >= 5 && slot == 1 && board.hiddenRow == null) {
for (var row = 0; row < 7 && board.footprintTrails.isEmpty; row++) {
for (var col = 0; col < 5; col++) {
final trail = [row * 7 + col, row * 7 + col + 1, row * 7 + col + 2];
if (trail.every((i) => !board.given[i]) &&
board.solution[trail[1]] == 1 &&
board.solution[trail[0]] + board.solution[trail[2]] == 1) {
board.footprintTrails.add(trail);
break;
}
}
}
}
return board;
}
}