From f5e8477bc0e32a59eda3853994154c2d3d804a69 Mon Sep 17 00:00:00 2001 From: Jack Harley Date: Sat, 30 Jan 2021 13:27:49 +0000 Subject: [PATCH] Uncover all squares when bomb hit --- src/Minesweeper.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Minesweeper.hs b/src/Minesweeper.hs index 98dc523..2fec3c1 100644 --- a/src/Minesweeper.hs +++ b/src/Minesweeper.hs @@ -13,11 +13,11 @@ data Board = Board { size :: Int -- Creates a board given a size (width/height), mine ratio and random generator createBoard :: Int -> Float -> StdGen -> Board -createBoard size mineRatio rng = Board size (seedGrid rng mineRatio (createGrid size)) (createGrid size) (createGrid size) +createBoard size mineRatio rng = Board size (seedGrid rng mineRatio (createGrid False size)) (createGrid False size) (createGrid False size) --- Creates a 2D list of booleans of given size, initialised to False -createGrid :: Int -> Grid -createGrid size = replicate size (replicate size False) +-- Creates a 2D list of booleans of given size, initialised to given boolean +createGrid :: Bool -> Int -> Grid +createGrid b size = replicate size (replicate size b) -- Functions relating to seeding a grid with mines @@ -105,6 +105,8 @@ boolToInt x | x = 1 uncover :: Board -> Square -> Board uncover b (r,c) | not $ validSquare b (r,c) = b | isUncovered b (r,c) = b + | hasMine b (r,c) = let Board s m u f = b + in Board s m (createGrid True s) f | otherwise = let Board s m u f = b (rowsA, row : rowsB) = splitAt r u (cellsA, _ : cellsB) = splitAt c row