Better implementation of adjacent bombs
This commit is contained in:
parent
cda669bcc4
commit
f828182551
|
@ -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" #+ [
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue