|
@@ -112,12 +112,26 @@ uncover (i, j) g =
|
|
in
|
|
in
|
|
Grid (applyij uncoverOneCell i j cm)
|
|
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
|
|
-- Testing data
|
|
|
|
|
|
dtTinyGrid = Grid [
|
|
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
|
|
dtRS = randSet 3 SG SG 4 5
|