Make special mechanics essential in postcard and story puzzles

This commit is contained in:
Hadrian Burkhardt
2026-11-14 10:10:36 +01:00
parent b19295472d
commit fc71accb38
11 changed files with 736 additions and 40 deletions
+13 -1
View File
@@ -21,13 +21,15 @@ class CampaignLevel {
illustrationAsset = data['illustrationAsset'] as String?,
picture = (data['picture'] as String).split('').map(int.parse).toList(),
clues = data['clues'],
areas = data['areas'];
areas = data['areas'],
mechanics = Map<String, dynamic>.from(data['mechanics'] as Map? ?? {});
final String id, chapterId;
final int size;
final String chapter, title, object, before, after, clues, areas;
final String beforeContinuation, afterContinuation;
final String? illustrationAsset;
final List<int> picture;
final Map<String, dynamic> mechanics;
Puzzle puzzle() {
final p = Puzzle(size, picture);
if (clues.isNotEmpty) {
@@ -51,6 +53,16 @@ class CampaignLevel {
);
}
}
if (mechanics.isNotEmpty) {
p.omittedRow = mechanics['omittedRow'] as int;
p.omittedColumn = mechanics['omittedColumn'] as int;
if (mechanics['lantern'] case final List pair) {
p.lanternPairs.add(LanternPair(pair[0] as int, pair[1] as int));
}
if (mechanics['trail'] case final List trail) {
p.footprintTrails.add(trail.cast<int>());
}
}
return p;
}
}
+133
View File
@@ -0,0 +1,133 @@
// Generated by tool/tune_postcard_puzzles.dart. Null keeps the original givens.
const postcardTunedGivens = <List<int>?>[
null,
null,
null,
null,
null,
null,
null,
null,
[14, 15, 16, 48],
[4, 7, 12, 13, 17],
null,
[1, 7, 10, 11, 21, 23, 24, 40, 48],
[6, 7, 17, 22, 27],
[0, 20, 21, 22, 29, 39, 42],
[7, 16, 19, 25, 32, 41, 46],
[15, 17, 34, 38],
[7, 11, 24, 26, 29, 31, 35],
[7, 9, 14, 22, 47],
[3, 13, 33, 39, 44, 45],
[36, 38, 47],
[2, 6, 12, 16, 17, 25, 33],
[4, 9, 11, 14, 20, 24, 31, 32, 36],
[7, 18, 29, 31],
[16, 19, 22, 32, 40],
[7, 8, 12, 16, 33, 39, 44, 46],
[2, 28, 33, 35, 44, 47],
[5, 9, 14, 25, 37, 39],
[7, 14, 17, 36, 43, 44, 45],
[0, 4, 13, 22, 27, 30, 45, 48],
[9, 14, 15, 22, 25, 29, 32, 48],
[15, 26, 29, 30, 34, 42],
[7, 13, 16, 17, 24, 27, 30, 43, 47],
[8, 24, 33, 45],
[10, 25, 26, 31],
[9, 15, 20, 30, 41, 42, 45, 48],
[1, 10, 12, 14, 19, 22, 27, 40],
[0, 20, 31, 34, 37, 40, 45, 48],
[5, 9, 11, 14, 22, 31, 46],
[9, 12, 15, 21, 29, 38, 44],
[15, 18, 19, 21, 35],
[7, 9, 15, 18, 20],
[5, 13, 16, 26, 30, 31, 33, 46],
];
const postcardTunedTrails = <List<int>?>[
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
[18, 25, 32],
null,
null,
null,
null,
null,
[16, 17, 18],
null,
null,
[11, 18, 25],
null,
null,
[4, 11, 18],
null,
null,
null,
null,
null,
null,
null,
null,
[25, 32, 39],
null,
];
const postcardTunedLanterns = <List<int>?>[
null,
null,
null,
null,
null,
null,
null,
null,
[6, 37],
null,
null,
[20, 29],
null,
null,
[26, 42],
null,
null,
[16, 43],
null,
null,
[19, 36],
null,
null,
[2, 8],
null,
null,
[19, 34],
null,
null,
[2, 10],
null,
null,
[9, 26],
null,
null,
[3, 16],
null,
null,
[24, 46],
null,
null,
[25, 29],
];
+24 -1
View File
@@ -1,4 +1,5 @@
import 'postcard_patterns.dart';
import 'postcard_tuned_givens.dart';
import 'puzzle.dart';
/// A separate collection; it never changes a book's saved position.
@@ -10,7 +11,7 @@ class IslandPostcard {
String puzzleKey(int slot) => 'postcard_v2_${id}_$slot';
String legacyPuzzleKey(int slot) => 'postcard_v1_${id}_$slot';
Puzzle puzzle(int slot) {
Puzzle puzzle(int slot, {bool useTunedGivens = true}) {
RangeError.checkValidIndex(slot, const [0, 1, 2]);
final index = islandPostcards.indexOf(this);
final (picture, clues) = postcardPatterns[index * puzzlesPerOuting + slot];
@@ -55,6 +56,10 @@ class IslandPostcard {
for (var row = 1; row < 7; row++) {
if (board.rows[row] == board.rows[row - 1] + 1) {
board.hiddenRow = row;
board.hiddenColumn = index % 7;
board.hiddenTotalCells.addAll([
for (var c = 0; c < 3; c++) ((row + 3) % 7) * 7 + c * 2,
]);
break;
}
}
@@ -85,6 +90,24 @@ class IslandPostcard {
}
}
}
final tuned = postcardTunedGivens[index * puzzlesPerOuting + slot];
final tunedPair = postcardTunedLanterns[index * puzzlesPerOuting + slot];
if (useTunedGivens && tunedPair != null) {
board.lanternPairs
..clear()
..add(LanternPair(tunedPair[0], tunedPair[1]));
}
final tunedTrail = postcardTunedTrails[index * puzzlesPerOuting + slot];
if (useTunedGivens && tunedTrail != null) {
board.footprintTrails
..clear()
..add(tunedTrail);
}
if (useTunedGivens && tuned != null) {
for (var cell = 0; cell < board.given.length; cell++) {
board.given[cell] = tuned.contains(cell);
}
}
return board;
}
}
+24 -10
View File
@@ -270,6 +270,16 @@ class Puzzle {
final List<LanternPair> mirrorPairs = [];
final List<List<int>> footprintTrails = [];
int? hiddenRow;
int? hiddenColumn;
int? omittedRow, omittedColumn;
final List<int> hiddenTotalCells = [];
List<int> get hiddenClueCells => [
if (hiddenRow != null)
for (var c = 0; c < size; c++) hiddenRow! * size + c,
...hiddenTotalCells,
];
int get hiddenClueTotal =>
hiddenClueCells.fold(0, (sum, cell) => sum + solution[cell]);
List<int> get rows => List.generate(
size,
(r) => List.generate(
@@ -289,6 +299,8 @@ class Puzzle {
(i) => r.contains(i, size) ? solution[i] : 0,
).reduce((a, b) => a + b);
List<Constraint> get constraints => [
if (hiddenRow != null)
Constraint(hiddenClueCells, hiddenClueTotal, 'Combined hidden total'),
for (final trail in footprintTrails) ...[
Constraint([trail[1]], 1, 'Footprint trail centre'),
Constraint([trail[0], trail[2]], 1, 'Footprint trail ends'),
@@ -298,16 +310,18 @@ class Puzzle {
for (final pair in lanternPairs)
Constraint([pair.first, pair.second], 1, 'Lantern pair'),
for (var l = 0; l < size; l++) ...[
Constraint(
List.generate(size, (p) => l * size + p),
rows[l],
'Row ${l + 1}',
),
Constraint(
List.generate(size, (p) => p * size + l),
cols[l],
'Column ${l + 1}',
),
if (l != hiddenRow && l != omittedRow)
Constraint(
List.generate(size, (p) => l * size + p),
rows[l],
'Row ${l + 1}',
),
if (l != hiddenColumn && l != omittedColumn)
Constraint(
List.generate(size, (p) => p * size + l),
cols[l],
'Column ${l + 1}',
),
],
for (final r in regions)
Constraint(