module Wordify.Rules.Tile (Tile(Letter, Blank), tileValue, isPlayable, tileLetter, printLetter) where
import Data.Char
data Tile = Letter Char Int | Blank (Maybe Char) deriving (Show, Eq, Ord)
tileValue :: Tile -> Int
tileValue (Letter _ val) = val
tileValue (Blank _) = 0
tileLetter :: Tile -> Maybe Char
tileLetter (Letter char _) = Just char
tileLetter (Blank (Just char)) = Just char
tileLetter (Blank Nothing) = Nothing
printLetter :: Tile -> Maybe Char
printLetter (Letter char _) = Just char
printLetter (Blank (Just char)) = Just $ toLower char
printLetter _ = Nothing
isPlayable :: Tile -> Tile -> Bool
isPlayable (Letter a b) (Letter x y) = (a == x) && (b == y)
isPlayable (Blank (Just _)) (Blank Nothing) = True
isPlayable _ _ = False