Make special mechanics essential in postcard and story puzzles
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/domain/library.dart';
|
||||
import 'package:lumen/domain/postcards.dart';
|
||||
import 'package:lumen/domain/postcard_tuned_givens.dart';
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
import 'package:lumen/services/ad_pacing.dart';
|
||||
import 'package:lumen/services/play_metrics.dart';
|
||||
@@ -21,6 +22,74 @@ void solve(Game game) {
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('advanced story puzzles need their special rule and preserve their pictures', () async {
|
||||
final library = await StoryLibrary.load();
|
||||
var count = 0;
|
||||
for (final definition in library.stories) {
|
||||
final book = await library.open(definition.id);
|
||||
for (final level in book.levels) {
|
||||
final p = level.puzzle();
|
||||
if (level.mechanics.isEmpty) continue;
|
||||
count++;
|
||||
final without = p.constraints
|
||||
.where(
|
||||
(c) =>
|
||||
c.name != 'Lantern pair' &&
|
||||
!c.name.startsWith('Footprint trail'),
|
||||
)
|
||||
.toList();
|
||||
expect(p.solution, level.picture);
|
||||
expect(p.countSolutions(), 1, reason: level.id);
|
||||
expect(
|
||||
LogicSolver(49, p.constraints).analyze(p.initial).solved,
|
||||
isTrue,
|
||||
reason: level.id,
|
||||
);
|
||||
expect(
|
||||
LogicSolver(49, without).countSolutions(p.initial),
|
||||
greaterThan(1),
|
||||
reason: level.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(count, 8);
|
||||
});
|
||||
test('tuned boards require their special rule for a unique solution', () {
|
||||
var count = 0;
|
||||
for (var i = 0; i < islandPostcards.length; i++) {
|
||||
for (var slot = 0; slot < 3; slot++) {
|
||||
final p = islandPostcards[i].puzzle(slot);
|
||||
final hasSpecial =
|
||||
p.lanternPairs.isNotEmpty ||
|
||||
p.mirrorPairs.isNotEmpty ||
|
||||
p.footprintTrails.isNotEmpty ||
|
||||
p.hiddenRow != null;
|
||||
if (!hasSpecial) continue;
|
||||
expect(postcardTunedGivens[i * 3 + slot], isNotNull);
|
||||
count++;
|
||||
final without = p.constraints
|
||||
.where(
|
||||
(c) =>
|
||||
!(p.lanternPairs.isNotEmpty && c.name == 'Lantern pair') &&
|
||||
!(p.mirrorPairs.isNotEmpty && c.equal) &&
|
||||
!(p.footprintTrails.isNotEmpty &&
|
||||
c.name.startsWith('Footprint trail')) &&
|
||||
!(p.hiddenRow != null && c.name == 'Combined hidden total'),
|
||||
)
|
||||
.toList();
|
||||
expect(
|
||||
LogicSolver(49, without).countSolutions(p.initial),
|
||||
greaterThan(1),
|
||||
);
|
||||
expect(p.countSolutions(), 1);
|
||||
expect(
|
||||
LogicSolver(49, p.constraints).analyze(p.initial).solved,
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(count, 33);
|
||||
});
|
||||
test('hidden totals and mirrored pairs agree with the saved solutions', () {
|
||||
var hidden = 0, mirrors = 0, trails = 0;
|
||||
for (final card in islandPostcards) {
|
||||
@@ -35,7 +104,19 @@ void main() {
|
||||
final row = p.hiddenRow;
|
||||
if (row != null) {
|
||||
hidden++;
|
||||
expect(p.rows[row], p.rows[row - 1] + 1);
|
||||
expect(p.hiddenColumn, isNotNull);
|
||||
expect(p.constraints.any((c) => c.name == 'Row ${row + 1}'), isFalse);
|
||||
expect(
|
||||
p.constraints.any((c) => c.name == 'Column ${p.hiddenColumn! + 1}'),
|
||||
isFalse,
|
||||
);
|
||||
expect(p.hiddenTotalCells.length, 3);
|
||||
expect(
|
||||
p.hiddenClueTotal,
|
||||
p.hiddenClueCells
|
||||
.map((cell) => p.solution[cell])
|
||||
.reduce((a, b) => a + b),
|
||||
);
|
||||
}
|
||||
for (final pair in p.mirrorPairs) {
|
||||
mirrors++;
|
||||
|
||||
Reference in New Issue
Block a user