Uncover all squares when bomb hit

This commit is contained in:
Jack Harley 2021-01-30 13:27:49 +00:00
parent 5576cc46e3
commit f5e8477bc0
1 changed files with 6 additions and 4 deletions

View File

@ -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