Make special mechanics essential in postcard and story puzzles
This commit is contained in:
+13
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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],
|
||||
];
|
||||
@@ -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
@@ -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(
|
||||
|
||||
+7
-1
@@ -1533,6 +1533,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
List<Widget> puzzleNotes() => [
|
||||
if (g.puzzle?.omittedRow != null)
|
||||
writing(
|
||||
'Two totals have faded. Use the marked cells and area clues to recover the pattern.',
|
||||
size: 19,
|
||||
color: regionInk,
|
||||
),
|
||||
if (g.puzzle?.footprintTrails.isNotEmpty ?? false)
|
||||
writing(
|
||||
'Footprints: exactly two marked cells are lit, and they touch.',
|
||||
@@ -1547,7 +1553,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
if (g.puzzle?.hiddenRow case final row?)
|
||||
writing(
|
||||
'Row ${row + 1} has one more light than row $row.',
|
||||
'Row ${row + 1} and the diamond-marked cells together contain ${g.puzzle!.hiddenClueTotal} lights. Recover both missing totals.',
|
||||
size: 19,
|
||||
color: regionInk,
|
||||
),
|
||||
|
||||
+78
-11
@@ -107,11 +107,16 @@ class Board extends StatelessWidget {
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
puzzle.hiddenColumn == col ||
|
||||
puzzle.omittedColumn == col
|
||||
? '?'
|
||||
: '${puzzle.cols[col]}',
|
||||
puzzle.hiddenColumn != col &&
|
||||
puzzle.omittedColumn != col &&
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -120,10 +125,12 @@ class Board extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
puzzle.hiddenRow == row
|
||||
puzzle.hiddenRow == row ||
|
||||
puzzle.omittedRow == row
|
||||
? '?'
|
||||
: '${puzzle.rows[row]}',
|
||||
puzzle.hiddenRow != row &&
|
||||
puzzle.omittedRow != row &&
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
@@ -238,6 +245,25 @@ class Board extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (puzzle
|
||||
.hiddenTotalCells
|
||||
.contains(i))
|
||||
Positioned(
|
||||
left: 1,
|
||||
top: 1,
|
||||
child: Container(
|
||||
key: ValueKey(
|
||||
'diamond-$i',
|
||||
),
|
||||
color: cream,
|
||||
child: Icon(
|
||||
Icons
|
||||
.diamond_outlined,
|
||||
size: u * .31,
|
||||
color: regionInk,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (mirrored)
|
||||
Positioned(
|
||||
left: 1,
|
||||
@@ -282,11 +308,13 @@ class Board extends StatelessWidget {
|
||||
const EdgeInsets.all(
|
||||
1,
|
||||
),
|
||||
child: Icon(
|
||||
Icons
|
||||
.directions_walk,
|
||||
size: u * .31,
|
||||
color: regionInk,
|
||||
child: SizedBox.square(
|
||||
dimension:
|
||||
u * .31,
|
||||
child: CustomPaint(
|
||||
painter:
|
||||
FootprintMark(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -350,6 +378,45 @@ class Board extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// A tiny shoe print, used only as a marker inside a puzzle cell.
|
||||
class FootprintMark extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint()..color = regionInk;
|
||||
canvas.save();
|
||||
canvas.translate(size.width * .5, size.height * .5);
|
||||
canvas.rotate(-.35);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(
|
||||
-size.width * .25,
|
||||
-size.height * .46,
|
||||
size.width * .5,
|
||||
size.height * .55,
|
||||
),
|
||||
Radius.circular(size.width * .22),
|
||||
),
|
||||
paint,
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(
|
||||
-size.width * .2,
|
||||
size.height * .16,
|
||||
size.width * .4,
|
||||
size.height * .27,
|
||||
),
|
||||
Radius.circular(size.width * .1),
|
||||
),
|
||||
paint,
|
||||
);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant FootprintMark oldDelegate) => false;
|
||||
}
|
||||
|
||||
/// Deterministic pencil strokes stay put when the player revisits a cell.
|
||||
/// Both marks use paths, so their appearance never depends on a fallback font.
|
||||
class PencilMark extends CustomPainter {
|
||||
|
||||
Reference in New Issue
Block a user