示例#1
0
 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);
 }
示例#2
0
        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"]);
        }
示例#3
0
        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();
        }
示例#4
0
        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());
        }
示例#5
0
        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"]);
        }
示例#6
0
        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());
        }
示例#7
0
        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());
        }
示例#8
0
        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());
        }
示例#9
0
        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);
        }
示例#10
0
        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;
            }
        }
示例#11
0
 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);
 }
示例#12
0
 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);
 }
示例#13
0
        private static void ExportSinglePGN(ChessGame game, TextWriter writer)
        {
            var pgn = new PGNParser();
            foreach (var s in pgn.Generate(game))
                writer.WriteLine(s);

            writer.WriteLine("");
        }
示例#14
0
 public void JustParseMovetext()
 {
     string movetext = "1. a2 e4";
     var moves = new PGNParser().ParseMoves(movetext).ToList();
     Assert.AreEqual(2, moves.Count);
 }
示例#15
0
        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());
        }
示例#16
0
        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();
        }
示例#17
0
        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());
        }
示例#18
0
        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());
        }
示例#19
0
        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());
        }
示例#20
0
        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();
        }
示例#21
0
        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());
        }
示例#22
0
        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);
        }
示例#23
0
 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);
 }
示例#24
0
        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());
        }
示例#25
0
        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());
        }
示例#26
0
        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());
        }
示例#27
0
 public void ParseOneMove()
 {
     string movetext = "1. a2";
     var moves = new PGNParser().ParseMoves(movetext).ToList();
     Assert.AreEqual(1, moves.Count);
 }
示例#28
0
        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());
        }
示例#29
0
 public void ParseTwoMoves()
 {
     string movetext = "1. a2 e4 2. aa3";
     var moves = new PGNParser().ParseMoves(movetext).ToList();
     Assert.AreEqual(3, moves.Count);
 }
示例#30
0
        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());
        }