Skip to content

Commit

Permalink
Changed win condition to uncovered mines
Browse files Browse the repository at this point in the history
  • Loading branch information
kallepronk committed Mar 27, 2023
1 parent 156d942 commit 47db46a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Shared/MinesweeperGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,15 @@ extension Grid2D where Tile == MinesweeperTile {
}

// Check win condition

// Check if all mines have a flag
let mines = memory.filter { tile in
tile.content == .mine
}
let flaggedMines = mines.filter { tile in
tile.state == .flagged
}
let allMinesAreFlagged = mines.count == flaggedMines.count

// Check if all empty tiles *don't* have a flag
let emptyTiles = memory.filter { tile in
tile.content == .empty
}
let nonMineTilesDontHaveFlags = emptyTiles.allSatisfy { tile in
tile.state != .flagged

let uncoveredTiles = memory.filter { tile in
tile.state == .exposed
}

if allMinesAreFlagged && nonMineTilesDontHaveFlags {
if emptyTiles.count == uncoveredTiles.count {
return .won
} else {
return .running
Expand Down

0 comments on commit 47db46a

Please sign in to comment.