From 617a5d824a836300e533caafa29e6ff3dbe3a696 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 18 Sep 2017 13:45:38 +0200 Subject: Print every gamestate to stdout; Add fault test; Add runchess to gitignore --- src/runchess.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/runchess.hs b/src/runchess.hs index 27a6da8..5854e57 100644 --- a/src/runchess.hs +++ b/src/runchess.hs @@ -21,15 +21,19 @@ readPGN = do Right games -> return games applyPGN :: PGN -> IO () -applyPGN pgn = printGame (foldM (flip moveSAN) defaultBoard $ moves pgn) pgn +applyPGN pgn = mapM_ printBoard (seqList [moveSAN m | m <- moves pgn] $ Right defaultBoard) + where + seqList (f:fs) (Right io) = f io:seqList fs (f io) + seqList _ (Left _) = [] + seqList [] _ = [] 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 +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 -- cgit v1.2.3