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 --- .gitignore | 2 ++ src/runchess.hs | 20 ++++++++++------- test/1924-wilson-ewing.pgn | 22 ------------------ test/1956-byrne-fischer.pgn | 43 ------------------------------------ test/database/1.in | 43 ++++++++++++++++++++++++++++++++++++ test/database/1924-wilson-ewing.pgn | 22 ++++++++++++++++++ test/database/1956-byrne-fischer.pgn | 43 ++++++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 73 deletions(-) delete mode 100644 test/1924-wilson-ewing.pgn delete mode 100644 test/1956-byrne-fischer.pgn create mode 100644 test/database/1.in create mode 100644 test/database/1924-wilson-ewing.pgn create mode 100644 test/database/1956-byrne-fischer.pgn 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/1924-wilson-ewing.pgn b/test/1924-wilson-ewing.pgn deleted file mode 100644 index f8b87ed..0000000 --- a/test/1924-wilson-ewing.pgn +++ /dev/null @@ -1,22 +0,0 @@ -[Event "CAN ch"] -[Site "Hamilton"] -[Date "1924.08.20"] -[Round "6"] -[White "Wilson, Stanley B"] -[Black "Ewing, John M"] -[Result "0-1"] -[ECO "B01"] -[PlyCount "118"] -[EventDate "1924.08.18"] - -1. e4 d5 2. exd5 Qxd5 3. Nc3 Qd8 4. Nf3 c6 5. b3 Nf6 6. Bb2 Bf5 7. Be2 e6 8. -O-O Bd6 9. Nh4 Bg6 10. h3 Nbd7 11. Rc1 Nd5 12. Nxd5 Qxh4 13. Ne3 O-O 14. d4 Nf6 -15. Bf3 Nd5 16. Nxd5 exd5 17. c4 dxc4 18. bxc4 Be4 19. Bxe4 Qxe4 20. Re1 Qf4 -21. g3 Qf5 22. Kg2 Rfe8 23. Qb3 b6 24. Re3 Rxe3 25. Qxe3 Qe6 26. Qf3 Rc8 27. d5 -Qd7 28. dxc6 Qxc6 29. Qd5 Qxd5+ 30. cxd5 Rxc1 31. Bxc1 f5 32. Kf3 Kf7 33. Ke2 -Ke7 34. Kd3 Bc5 35. Be3 Kd6 36. Kc4 Bxe3 37. fxe3 Ke5 38. a4 a6 39. a5 bxa5 40. -Kc5 a4 41. d6 Ke6 42. Kc6 a3 43. d7 a2 44. d8=Q a1=Q 45. Qd5+ Ke7 46. Qd7+ Kf8 -47. Qd6+ (47. Qxf5+ Qf6+ 48. Qxf6+ gxf6 49. Kb6) 47... Kf7 48. Qd7+ Kg6 49. -Qe8+ Kh6 50. Qe6+ g6 51. Kb6 Qa4 52. Qe5 a5 53. Qxa5 Qxa5+ 54. Kxa5 Kg5 55. Kb4 -h5 56. Kc3 h4 57. gxh4+ Kxh4 58. Kd3 Kxh3 59. Ke2 59... Kg2 {(Le Pion 1924)} -0-1 diff --git a/test/1956-byrne-fischer.pgn b/test/1956-byrne-fischer.pgn deleted file mode 100644 index 3fe5a09..0000000 --- a/test/1956-byrne-fischer.pgn +++ /dev/null @@ -1,43 +0,0 @@ -[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. Nf3 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/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/database/1924-wilson-ewing.pgn b/test/database/1924-wilson-ewing.pgn new file mode 100644 index 0000000..f8b87ed --- /dev/null +++ b/test/database/1924-wilson-ewing.pgn @@ -0,0 +1,22 @@ +[Event "CAN ch"] +[Site "Hamilton"] +[Date "1924.08.20"] +[Round "6"] +[White "Wilson, Stanley B"] +[Black "Ewing, John M"] +[Result "0-1"] +[ECO "B01"] +[PlyCount "118"] +[EventDate "1924.08.18"] + +1. e4 d5 2. exd5 Qxd5 3. Nc3 Qd8 4. Nf3 c6 5. b3 Nf6 6. Bb2 Bf5 7. Be2 e6 8. +O-O Bd6 9. Nh4 Bg6 10. h3 Nbd7 11. Rc1 Nd5 12. Nxd5 Qxh4 13. Ne3 O-O 14. d4 Nf6 +15. Bf3 Nd5 16. Nxd5 exd5 17. c4 dxc4 18. bxc4 Be4 19. Bxe4 Qxe4 20. Re1 Qf4 +21. g3 Qf5 22. Kg2 Rfe8 23. Qb3 b6 24. Re3 Rxe3 25. Qxe3 Qe6 26. Qf3 Rc8 27. d5 +Qd7 28. dxc6 Qxc6 29. Qd5 Qxd5+ 30. cxd5 Rxc1 31. Bxc1 f5 32. Kf3 Kf7 33. Ke2 +Ke7 34. Kd3 Bc5 35. Be3 Kd6 36. Kc4 Bxe3 37. fxe3 Ke5 38. a4 a6 39. a5 bxa5 40. +Kc5 a4 41. d6 Ke6 42. Kc6 a3 43. d7 a2 44. d8=Q a1=Q 45. Qd5+ Ke7 46. Qd7+ Kf8 +47. Qd6+ (47. Qxf5+ Qf6+ 48. Qxf6+ gxf6 49. Kb6) 47... Kf7 48. Qd7+ Kg6 49. +Qe8+ Kh6 50. Qe6+ g6 51. Kb6 Qa4 52. Qe5 a5 53. Qxa5 Qxa5+ 54. Kxa5 Kg5 55. Kb4 +h5 56. Kc3 h4 57. gxh4+ Kxh4 58. Kd3 Kxh3 59. Ke2 59... Kg2 {(Le Pion 1924)} +0-1 diff --git a/test/database/1956-byrne-fischer.pgn b/test/database/1956-byrne-fischer.pgn new file mode 100644 index 0000000..3fe5a09 --- /dev/null +++ b/test/database/1956-byrne-fischer.pgn @@ -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. Nf3 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 -- cgit v1.2.3