diff --git a/src/Main.hs b/src/Main.hs index e187fe5..025be17 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -22,7 +22,7 @@ setup rng w = void $ do UI.addStyleSheet w "bootstrap.min.css" UI.addStyleSheet w "minesweeper.css" - let board = createBoard 10 0.06 rng + let board = createBoard 10 0.2 rng getBody w #+ [ UI.div #. "container" #+ [ diff --git a/src/Minesweeper.hs b/src/Minesweeper.hs index 7caa547..8299933 100644 --- a/src/Minesweeper.hs +++ b/src/Minesweeper.hs @@ -65,15 +65,10 @@ squareColour b (r,c) | hasMine b (r,c) = "red" | otherwise = "green" adjacentBombs :: Board -> Square -> Int -adjacentBombs board (row,col) = let tl = boolToInt $ hasMine board (row-1,col-1) - t = boolToInt $ hasMine board (row-1,col) - tr = boolToInt $ hasMine board (row-1,col+1) - l = boolToInt $ hasMine board (row,col-1) - r = boolToInt $ hasMine board (row,col+1) - bl = boolToInt $ hasMine board (row+1,col-1) - b = boolToInt $ hasMine board (row+1,col) - br = boolToInt $ hasMine board (row+1,col+1) - in tl + t + tr + l + r + bl + b + br +adjacentBombs b (r,c) = sum $ map (boolToInt . hasMine b) $ adjacentSquares (r,c) + +adjacentSquares :: Square -> [Square] +adjacentSquares (r,c) = [(r-1,c-1), (r-1,c), (r-1,c+1), (r,c-1), (r,c+1), (r+1,c-1), (r+1,c), (r+1,c+1)] boolToInt :: Bool -> Int boolToInt x | x = 1