Browse Source

Implement won

DricomDragon 5 years ago
parent
commit
c068953d94
1 changed files with 16 additions and 2 deletions
  1. 16 2
      tp/mine-sweeper/main.hs

+ 16 - 2
tp/mine-sweeper/main.hs

@@ -112,12 +112,26 @@ uncover (i, j) g =
     in
     Grid (applyij uncoverOneCell i j cm)
 
+-- 5) Main Loop
+covIndic::Cell -> Int
+covIndic (Covered _ _ _) = 1
+covIndic Selected = 1
+covIndic _ = 0
+
+won::Grid -> Int -> Bool
+won g nbMines =
+    let Grid cm = g in
+    let nbTotal = (length cm) * (length (cm!!0)) in
+    let uncoBinMatrix = map (map covIndic) cm in
+    let nbUnco = sum (map sum uncoBinMatrix) in
+    nbUnco == nbTotal - nbMines
+
 
 -- Testing data
 
 dtTinyGrid = Grid [
-                    [Covered 2 True False, Uncovered 2, Covered 0 True False],
-                    [Selected, Uncovered 0, Covered 2 True True]
+                    [Covered 1 True False, Uncovered 2, Covered 0 True False],
+                    [Uncovered 0, Uncovered 0, Covered 1 True True]
                 ]
 
 dtRS = randSet 3 SG SG 4 5