From 47db46ae73ac6a7a1df81b560e04541a58f231e0 Mon Sep 17 00:00:00 2001 From: Kalle Pronk Date: Mon, 27 Mar 2023 17:57:23 +0200 Subject: [PATCH] Changed win condition to uncovered mines --- Shared/MinesweeperGrid.swift | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Shared/MinesweeperGrid.swift b/Shared/MinesweeperGrid.swift index 135adbb..ffbd6dc 100644 --- a/Shared/MinesweeperGrid.swift +++ b/Shared/MinesweeperGrid.swift @@ -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