Rename field board -> cells
This commit is contained in:
parent
75e1b62dfb
commit
c2df3477fd
2 changed files with 10 additions and 10 deletions
|
|
@ -18,27 +18,27 @@ import Types.GameMode
|
||||||
data GameBoard mode = MkGameBoard
|
data GameBoard mode = MkGameBoard
|
||||||
{ width :: Int
|
{ width :: Int
|
||||||
, height :: Int
|
, height :: Int
|
||||||
, board :: Array BoardPosition (Maybe (Tile mode))
|
, cells :: Array BoardPosition (Maybe (Tile mode))
|
||||||
, gameMode :: mode
|
, gameMode :: mode
|
||||||
}
|
}
|
||||||
|
|
||||||
clear :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> GameBoard mode
|
clear :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> GameBoard mode
|
||||||
clear topLeft bottomRight gBoard@MkGameBoard{board} = gBoard{board = newCells}
|
clear topLeft bottomRight gBoard@MkGameBoard{cells} = gBoard{cells = newCells}
|
||||||
where
|
where
|
||||||
newCells = board // map (,Nothing) (range (topLeft, bottomRight))
|
newCells = cells // map (,Nothing) (range (topLeft, bottomRight))
|
||||||
|
|
||||||
selectCheck :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> Bool
|
selectCheck :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> Bool
|
||||||
selectCheck topLeft bottomRight board@MkGameBoard{gameMode} =
|
selectCheck topLeft bottomRight board@MkGameBoard{gameMode} =
|
||||||
check gameMode (select topLeft bottomRight board)
|
check gameMode (select topLeft bottomRight board)
|
||||||
|
|
||||||
select :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> [Tile mode]
|
select :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> [Tile mode]
|
||||||
select topLeft bottomRight MkGameBoard{board} =
|
select topLeft bottomRight MkGameBoard{cells} =
|
||||||
mapMaybe (board !) (range (topLeft, bottomRight))
|
mapMaybe (cells !) (range (topLeft, bottomRight))
|
||||||
|
|
||||||
-- TODO: rewrite this with monadic RNG?
|
-- TODO: rewrite this with monadic RNG?
|
||||||
newRandomBoard :: (RandomGen g, GameMode mode) => mode -> Int -> Int -> g -> (GameBoard mode, g)
|
newRandomBoard :: (RandomGen g, GameMode mode) => mode -> Int -> Int -> g -> (GameBoard mode, g)
|
||||||
newRandomBoard gameMode width height rng =
|
newRandomBoard gameMode width height rng =
|
||||||
(MkGameBoard{width, height, gameMode, board = array ixRange cellAssocList}, nextRng)
|
(MkGameBoard{width, height, gameMode, cells = array ixRange cellAssocList}, nextRng)
|
||||||
where
|
where
|
||||||
ixRange = ((0, 0), (width - 1, height - 1))
|
ixRange = ((0, 0), (width - 1, height - 1))
|
||||||
(cellAssocList, nextRng) =
|
(cellAssocList, nextRng) =
|
||||||
|
|
@ -48,10 +48,10 @@ newRandomBoard gameMode width height rng =
|
||||||
(range ixRange)
|
(range ixRange)
|
||||||
|
|
||||||
instance (Display (Tile mode)) => Display (GameBoard mode) where
|
instance (Display (Tile mode)) => Display (GameBoard mode) where
|
||||||
display MkGameBoard{width, height, board} =
|
display MkGameBoard{width, height, cells} =
|
||||||
foldl' (\c -> \row -> c `append` displayRow row `append` "\n") "" [0 .. height - 1]
|
foldl' (\c -> \row -> c `append` displayRow row `append` "\n") "" [0 .. height - 1]
|
||||||
where
|
where
|
||||||
displayCell row col = case board ! (row, col) of Nothing -> " "; Just t -> display t
|
displayCell row col = case cells ! (row, col) of Nothing -> " "; Just t -> display t
|
||||||
displayRow row =
|
displayRow row =
|
||||||
foldl'
|
foldl'
|
||||||
( \c -> \col ->
|
( \c -> \col ->
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ spec = describe "gameboard" do
|
||||||
, ((1, 0), Just $ IntTile 3)
|
, ((1, 0), Just $ IntTile 3)
|
||||||
, ((1, 1), Just $ IntTile 4)
|
, ((1, 1), Just $ IntTile 4)
|
||||||
]
|
]
|
||||||
gameBoard = MkGameBoard{width = 2, height = 2, gameMode = MkSumTo 10, board = tiles}
|
gameBoard = MkGameBoard{width = 2, height = 2, gameMode = MkSumTo 10, cells = tiles}
|
||||||
|
|
||||||
it "displays correctly" do
|
it "displays correctly" do
|
||||||
displayText gameBoard `shouldBe` "1 2 \n3 4 \n"
|
displayText gameBoard `shouldBe` "1 2 \n3 4 \n"
|
||||||
|
|
@ -30,4 +30,4 @@ spec = describe "gameboard" do
|
||||||
|
|
||||||
it "clears properly" do
|
it "clears properly" do
|
||||||
let cleared = clear (0, 0) (0, 1) gameBoard
|
let cleared = clear (0, 0) (0, 1) gameBoard
|
||||||
elems (board cleared) `shouldBe` [Nothing, Nothing, Just $ IntTile 3, Just $ IntTile 4]
|
elems (cells cleared) `shouldBe` [Nothing, Nothing, Just $ IntTile 3, Just $ IntTile 4]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue