implement clear

This commit is contained in:
Sidharth Kulkarni 2026-05-03 14:10:20 -07:00
parent a9b265fabc
commit 140d6989ec
Signed by: skulk
SSH key fingerprint: SHA256:Jby+S9d1WmwqnXIrngHgccYNHz+cYquxN1zm3ym3Kbg
2 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,7 @@
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableInstances #-}
module Types.GameBoard where module Types.GameBoard where
@ -20,8 +21,10 @@ data GameBoard mode = MkGameBoard
, gameMode :: mode , gameMode :: mode
} }
clear = undefined
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}
where
newCells = board // 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} =

View file

@ -3,7 +3,7 @@
module Spec where module Spec where
import Data.Array (array) import Data.Array (array, elems)
import Display (displayText) import Display (displayText)
import Test.Hspec import Test.Hspec
import Types.GameBoard import Types.GameBoard
@ -27,3 +27,7 @@ spec = describe "gameboard" do
it "validates a move" do it "validates a move" do
selectCheck (0, 0) (1, 1) gameBoard `shouldBe` True selectCheck (0, 0) (1, 1) gameBoard `shouldBe` True
selectCheck (0, 0) (0, 1) gameBoard `shouldBe` False selectCheck (0, 0) (0, 1) gameBoard `shouldBe` False
it "clears properly" do
let cleared = clear (0, 0) (0, 1) gameBoard
elems (board cleared) `shouldBe` [Nothing, Nothing, Just $ IntTile 3, Just $ IntTile 4]