public void ImportTest() { var f = new FileIO(Filepath, "err.log"); IEnumerable<ChessGame> gs = f.ImportPGN(); String[] pgn = new PGNParser().Generate(gs.ElementAt(0)).ToArray(); CollectionAssert.AreEqual(FirstGamePGN, pgn); }
public void ParseFullNoDelimeter() { var pgn = new String[] { "[Tag \"Value\"]", "1. a2 e4" }; var game = new PGNParser().Parse(pgn); Assert.AreEqual(2, game.MovesCount); Assert.AreEqual("Value", game.Info["Tag"]); }
public void CastlingUnderAttackTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"5q2/8/8/8/8/8/8/4K2R w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. O-O"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); }
public void CastlingPieceMovedTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"5q2/8/8/8/8/8/8/4K2R w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Rh7 Qb8 2. Rh1 Qa8 3. O-O"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); while (game.MakeMove()); }
public void ParseMovetextMultiline() { var pgn = new String[] { "[Tag \"Value\"]", "", "1. a2", "e4"}; var game = new PGNParser().Parse(pgn); Assert.AreEqual(2, game.MovesCount); Assert.AreEqual("Value", game.Info["Tag"]); }
public void BlackPawnTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/p7/8/8/8/8/8/8 b KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1... a6"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); Assert.AreEqual("8/8/p7/8/8/8/8/8 w KQkq - 0 2", game.State.ToString()); }
public void CaptureTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/4p3/3P4/8/8 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. d3xe4"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); Assert.AreEqual("8/8/8/8/4P3/8/8/8 b KQkq - 0 1", game.State.ToString()); }
public void BishopTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/7P/8/8/8/8/8/B7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Bh8"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); Assert.AreEqual("7B/7P/8/8/8/8/8/8 b KQkq - 0 1", game.State.ToString()); }
public void ParsePGN() { var pgn = new String[5]; pgn[0] = "[Event \"Some Event\"]"; pgn[1] = "[Site \"Some Site\"]"; pgn[2] = ""; pgn[3] = "1. e2e4 {Comment.} 1... e2e5 2. e2e6"; pgn[4] = "e2e7 {}"; var moves = new String[4]; moves[0] = "e2e4"; moves[1] = "e2e5"; moves[2] = "e2e6"; moves[3] = "e2e7"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); Assert.AreEqual("Some Event", game.Info["Event"]); for (int i = 0; i < 4; ++i) Assert.AreEqual(moves[i], ((ChessMove)game.Moves.ToList()[i]).Desc); }
public IEnumerable<ChessGame> ImportPGN() { var pgnParser = new PGNParser(); var lines = ReadFile(); var pgnGames = SeparateGames(lines); foreach (var game in pgnGames) { ChessGame result = null; try { result = pgnParser.Parse(game); } catch (Exception) { WriterToLog(game, ErrorFilepath); } if (result != null) yield return result; } }
public void ParsePGNFullMoveException() { var moves = new PGNParser().ParseMoves("1. e2q4 Qqe5", new AlgebraicNotation()).ToArray(); Assert.AreEqual("e2q4", (moves[0]).Desc); Assert.AreEqual("Qqe5", (moves[1]).Desc); }
public void ParsePGNFullMoveWithComments() { var moves = new PGNParser().ParseMoves("1. e2e4 {Comment.} 1... e2e5", new AlgebraicNotation()).ToArray(); Assert.AreEqual("e2e4", (moves[0]).Desc); Assert.AreEqual("e2e5", (moves[1]).Desc); }
private static void ExportSinglePGN(ChessGame game, TextWriter writer) { var pgn = new PGNParser(); foreach (var s in pgn.Generate(game)) writer.WriteLine(s); writer.WriteLine(""); }
public void JustParseMovetext() { string movetext = "1. a2 e4"; var moves = new PGNParser().ParseMoves(movetext).ToList(); Assert.AreEqual(2, moves.Count); }
public void QueenTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"7q/8/8/8/8/8/8/Q7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Qa8 Qa1"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); game.MakeMove(); Assert.AreEqual("Q7/8/8/8/8/8/8/q7 w KQkq - 0 2", game.State.ToString()); }
public void NotPossibleMoveTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/4P3/8/8/8 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. e8"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); }
public void MakeMoveTest() { String[] pgn = new String[4]; pgn[0] = "[Event \"Some Event\"]"; pgn[1] = "[FEN \"8/8/8/8/8/8/P7/8 w KQkq - 0 1\"]"; pgn[2] = ""; pgn[3] = "1. a2a3 {}"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); Assert.AreEqual("8/8/8/8/8/P7/8/8 b KQkq - 0 1", game.State.ToString()); }
public void KnightTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/3pp3/3P4/3N4/8/8/8 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Nxe6"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); Assert.AreEqual("8/8/3pN3/3P4/8/8/8/8 b KQkq - 0 1", game.State.ToString()); }
public void KingLengthTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/8/8/8/K7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Kc3"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); Assert.AreEqual("8/8/8/8/8/2K5/8/8 b KQkq - 0 1", game.State.ToString()); }
public void CheckmateMoveTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"q7/8/8/8/8/8/R7/K7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Rb2"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); }
public void EnPassantCaptureTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/4Pp2/8/8/8/8 w KQkq f6 0 1\"]"; pgn[1] = ""; pgn[2] = "2. e5xf6"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); game.MakeMove(); Assert.AreEqual("8/8/5P2/8/8/8/8/8 b KQkq f6 0 1", game.State.ToString()); }
public void ParseNoMovetext() { var pgn = new String[] { "[FEN \"1k6/1p6/p1p3b1/5q2/8/P7/1PP5/1K6 w KQkq - 0 42\"]" }; var game = new PGNParser().Parse(pgn); }
public void ParseComments() { string movetext = "1. a2 { comment } 1...e4 { comment 2 } 2. aa3"; var moves = new PGNParser().ParseMoves(movetext).ToList(); Assert.AreEqual(3, moves.Count); }
public void ParseTequilajazzzStartingFEN() { var pgn = new String[] { "[FEN \"1k6/1p6/p1p3b1/5q2/8/P7/1PP5/1K6 w KQkq - 0 42\"]", "1. a2 e4" }; var game = new PGNParser().Parse(pgn); Assert.AreEqual("1k6/1p6/p1p3b1/5q2/8/P7/1PP5/1K6 w KQkq - 0 42", game.State.ToString()); }
public void RollbackComplicatedTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"r7/8/8/8/8/8/8/B7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Bb2 Rb8 2. Bc3 Rc8"; var game = new PGNParser().Parse(pgn, new AlgebraicNotation()); while (game.MakeMove()) ; while (game.UndoMove()) ; Assert.AreEqual("r7/8/8/8/8/8/8/B7 w KQkq - 0 1", game.State.ToString()); }
public void PGNStartingPositionTest() { var pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/8/8/3P4/8 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. d2d3"; ChessGame game = new PGNParser().Parse(pgn, new AlgebraicNotation()); Assert.AreEqual("8/8/8/8/8/8/3P4/8 w KQkq - 0 1", game.State.ToString()); }
public void ParseOneMove() { string movetext = "1. a2"; var moves = new PGNParser().ParseMoves(movetext).ToList(); Assert.AreEqual(1, moves.Count); }
public void RookTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/8/8/8/R7 w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. Rh1"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); Assert.AreEqual("8/8/8/8/8/8/8/7R b KQkq - 0 1", game.State.ToString()); }
public void ParseTwoMoves() { string movetext = "1. a2 e4 2. aa3"; var moves = new PGNParser().ParseMoves(movetext).ToList(); Assert.AreEqual(3, moves.Count); }
public void WhiteCastlingKingsideTest() { String[] pgn = new String[3]; pgn[0] = "[FEN \"8/8/8/8/8/8/8/4K2R w KQkq - 0 1\"]"; pgn[1] = ""; pgn[2] = "1. O-O"; ChessGame game = new PGNParser().Parse(pgn); game.MakeMove(); Assert.AreEqual("8/8/8/8/8/8/8/5RK1 b kq - 0 1", game.State.ToString()); }