From c2df3477fd0067be819e7224f6444ef4e7ddcf4c Mon Sep 17 00:00:00 2001 From: Sidharth Kulkarni Date: Wed, 6 May 2026 21:59:24 -0700 Subject: [PATCH] Rename field board -> cells --- src/Types/GameBoard.hs | 16 ++++++++-------- test/Spec.hs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Types/GameBoard.hs b/src/Types/GameBoard.hs index fa16b45..8e158fc 100644 --- a/src/Types/GameBoard.hs +++ b/src/Types/GameBoard.hs @@ -18,27 +18,27 @@ import Types.GameMode data GameBoard mode = MkGameBoard { width :: Int , height :: Int - , board :: Array BoardPosition (Maybe (Tile mode)) + , cells :: Array BoardPosition (Maybe (Tile mode)) , gameMode :: 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 - newCells = board // map (,Nothing) (range (topLeft, bottomRight)) + newCells = cells // map (,Nothing) (range (topLeft, bottomRight)) selectCheck :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> Bool selectCheck topLeft bottomRight board@MkGameBoard{gameMode} = check gameMode (select topLeft bottomRight board) select :: (GameMode mode) => BoardPosition -> BoardPosition -> GameBoard mode -> [Tile mode] -select topLeft bottomRight MkGameBoard{board} = - mapMaybe (board !) (range (topLeft, bottomRight)) +select topLeft bottomRight MkGameBoard{cells} = + mapMaybe (cells !) (range (topLeft, bottomRight)) -- TODO: rewrite this with monadic RNG? newRandomBoard :: (RandomGen g, GameMode mode) => mode -> Int -> Int -> g -> (GameBoard mode, g) newRandomBoard gameMode width height rng = - (MkGameBoard{width, height, gameMode, board = array ixRange cellAssocList}, nextRng) + (MkGameBoard{width, height, gameMode, cells = array ixRange cellAssocList}, nextRng) where ixRange = ((0, 0), (width - 1, height - 1)) (cellAssocList, nextRng) = @@ -48,10 +48,10 @@ newRandomBoard gameMode width height rng = (range ixRange) 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] 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 = foldl' ( \c -> \col -> diff --git a/test/Spec.hs b/test/Spec.hs index 803b34e..01c162e 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -19,7 +19,7 @@ spec = describe "gameboard" do , ((1, 0), Just $ IntTile 3) , ((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 displayText gameBoard `shouldBe` "1 2 \n3 4 \n" @@ -30,4 +30,4 @@ spec = describe "gameboard" do it "clears properly" do 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]