commit 50e2299d36172417eb2ef7a3bcf8611640d997c5
parent ed23143fdfc3363d65f42270ca63dfba36e265fd
Author: Michael Camilleri <[email protected]>
Date: Thu, 30 Apr 2026 21:51:33 +0900
Change reveal tool to only mark mistakes as correct
Previous to this commit, using the reveal tool in a game would mark as
corrected all squares that were being revealed, even those that were
already correct. This commit changes that so that only the mistaken
squares are marked as corrected.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Diffstat:
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/Crossmate/Models/Game.swift b/Crossmate/Models/Game.swift
@@ -73,12 +73,17 @@ final class Game {
}
/// For each target cell, writes the solution into the entry and sets the
- /// mark to `.revealed` (which locks the cell against future edits).
+ /// mark to `.revealed` (which locks the cell against future edits). Cells
+ /// whose entry already matches the solution are left untouched — the user
+ /// got it right, so there's no reason to overwrite their mark or lock the
+ /// cell.
func revealCells(_ cells: [Puzzle.Cell]) {
for cell in cells {
guard !cell.isBlock else { continue }
guard let solution = cell.solution else { continue }
- squares[cell.row][cell.col].entry = solution.uppercased()
+ let expected = solution.uppercased()
+ if squares[cell.row][cell.col].entry == expected { continue }
+ squares[cell.row][cell.col].entry = expected
squares[cell.row][cell.col].mark = .revealed
}
}
diff --git a/Tests/Unit/GameMutatorTests.swift b/Tests/Unit/GameMutatorTests.swift
@@ -65,6 +65,40 @@ struct GameMutatorTests {
#expect(game.squares[0][0].mark == .revealed)
}
+ @Test("revealCells leaves correct entries unmarked")
+ func revealCellsSkipsCorrectEntries() throws {
+ let (game, mutator, _, _) = try makeTestGame()
+
+ // Cell (0,0) has solution "A" — user already entered it correctly in pen.
+ mutator.setLetter("A", atRow: 0, atCol: 0, pencil: false)
+ mutator.revealCells([game.puzzle.cells[0][0]])
+
+ #expect(game.squares[0][0].entry == "A")
+ #expect(game.squares[0][0].mark == .none)
+ }
+
+ @Test("revealCells preserves pencil mark on correct entries")
+ func revealCellsPreservesPencilOnCorrect() throws {
+ let (game, mutator, _, _) = try makeTestGame()
+
+ mutator.setLetter("A", atRow: 0, atCol: 0, pencil: true)
+ mutator.revealCells([game.puzzle.cells[0][0]])
+
+ #expect(game.squares[0][0].entry == "A")
+ #expect(game.squares[0][0].mark == .pencil(checkedWrong: false))
+ }
+
+ @Test("revealCells overwrites wrong entries and marks them revealed")
+ func revealCellsOverwritesWrong() throws {
+ let (game, mutator, _, _) = try makeTestGame()
+
+ mutator.setLetter("Z", atRow: 0, atCol: 0, pencil: false)
+ mutator.revealCells([game.puzzle.cells[0][0]])
+
+ #expect(game.squares[0][0].entry == "A")
+ #expect(game.squares[0][0].mark == .revealed)
+ }
+
@Test("clearCells clears non-revealed cells")
func clearCellsClearsNonRevealed() throws {
let (game, mutator, _, _) = try makeTestGame()