module State where defCharsFaction :: Faction -> MainCharacter defCharsFaction Blue = Shinji defCharsFaction Red = Asuka defCharsFaction White = Rei defCharsFaction Green = Misato defCharsFaction Yellow = Ritsuko defCharsFaction Black = Gendo numPut :: Either MainCharacter MainEva -> PutCards -> Integer numPut c p = toInteger $ length $ filter (\x -> (fst x) == c) p removeHand :: CardSym -> Player -> Either Player GameError removeHand c p@(n, h, d) | not $ c `elem` h = Right "Card not in hand" | otherwise = Left (n, nh, nd) where nh = rmFirstMatch h (== c) nd = (c:d) playChar :: Player -> CardSym -> BoardState -> Either BoardState GameError playChar p@(on, oh, od) c ob@(cl, ps, d, pc) | ciType (getCardInfo c cl) /= Character = Right "Not a character" | numPut (Left targetChar) pc >= 2 = Right "Too many put cards" | targetChar `elem` d = Right "Character is down" | isRight np = Right $ unwrapRight np | otherwise = Left $ (cl, (unwrapLeft np):(rmFirstMatch ps (\(n, _, _) -> n == on)), d, npc) where targetChar = defCharsFaction $ ciFaction (getCardInfo c cl) np = removeHand c p npc = (Left targetChar, c):pc