check should return score or nothing if invalid

This commit is contained in:
Sidharth Kulkarni 2026-05-09 20:32:17 -07:00
parent 57579fa5e4
commit 38838c47b9
Signed by: skulk
SSH key fingerprint: SHA256:Jby+S9d1WmwqnXIrngHgccYNHz+cYquxN1zm3ym3Kbg
4 changed files with 11 additions and 13 deletions

View file

@ -8,7 +8,6 @@ import Data.Bifunctor (Bifunctor (first))
import Data.Kind (Type)
import Display
import System.Random.Stateful (Random (randomR), RandomGen)
import Types.BoardPosition
{- | The type of game that is being played.
@ -19,7 +18,7 @@ that sums up to 'n'.
-}
class (Display (Tile t), Show (Tile t), Eq (Tile t), Eq t, Show t) => GameMode t where
data Tile t :: Type
check :: t -> [Tile t] -> Bool
check :: t -> [Tile t] -> Maybe Int
gen :: (RandomGen g) => t -> g -> (Tile t, g)
data SumTo = MkSumTo Int
@ -28,8 +27,8 @@ data SumTo = MkSumTo Int
instance GameMode SumTo where
data Tile SumTo = IntTile Int deriving (Eq, Show)
check (MkSumTo n) [] = n == 0
check (MkSumTo n) lst = n == sum (map toInt lst)
check (MkSumTo n) [] = if n == 0 then Just 0 else Nothing
check (MkSumTo n) lst = if n == sum (map toInt lst) then Just (length lst) else Nothing
where
toInt (IntTile a) = a
gen (MkSumTo n) = first IntTile . randomR (1, n)