public void TestKingCanTakeOtherRookButNotOwnPawn()
        {
            AtomarChessGame game = new AtomarChessGame("3Rk2r/pp3ppp/n4n2/8/8/8/PPP2P1P/2K3NR b k - 0 1");

            Assert.True(game.IsValidMove(new Move("E8", "D8", Player.Black)));
            Assert.False(game.IsValidMove(new Move("E8", "F7", Player.Black)));
        }
        public void TestCastling2()
        {
            AtomarChessGame game = new AtomarChessGame("3Rk2r/pp3ppp/n4n2/8/8/8/PPP2P1P/2K3NR b k - 0 1");

            Assert.True(game.IsValidMove(new Move("E8", "G8", Player.Black)));
            Assert.True(game.IsValidMove(new Move("E8", "H8", Player.Black)));
        }
        public void TestCornerEndgame2()
        {
            Piece[][] board = new Piece[8][]
            {
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    qw, kb, o, o, o, o, o, o
                },
                new Piece[8] {
                    kw, qw, o, o, o, o, o, o
                }
            };

            AtomarChessGame game = new AtomarChessGame(board, Player.Black);

            Assert.False(game.IsInCheck(Player.Black));
            Assert.False(game.IsInCheck(Player.White));

            Assert.True(game.IsValidMove(new Move("B2", "B1", Player.Black)));
            Assert.True(game.IsValidMove(new Move("B2", "A2", Player.Black)));
            Assert.False(game.IsValidMove(new Move("B2", "A1", Player.Black)));

            game.MakeMove(new Move("B2", "B1", Player.Black), true);
            Assert.True(game.IsDraw());
            Assert.AreEqual(2, game.PiecesOnBoard.Count);
        }
        public void TestKingsNextToEachOther()
        {
            Piece[][] board = new Piece[8][]
            {
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, pb, nb, o, o, o
                },
                new Piece[8] {
                    o, o, o, pw, pb, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, nw, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, kb, o, kw, o, o, o
                }
            };

            AtomarChessGame game = new AtomarChessGame(board, Player.White);

            Assert.True(game.IsValidMove(new Move("E1", "D1", Player.White)));

            game.MakeMove(new Move("E1", "D1", Player.White), true);
            Assert.False(game.IsInCheck(Player.Black));
            Assert.False(game.IsInCheck(Player.White));
            Assert.False(game.IsValidMove(new Move("C1", "D1", Player.Black)));
            Assert.True(game.IsValidMove(new Move("C1", "D2", Player.Black)));
            Assert.True(game.IsValidMove(new Move("C1", "C2", Player.Black)));
        }
        public void TestCastling()
        {
            AtomarChessGame game = new AtomarChessGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");

            game.MakeMove(new Move("G1", "F3", Player.White), true);
            game.MakeMove(new Move("G8", "F6", Player.Black), true);
            game.MakeMove(new Move("G2", "G3", Player.White), true);
            game.MakeMove(new Move("G7", "G6", Player.Black), true);
            game.MakeMove(new Move("F1", "G2", Player.White), true);
            game.MakeMove(new Move("F8", "G7", Player.Black), true);
            Assert.True(game.IsValidMove(new Move("E1", "H1", Player.White)));
            var moves = game.GetValidMoves(Player.White);
            int ok    = 0;

            foreach (var move in moves)
            {
                if (move.OriginalPosition.ToString() == "E1" && (move.NewPosition.ToString() == "G1" || move.NewPosition.ToString() == "H1"))
                {
                    ok++;
                }
            }
            Assert.AreEqual(2, ok);
        }
        public void TestKingsImmuneToExplosions()
        {
            Piece[][] board = new Piece[8][]
            {
                new Piece[8] {
                    nb, nw, nb, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, kb, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, bb, o, o, o, rw
                },
                new Piece[8] {
                    o, o, o, kw, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                },
                new Piece[8] {
                    o, o, o, o, o, o, o, o
                }
            };

            AtomarChessGame game = new AtomarChessGame(board, Player.White);

            Assert.True(game.IsValidMove(new Move("H4", "D4", Player.White)));
            game.MakeMove(new Move("H4", "D4", Player.White), true);
            Assert.AreEqual("nNn5/8/8/3k4/8/3K4/8/8", game.GetFen().Split(" ")[0]);
        }