static ChessGame CreateGameFromPGN() { Console.WriteLine("please paste pgn (2 empty lines marks the end of the pgn)"); string pgn = ""; bool lastLineWasEmpty = false; while (true) { string line = Console.ReadLine(); if (lastLineWasEmpty) { if (line.Trim() == "") { break; } else { lastLineWasEmpty = false; } } else { if (line.Trim() == "") { lastLineWasEmpty = true; } } pgn += line + "\n"; } return(PGNParser.parse(pgn)); }
private static void ParseOldWay(string pgn) { var parser = new PGNParser(); var game = parser.GetGamesFromPGNAsync(pgn).Result.ToArray(); System.Console.WriteLine($"Parsed {game.Length} games."); }
public void TestParser3() { var data = File.ReadAllText("..\\..\\..\\TestData\\perle.pgn"); var parser = new PGNParser(); parser.ParsePGN(data); }
public void parseBody() { var pgn = @"[Event ""Rated Blitz game""] [Site ""https://lichess.org/kglGFcVo""] [Date ""????.??.??""] [Round ""?""] [White ""awser44""] [Black ""9804808497""] [Result ""0-1""] [BlackElo ""1360""] [BlackRatingDiff ""+17""] [ECO ""A20""] [FEN ""r2q1rk1/ppp1bppp/2n5/3p4/2PP2P1/1P2P3/1P1Q1PBP/R1B1K2R w KQ - 3 16""] [Opening ""English Opening: King's English Variation, Nimzowitsch-Flohr Variation""] [SetUp ""1""] [Termination ""Time forfeit""] [TimeControl ""420+0""] [UTCDate ""2014.04.27""] [UTCTime ""10:59:44""] [WhiteElo ""1466""] [WhiteRatingDiff ""-14""] 16. Bxd5 Bb4 17. O-O Bxd2 18. Bxd2 0-1"; var chess = PGNParser.parse(pgn); chess.UndoAll(); Assert.AreEqual("Bxd5", chess.Redo().san); Assert.AreEqual("Bb4", chess.Redo().san); Assert.AreEqual("O-O", chess.Redo().san); Assert.AreEqual("Bxd2", chess.Redo().san); Assert.AreEqual("Bxd2", chess.Redo().san); }
public void TestStripPGN1() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\BobbyFischer.pgn"); var output = new PGNParser().ParsePGN(data); Assert.AreEqual(1, output.Games.Count); }
public void TestGameEncoder() { var parser = new PGNParser(); var g = parser.ParsePGN(GameData); var game = g.Games[0]; var enc = GameEncoder.EncodeGame(game); }
private bool LoadFile(string fileName) { Debug.Log("Loading " + fileName); try { var lexer = new PGNLexer(new AntlrInputStream(new StreamReader(fileName))); var stream = new CommonTokenStream(lexer); var parser = new PGNParser(stream); parser.ErrorHandler = new BailErrorStrategy(); var context = parser.parse(); Debug.Log("Count games in PGN file: " + context.pgn_database().pgn_game().Length); var walker = ParseTreeWalker.Default; // listen stream and build game data var listener = new PGNListener(); walker.Walk(listener, context); // Copy moves from Listener to Game Manager //GameManager.Instance.GameData.Moves = new Dictionary<int, List<string>>(listener.Moves); GameManager.Instance.GameData.SetTags(listener.Tags); } catch (Exception e) { errorDialog.GetComponentInChildren <TextMeshProUGUI>().text = "File cannot be read. " + e.Message; errorDialog.gameObject.SetActive(true); return(false); } return(true); }
public void TestStripPGNMany() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\HumansVsComputers.pgn"); var output = new PGNParser().ParsePGN(data); Assert.AreEqual(28, output.Games.Count); }
public void parseHeaderFormat() { var format = PGNParser.parseHeaderFormat("[Event \"No event\"]"); Assert.AreEqual("Event", format.key); Assert.AreEqual("No event", format.value); }
public void TestParser2() { var data = File.ReadAllText("..\\..\\..\\TestData\\annotatedsetone.pgn"); var parser = new PGNParser(); parser.ParsePGN(data); }
/// <summary> /// Compiles an opening book out of one or more PGN input files. /// </summary> /// <param name="pgnFileNames">list of files to parse</param> /// <param name="moveCount">how many moves to store in the book, e.g. First 20 moves</param> /// <param name="skip"> /// only use every n-th game, e.g. 2 = use every other game, 3 = use every third game. /// Useful for limiting the output size if the input PGN is huge /// </param> /// <param name="callback">callback to take action for every game that is parsed</param> /// <param name="errorHandler">callback to handle errors</param> /// <returns>List of all parsed games, Encoded</returns> public static List <string> CompileBook( List <string> pgnFileNames, int moveCount = 20, int skip = 1, Action <string, string> callback = null, Action <string, PGNParserError> errorHandler = null) { int halfMoves = moveCount * 2; // +1 to round up var output = new List <string>(); foreach (var file in pgnFileNames) { try { Action <PGNParserError> errHandler = x => { errorHandler(file, x); }; Action <PGNGame> gameHandler = x => { var encoded = GameEncoder.EncodeGame(x, false); if (encoded.Length > halfMoves) { // make sure we don't cut off the promotion, in case tha last move is a promotion if (encoded[halfMoves] == '*') { encoded = encoded.Substring(0, halfMoves + 2); } else { encoded = encoded.Substring(0, halfMoves); } } string results = "-" + ((int)x.Results.Results).ToString(); var line = encoded + results; output.Add(line); if (callback != null) { callback(file, line); } }; var data = File.ReadAllText(file); var parser = new PGNParser(); var games = parser.ParsePGN(data, skip, gameHandler, errHandler); } catch (Exception e) { if (errorHandler != null) { errorHandler(file, new PGNParserError() { Exception = e, Message = "Unable to parse input file" }); } } } output = output.Where(x => !String.IsNullOrWhiteSpace(x)).OrderBy(x => x).ToList(); return(output); }
public void CountRepeatedPositionsKeepBoardAlive1() { // if you want to see the game import the game on lichess.org var pgn = @"[Event ""Shamkir Chess""] [Site ""chess24.com""] [Date ""2019.03.31""] [Round ""1""] [White ""Anand, Viswanathan""] [Black ""Navara, David""] [Result ""1/2-1/2""] [Board ""1""] [WhiteElo ""2779""] [WhiteTitle ""GM""] [WhiteCountry ""IND""] [WhiteFideId ""5000017""] [WhiteEloChange ""-1""] [BlackElo ""2739""] [BlackTitle ""GM""] [BlackCountry ""CZE""] [BlackFideId ""309095""] [BlackEloChange ""1""] 1. e4 {[%clk 1:59:57]} c5 {[%clk 1:59:56]} 2. Nf3 {[%clk 1:59:45]} d6 {[%clk 1:59:51]} 3. d4 {[%clk 1:59:39]} cxd4 {[%clk 1:59:45]} 4. Nxd4 {[%clk 1:59:34]} Nf6 {[%clk 1:59:39]} 5. Nc3 {[%clk 1:59:26]} a6 {[%clk 1:59:35]} 6. Bd3 {[%clk 1:59:16]} g6 {[%clk 1:54:35]} 7. f3 {[%clk 1:58:42]} Bg7 {[%clk 1:29:57]} 8. Be3 {[%clk 1:57:45]} Nc6 {[%clk 1:29:16]} 9. Qd2 {[%clk 1:55:46]} Nxd4 {[%clk 1:19:30]} 10. Bxd4 {[%clk 1:55:22]} Be6 {[%clk 1:19:22]} 11. g4 {[%clk 1:36:58]} b5 {[%clk 1:06:38]} 12. h4 {[%clk 1:28:04]} Qa5 {[%clk 0:56:17]} 13. a3 {[%clk 1:16:31]} h6 {[%clk 0:53:06]} 14. O-O-O {[%clk 1:10:07]} Rb8 {[%clk 0:51:16]} 15. g5 {[%clk 1:06:02]} Nh5 {[%clk 0:50:45]} 16. Bxg7 {[%clk 1:05:53]} Nxg7 {[%clk 0:50:36]} 17. gxh6 {[%clk 1:05:48]} Nh5 {[%clk 0:50:27]} 18. Qg5 {[%clk 1:05:10]} f6 {[%clk 0:46:26]} 19. Qxg6+ {[%clk 0:59:49]} Bf7 {[%clk 0:46:13]} 20. Qg1 {[%clk 0:59:27]} b4 {[%clk 0:45:51]} 21. axb4 {[%clk 0:50:08]} Qxb4 {[%clk 0:44:35]} 22. Kd2 {[%clk 0:48:00]} Nf4 {[%clk 0:34:46]} 23. Qe3 {[%clk 0:44:29]} Nxd3 {[%clk 0:28:41]} 24. Qxd3 {[%clk 0:39:57]} Rxh6 {[%clk 0:28:18]} 25. Qxa6 {[%clk 0:35:14]} Kf8 {[%clk 0:16:27]} 26. Ra1 {[%clk 0:28:43]} d5 {[%clk 0:11:26]} 27. Ra4 {[%clk 0:24:41]} Qc5 {[%clk 0:11:18]} 28. exd5 {[%clk 0:21:08]} Rxb2 {[%clk 0:08:00]} 29. Qa7 {[%clk 0:17:36]} Qd6 {[%clk 0:02:30]} 30. Qe3 {[%clk 0:17:04]} Rg6 {[%clk 0:02:08]} 31. Ra8+ {[%clk 0:16:02]} Kg7 {[%clk 0:01:40]} 32. Kc1 {[%clk 0:15:36]} Qb4 {[%clk 0:00:52]} 33. Ra4 {[%clk 0:10:47]} Rb1+ {[%clk 0:00:51]} 34. Nxb1 {[%clk 0:10:37]} Qxa4 {[%clk 0:00:50]} 35. Qxe7 {[%clk 0:07:18]} Rg2 {[%clk 0:00:12]} 36. Qe4 {[%clk 0:05:27]} Qa7 {[%clk 0:00:10]} 37. Re1 {[%clk 0:03:31]} Rg1 {[%clk 0:00:09]} 38. Nc3 {[%clk 0:01:07]} Qa1+ {[%clk 0:00:04]} 39. Kd2 {[%clk 0:00:49]} Rg2+ {[%clk 0:00:03]} 40. Re2 {[%clk 1:00:29]} Rg1 {[%clk 1:00:01]} 41. Qe7 {[%clk 0:50:10]} Rd1+ {[%clk 0:59:32]} 1/2-1/2"; var game = PGNParser.parse(pgn); // replays the game Assert.AreEqual("8/4Qbk1/5p2/3P4/7P/2N2P2/2PKR3/q2r4 w - - 13 42", game.FEN); game.board.RepeatedPositions(game.moveHistory()); Assert.AreEqual("8/4Qbk1/5p2/3P4/7P/2N2P2/2PKR3/q2r4 w - - 13 42", game.FEN); game.Winner(); Assert.AreEqual("8/4Qbk1/5p2/3P4/7P/2N2P2/2PKR3/q2r4 w - - 13 42", game.FEN); }
public void CountRepeatedPositionsKeepBoardAlive3() { // if you want to see the game import the game on lichess.org var pgn = @"[Event ""Shamkir Chess""] [Site ""chess24.com""] [Date ""2019.03.31""] [Round ""1""] [White ""Radjabov, Teimour""] [Black ""Carlsen, Magnus""] [Result ""1/2-1/2""] [Board ""3""] [WhiteElo ""2756""] [WhiteTitle ""GM""] [WhiteCountry ""AZE""] [WhiteFideId ""13400924""] [WhiteEloChange ""1""] [BlackElo ""2845""] [BlackTitle ""GM""] [BlackCountry ""NOR""] [BlackFideId ""1503014""] [BlackEloChange ""-1""] 1. e4 {[%clk 1:59:59]} e5 {[%clk 1:59:52]} 2. Nf3 {[%clk 1:59:52]} Nc6 {[%clk 1:59:45]} 3. Bc4 {[%clk 1:58:32]} Nf6 {[%clk 1:59:34]} 4. d3 {[%clk 1:58:28]} Be7 {[%clk 1:59:07]} 5. O-O {[%clk 1:56:56]} O-O {[%clk 1:58:53]} 6. h3 {[%clk 1:55:28]} d6 {[%clk 1:53:14]} 7. a4 {[%clk 1:54:55]} a5 {[%clk 1:43:32]} 8. Nbd2 {[%clk 1:51:21]} Nd7 {[%clk 1:35:24]} 9. Re1 {[%clk 1:49:21]} Nb6 {[%clk 1:29:28]} 10. Bb3 {[%clk 1:48:09]} Kh8 {[%clk 1:28:33]} 11. c3 {[%clk 1:41:55]} f5 {[%clk 1:27:42]} 12. exf5 {[%clk 1:35:09]} Bxf5 {[%clk 1:26:55]} 13. Nf1 {[%clk 1:32:50]} Bg6 {[%clk 1:17:04]} 14. Ng3 {[%clk 1:30:26]} Bf6 {[%clk 1:11:04]} 15. Ne4 {[%clk 1:24:11]} d5 {[%clk 1:03:35]} 16. Nxf6 {[%clk 1:19:52]} Qxf6 {[%clk 1:03:20]} 17. Bg5 {[%clk 1:18:14]} Qf5 {[%clk 0:48:04]} 18. Qd2 {[%clk 1:16:51]} Rae8 {[%clk 0:45:32]} 19. Be3 {[%clk 1:07:42]} Bh5 {[%clk 0:41:21]} 20. Bd1 {[%clk 1:01:25]} Qd7 {[%clk 0:36:20]} 21. Bxb6 {[%clk 0:54:49]} cxb6 {[%clk 0:36:11]} 22. Qg5 {[%clk 0:52:58]} Qf7 {[%clk 0:33:17]} 23. Qh4 {[%clk 0:49:06]} Bg6 {[%clk 0:32:15]} 24. Bb3 {[%clk 0:43:29]} Qd7 {[%clk 0:20:26]} 25. Qg3 {[%clk 0:42:18]} d4 {[%clk 0:16:01]} 26. Nxe5 {[%clk 0:37:09]} Nxe5 {[%clk 0:15:48]} 27. Rxe5 {[%clk 0:37:06]} dxc3 {[%clk 0:15:09]} 28. Rxe8 {[%clk 0:35:28]} Rxe8 {[%clk 0:14:58]} 29. bxc3 {[%clk 0:35:26]} Qxd3 {[%clk 0:14:41]} 30. Qxd3 {[%clk 0:28:05]} Bxd3 {[%clk 0:14:39]} 31. Rd1 {[%clk 0:27:52]} Be4 {[%clk 0:13:31]} 32. Rd6 {[%clk 0:26:02]} Bc6 {[%clk 0:13:04]} 33. Bd5 {[%clk 0:24:31]} Bxd5 {[%clk 0:12:58]} 34. Rxd5 {[%clk 0:24:29]} Re1+ {[%clk 0:12:47]} 35. Kh2 {[%clk 0:24:27]} h6 {[%clk 0:12:37]} 36. Rd7 {[%clk 0:23:42]} Rc1 {[%clk 0:12:18]} 37. Rxb7 {[%clk 0:23:37]} Rxc3 {[%clk 0:12:14]} 38. Rxb6 {[%clk 0:23:33]} Rc4 {[%clk 0:12:08]} 39. Ra6 {[%clk 0:23:07]} Rxa4 {[%clk 0:12:04]} 40. f4 {[%clk 1:23:00]} Rxf4 {[%clk 1:11:54]} 41. Rxa5 {[%clk 1:22:57]} 1/2-1/2"; var game = PGNParser.parse(pgn); // replays the game Assert.AreEqual("7k/6p1/7p/R7/5r2/7P/6PK/8 b - - 0 41", game.FEN); game.board.RepeatedPositions(game.moveHistory()); Assert.AreEqual("7k/6p1/7p/R7/5r2/7P/6PK/8 b - - 0 41", game.FEN); game.Winner(); Assert.AreEqual("7k/6p1/7p/R7/5r2/7P/6PK/8 b - - 0 41", game.FEN); }
public static void TestParsingNagSymbols() { var parser = new PGNParser(); var game = parser.GetGamesFromPGNAsync(PGNResources.MoveNagSymbol).Result; var formatter = new PgnFormatter <Move>(new PGNFormatterOptions()); formatter.BuildPgn(game.First()); }
public unsafe void TestMakeUnmakePromotion() { string data = "1. e4 d5 2. exd5 Nf6 3. Bb5+ c6 4. dxc6 Qb6 5. Bf1 Qb4 6. cxb7 Kd7 7. bxc8=Q+ Kd6 8. Qh3 Qb5 9. Qxh7 Qb6 10. Qxh8 "; string finalState = "rn3b1Q/p3ppp1/1q1k1n2/8/8/8/PPPP1PPP/RNBQKBNR b KQ - 0 10"; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); GenericGameTest(moves, finalState); }
public unsafe void TestMakeUnmakePGNKasparovDeepBlue() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\HumansVsComputers.pgn"); string finalState = "4r3/6P1/2p2P1k/1p6/pP2p1R1/P1B5/2P2K2/3r4 b - - 0 45"; var games = new PGNParser().ParsePGN(data); var game = games.Games[0]; var moves = game.GetMainVariation(); GenericGameTest(moves, finalState); }
public void TestMainVariation() { var parser = new PGNParser(); var g = parser.ParsePGN(GameData); var game = g.Games[0]; var variation = game.GetMainVariation(); Assert.IsTrue(variation.All(x => x is PGNMove)); Assert.IsTrue(variation.Count > 0); }
public unsafe void TestMakeUnmakePGNKasparovX3DFritz() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\HumansVsComputers.pgn"); string finalState = "r6k/1r1qnppp/NPp2n1b/2Pp4/3Pp3/1RB1P1PP/R1Q2P2/K4B2 b - - 4 45"; var games = new PGNParser().ParsePGN(data).Games; var game = games[games.Count - 2]; var moves = game.GetMainVariation(); GenericGameTest(moves, finalState); }
public unsafe void TestMakeUnmakePGNFischer() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\BobbyFischer.pgn"); string finalState = "1Q6/5pk1/2p3p1/1p2N2p/1b5P/1bn5/2r3P1/2K5 w - - 16 42"; var games = new PGNParser().ParsePGN(data); var game = games.Games[0]; var moves = game.GetMainVariation(); GenericGameTest(moves, finalState); }
public unsafe void TestMakeUnmakePGNKasparovX3D() { string data = System.IO.File.ReadAllText("..\\..\\..\\TestData\\HumansVsComputers.pgn"); string finalState = "3Q4/6pk/7p/8/8/8/r4qPP/3R3K w - - 2 28"; var games = new PGNParser().ParsePGN(data).Games; var game = games.Last(); var moves = game.GetMainVariation(); GenericGameTest(moves, finalState); }
public void TestABN1() { var board = new Board(true); string data = "1. e4 e5"; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); Assert.AreEqual(2, moves.Count); Assert.AreEqual(12, moves[0].From); Assert.AreEqual(12 + 16, moves[0].To); Assert.AreEqual(52, moves[1].From); Assert.AreEqual(52 - 16, moves[1].To); }
private static void Main(string[] args) { var parsePgn = new PGNParser(); //parsePgn.ProgressUpdate += OnProgressUpdated; var sw = new Stopwatch(); var pgnDb = Encoding.UTF8.GetString(PGNResources.talLarge); sw.Start(); var games = parsePgn.GetGamesFromPGNAsync(pgnDb).Result; sw.Stop(); Console.WriteLine($"Parsed {games.Count()} games in {sw.ElapsedMilliseconds} ms."); }
public static Game[] TestParsing(GameDatabase db) { var parser = new PGNParser(); parser.UpdateProgress += UpdateProgress; var dbToUse = GetDbFromEnum(db); var timer = new Stopwatch(); timer.Start(); var games = parser.GetGamesFromPGNAsync(dbToUse).Result.ToArray(); timer.Stop(); System.Console.WriteLine($"Parsing Finished {games.Length} games in {timer.ElapsedMilliseconds} ms."); return(games); }
public void CountRepeatedPositionsKeepBoardAlive4() { // if you want to see the game import the game on lichess.org var pgn = @"[Event ""Shamkir Chess""] [Site ""chess24.com""] [Date ""2019.03.31""] [Round ""1""] [White ""Karjakin, Sergey""] [Black ""Ding, Liren""] [Result ""1/2-1/2""] [Board ""4""] [WhiteElo ""2753""] [WhiteTitle ""GM""] [WhiteCountry ""RUS""] [WhiteFideId ""14109603""] [WhiteEloChange ""1""] [BlackElo ""2812""] [BlackTitle ""GM""] [BlackCountry ""CHN""] [BlackFideId ""8603677""] [BlackEloChange ""-1""] 1. e4 {[%clk 1:59:58]} e5 {[%clk 1:59:54]} 2. Nf3 {[%clk 1:59:49]} Nc6 {[%clk 1:59:51]} 3. Bc4 {[%clk 1:59:43]} Nf6 {[%clk 1:59:33]} 4. d3 {[%clk 1:59:38]} Bc5 {[%clk 1:59:29]} 5. c3 {[%clk 1:59:34]} d6 {[%clk 1:58:38]} 6. O-O {[%clk 1:59:25]} O-O {[%clk 1:58:26]} 7. Re1 {[%clk 1:59:10]} a5 {[%clk 1:56:39]} 8. Bg5 {[%clk 1:58:31]} h6 {[%clk 1:55:56]} 9. Bh4 {[%clk 1:58:23]} g5 {[%clk 1:55:53]} 10. Bg3 {[%clk 1:58:18]} Nh7 {[%clk 1:55:23]} 11. d4 {[%clk 1:57:57]} Bb6 {[%clk 1:55:17]} 12. dxe5 {[%clk 1:57:48]} h5 {[%clk 1:55:12]} 13. h4 {[%clk 1:57:35]} Bg4 {[%clk 1:55:06]} 14. Nbd2 {[%clk 1:57:04]} Nxe5 {[%clk 1:54:32]} 15. Be2 {[%clk 1:56:57]} Nxf3+ {[%clk 1:50:45]} 16. Nxf3 {[%clk 1:56:49]} Re8 {[%clk 1:49:28]} 17. Qd2 {[%clk 1:53:42]} Bxf3 {[%clk 1:47:42]} 18. Bxf3 {[%clk 1:53:21]} gxh4 {[%clk 1:47:38]} 19. Bf4 {[%clk 1:53:13]} Qf6 {[%clk 1:46:36]} 20. Bxh5 {[%clk 1:52:36]} Qg7 {[%clk 1:46:27]} 21. Bh6 {[%clk 1:45:22]} Qf6 {[%clk 1:44:12]} 22. Bf4 {[%clk 1:41:49]} Qg7 {[%clk 1:44:05]} 23. Bh6 {[%clk 1:38:02]} Qf6 {[%clk 1:43:58]} 24. Bf4 {[%clk 1:37:56]} Qg7 {[%clk 1:43:52]} 1/2-1/2"; var game = PGNParser.parse(pgn); // replays the game Assert.AreEqual("r3r1k1/1pp2pqn/1b1p4/p6B/4PB1p/2P5/PP1Q1PP1/R3R1K1 w - - 9 25", game.FEN); game.board.RepeatedPositions(game.moveHistory()); Assert.AreEqual("r3r1k1/1pp2pqn/1b1p4/p6B/4PB1p/2P5/PP1Q1PP1/R3R1K1 w - - 9 25", game.FEN); game.Winner(); Assert.AreEqual("r3r1k1/1pp2pqn/1b1p4/p6B/4PB1p/2P5/PP1Q1PP1/R3R1K1 w - - 9 25", game.FEN); }
public void TestABNFullgame1_1() { // test almost an entire game (excl. promotion) var board = new Board(true); string data = "1.e4 c5 2.Nf3 g6 3.c3 Bg7 4.d4 cxd4 5.cxd4 d5 6.exd5 Nf6 7.Bb5+ Nbd7 8.d6 exd6 9.Qe2+ Qe7 10.Bf4 Qxe2+ 11.Kxe2 d5 12.Rc1 O-O 13.Nbd2 a6 14.Bd3 Re8+ 15.Kf1 Nf8 16.Be5 Ne6 17.g3 Bd7 18.Nb3 Ne4 19.Bxg7 Kxg7 20.Nc5 N4xc5 21.dxc5 a5 22.Rc2 Rec8 23.Rac1 Rc7 24.Ne5 Be8 25.c6 b6 26.Nd7 Bxd7 27.cxd7 Rxd7 28.Bb5 Rd6 29.Rc8 Rxc8 30.Rxc8 Kf6 31.h4 h5 32.Ke1 Nc5 33.Ke2 Re6+ 34.Kf3 Ke5 35.Rc7 Rf6+ 36.Ke2 Ne4 37.f4+ Kd4 38.Kf3 Nd6 39.Bd7 Nc4 40.b3 Nd2+ 41.Ke2 Ne4 42.Kf3 Nc5 43.Be8 Kc3 44.Rxf7 Re6 45.Rf8 d4 46.f5 gxf5 47.Bxh5 Re3+ 48.Kg2 Re5 49.Bf3 d3 50.h5 Re6 51.Rxf5 d2 52.Rd5 Nd3 53.Bg4 Re4 54.h6 Rxg4"; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); } var board2 = Notation.ReadFEN("8/8/1p5P/p2R4/6r1/1Pkn2P1/P2p2K1/8 w - - 0 55"); Assert.IsTrue(board2.State.SequenceEqual(board.State)); }
public void TestABN4() { // Tests castling both kingside var board = new Board(true); string data = "1.e4 e5 2.Bd3 Bd6 3.Nf3 Nf6 4.O-O O-O "; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); } var board2 = Notation.ReadFEN("rnbq1rk1/pppp1ppp/3b1n2/4p3/4P3/3B1N2/PPPP1PPP/RNBQ1RK1 w -"); Assert.IsTrue(board2.State.SequenceEqual(board.State)); Assert.AreEqual(Color.White, board.PlayerTurn); }
public void TestABN2() { // Tests knights and bishops moving var board = new Board(true); string data = "1.e4 Nf6 2.Nc3 c6 3.Bc4 d5 "; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); } var board2 = Notation.ReadFEN("rnbqkb1r/pp2pppp/2p2n2/3p4/2B1P3/2N5/PPPP1PPP/R1BQK1NR w KQkq"); Assert.IsTrue(board2.State.SequenceEqual(board.State)); Assert.AreEqual(Color.White, board.PlayerTurn); }
public void TestABN5() { // Tests castling both queenside var board = new Board(true); string data = "1.e4 c5 2.Nf3 d6 3.d4 Nf6 4.dxc5 Qa5 5.c3 Qxc5 6.Bd3 g6 7.Be3 Qc7 8.Na3 Be6 9.Qd2 Nc6 10.O-O-O O-O-O "; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); } var board2 = Notation.ReadFEN("2kr1b1r/ppq1pp1p/2npbnp1/8/4P3/N1PBBN2/PP1Q1PPP/2KR3R w -"); Assert.IsTrue(moves[6].Capture); Assert.IsTrue(moves[9].Capture); Assert.IsTrue(board2.State.SequenceEqual(board.State)); Assert.AreEqual(Color.White, board.PlayerTurn); }
public void TestABNFullgame2() { // end results var board = new Board(true); string data = "1.e4 e5 2.Nf3 Nf6 3.Nxe5 d6 4.Nf3 Nxe4 5.d4 d5 6.Bd3 Nc6 7.O-O Be7 8.c4 Nb4 9.Be2 O-O 10.Nc3 Bf5 11.a3 Nxc3 12.bxc3 Nc6 13.Re1 Re8 14.Bf4 dxc4 15.Bxc4 Bd6 16.Rxe8+ Qxe8 17.Ng5 Bg6 18.Bxd6 cxd6 19.h4 Qe7 20.Qg4 h6 21.Nf3 Qe4 22.Qg3 Rd8 23.Re1 Qf5 24.Ba2 Qf6 25.Nh2 Qf5 26.Ng4 Kf8 27.Bb1 Qh5 28.Qf4 Bxb1 29.Rxb1 Rd7 30.Ne3 Ne7 31.g3 Nd5 32.Nxd5 Qxd5 33.Re1 Re7 34.Rxe7 Kxe7 35.Qe3+ Qe6 1/2"; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); if (move.Promotion != 0) { bool promoted = board.Promote(move.To, move.Promotion); Assert.IsTrue(promoted); } } var board2 = Notation.ReadFEN("8/pp2kpp1/3pq2p/8/3P3P/P1P1Q1P1/5P2/6K1 w - - 0 36"); Assert.IsTrue(board2.State.SequenceEqual(board.State)); }
public void TestABNFullgame1_3() { // end results var board = new Board(true); string data = "1.e4 c5 2.Nf3 g6 3.c3 Bg7 4.d4 cxd4 5.cxd4 d5 6.exd5 Nf6 7.Bb5+ Nbd7 8.d6 exd6 9.Qe2+ Qe7 10.Bf4 Qxe2+ 11.Kxe2 d5 12.Rc1 O-O 13.Nbd2 a6 14.Bd3 Re8+ 15.Kf1 Nf8 16.Be5 Ne6 17.g3 Bd7 18.Nb3 Ne4 19.Bxg7 Kxg7 20.Nc5 N4xc5 21.dxc5 a5 22.Rc2 Rec8 23.Rac1 Rc7 24.Ne5 Be8 25.c6 b6 26.Nd7 Bxd7 27.cxd7 Rxd7 28.Bb5 Rd6 29.Rc8 Rxc8 30.Rxc8 Kf6 31.h4 h5 32.Ke1 Nc5 33.Ke2 Re6+ 34.Kf3 Ke5 35.Rc7 Rf6+ 36.Ke2 Ne4 37.f4+ Kd4 38.Kf3 Nd6 39.Bd7 Nc4 40.b3 Nd2+ 41.Ke2 Ne4 42.Kf3 Nc5 43.Be8 Kc3 44.Rxf7 Re6 45.Rf8 d4 46.f5 gxf5 47.Bxh5 Re3+ 48.Kg2 Re5 49.Bf3 d3 50.h5 Re6 51.Rxf5 d2 52.Rd5 Nd3 53.Bg4 Re4 54.h6 Rxg4"; data += " 55.h7 d1Q 56.h8Q+ Kc2 57.Qc8+ Kd2 58.Qf8 Qe2+ 59.Kh3 Re4 60.Qf6 Qg4+ 0-1"; var game = new PGNParser().ParseGame(data); var moves = game.GetMainVariation(); foreach (var move in moves) { board.Move(move.From, move.To, true); if (move.Promotion != 0) { bool promoted = board.Promote(move.To, move.Promotion); Assert.IsTrue(promoted); } } var board2 = Notation.ReadFEN("8/8/1p3Q2/p2R4/4r1q1/1P1n2PK/P2k4/8 w - - 0 61"); Assert.IsTrue(board2.State.SequenceEqual(board.State)); }
public void Load(TextReader reader) { games.Clear (); viewer.StartProgress (); viewer.ProgressBar.PulseStep = 0.01; PGNParser parser = new PGNParser (reader); parser.Parse (gameloader); viewer.StopProgress (); viewer.LoadGames (Games); }
public EcoDbLoader(Stream filestream) { TextReader reader = new StreamReader (filestream); PGNParser parser = new PGNParser (reader); PGNGameLoader loader = new PGNGameLoader (); db = new OpeningsDb (); loader.GameLoaded += OnGameLoaded; parser.Parse (loader); reader.Close (); }