-- vim: sw=2 ts=2 et: import Control.Monad import Control.Monad.Trans.State.Lazy import Data.Attoparsec.ByteString.Char8 import Data.ByteString.Char8 (pack) import Data.Maybe import Chess import Chess.FEN import Chess.PGN main = readPGN >>= mapM_ applyPGN readPGN :: IO [PGN] readPGN = do pgn <- pack <$> getContents case parseOnly pgnParser pgn of Left err -> error err Right [] -> error "no games" Right games -> return games applyPGN :: PGN -> IO () applyPGN pgn = printGame (foldM (flip moveSAN) defaultBoard $ moves pgn) pgn printGame :: Either MoveError Board -> PGN -> IO () printGame b pgn = printPGN pgn >> printBoard b where printBoard (Left e) = putStrLn $ show e printBoard (Right b) = putStr $ show b printPGN :: PGN -> IO () printPGN pgn = do putStrLn $ site pgn ++ " " ++ date pgn ++ ": " ++ whitePlayer pgn ++ " vs. " ++ blackPlayer pgn putStrLn $ show $ result pgn