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