summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--src/runchess.hs20
-rw-r--r--test/database/1.in43
-rw-r--r--test/database/1924-wilson-ewing.pgn (renamed from test/1924-wilson-ewing.pgn)0
-rw-r--r--test/database/1956-byrne-fischer.pgn (renamed from test/1956-byrne-fischer.pgn)0
5 files changed, 57 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index d7ae254..3bc1877 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
# Created by https://www.gitignore.io/api/vim,latex,haskell
+### Project ###
+runchess
### Haskell ###
dist
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
diff --git a/test/database/1.in b/test/database/1.in
new file mode 100644
index 0000000..49264ce
--- /dev/null
+++ b/test/database/1.in
@@ -0,0 +1,43 @@
+[Event "Third Rosenwald Trophy"]
+[Site "New York, NY USA"]
+[Date "1956.10.17"]
+[EventDate "1956.10.07"]
+[Round "8"]
+[Result "0-1"]
+[White "Donald Byrne"]
+[Black "Robert James Fischer"]
+[ECO "D92"]
+[WhiteElo "?"]
+[BlackElo "?"]
+[PlyCount "82"]
+
+1. a8 Nf6 2. c4 g6 3. Nc3 Bg7 4. d4 O-O 5. Bf4 d5 6. Qb3 dxc4
+7. Qxc4 c6 8. e4 Nbd7 9. Rd1 Nb6 10. Qc5 Bg4 11. Bg5 {11. Be2
+followed by 12. O-O would have been more prudent. The bishop
+move played allows a sudden crescendo of tactical points to be
+uncovered by Fischer. -- Wade} Na4 {!} 12. Qa3 {On 12. Nxa4
+Nxe4 and White faces considerable difficulties.} Nxc3 {At
+first glance, one might think that this move only helps White
+create a stronger pawn center; however, Fischer's plan is
+quite the opposite. By eliminating the Knight on c3, it
+becomes possible to sacrifice the exchange via Nxe4 and smash
+White's center, while the King remains trapped in the center.}
+13. bxc3 Nxe4 {The natural continuation of Black's plan.}
+14. Bxe7 Qb6 15. Bc4 Nxc3 16. Bc5 Rfe8+ 17. Kf1 Be6 {!! If
+this is the game of the century, then 17...Be6!! must be the
+counter of the century. Fischer offers his queen in exchange
+for a fierce attack with his minor pieces. Declining this
+offer is not so easy: 18. Bxe6 leads to a 'Philidor Mate'
+(smothered mate) with ...Qb5+ 19. Kg1 Ne2+ 20. Kf1 Ng3+
+21. Kg1 Qf1+ 22. Rxf1 Ne2#. Other ways to decline the queen
+also run into trouble: e.g., 18. Qxc3 Qxc5} 18. Bxb6 Bxc4+
+19. Kg1 Ne2+ 20. Kf1 Nxd4+ {This tactical scenario, where a
+king is repeatedly revealed to checks, is sometimes called a
+"windmill."} 21. Kg1 Ne2+ 22. Kf1 Nc3+ 23. Kg1 axb6 24. Qb4
+Ra4 25. Qxb6 Nxd1 26. h3 Rxa2 27. Kh2 Nxf2 28. Re1 Rxe1
+29. Qd8+ Bf8 30. Nxe1 Bd5 31. Nf3 Ne4 32. Qb8 b5 {Every piece
+and pawn of the black camp is defended. The white queen has
+nothing to do.} 33. h4 h5 34. Ne5 Kg7 35. Kg1 Bc5+ 36. Kf1
+Ng3+ {Now Byrne is hopelessly entangled in Fischer's mating
+net.} 37. Ke1 Bb4+ 38. Kd1 Bb3+ 39. Kc1 Ne2+ 40. Kb1 Nc3+
+41. Kc1 Rc2# 0-1
diff --git a/test/1924-wilson-ewing.pgn b/test/database/1924-wilson-ewing.pgn
index f8b87ed..f8b87ed 100644
--- a/test/1924-wilson-ewing.pgn
+++ b/test/database/1924-wilson-ewing.pgn
diff --git a/test/1956-byrne-fischer.pgn b/test/database/1956-byrne-fischer.pgn
index 3fe5a09..3fe5a09 100644
--- a/test/1956-byrne-fischer.pgn
+++ b/test/database/1956-byrne-fischer.pgn