コード例 #1
0
        public void GetMoves_WhitePawn_EnPassant()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.White);
            board.SetSpot(5, 1, ChessPiece.WhiteKing);
            board.SetSpot(5, 8, ChessPiece.BlackKing);

            // Black's pawn has doublemoved.
            board.SetSpot(3, 5, ChessPiece.BlackPawn);

            // White has two pawns that could capture it.
            board.SetSpot(2, 5, ChessPiece.WhitePawn);
            board.SetSpot(4, 5, ChessPiece.WhitePawn);

            board.SetEnPassantCaptureSquare(3, 6);

            var expectedMoves = new List <string>
            {
                "Ke1-d1",
                "Ke1-f1",
                "Ke1-d2",
                "Ke1-e2",
                "Ke1-f2",

                "Pb5-b6",
                "Pb5xc6", // En Passant Capture

                "Pd5xc6", // En Passant Capture
                "Pd5-d6"
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #2
0
        public void GetMoves_BlackPawn_PromotionCapture()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.Black);
            board.SetSpot(4, 2, ChessPiece.BlackPawn);
            board.SetSpot(3, 1, ChessPiece.WhiteKnight);
            board.SetSpot(5, 1, ChessPiece.WhiteKnight);

            var expectedMoves = new List <string>
            {
                "Pd2xc1=b",
                "Pd2xc1=n",
                "Pd2xc1=q",
                "Pd2xc1=r",
                "Pd2-d1=b",
                "Pd2-d1=n",
                "Pd2-d1=q",
                "Pd2-d1=r",
                "Pd2xe1=b",
                "Pd2xe1=n",
                "Pd2xe1=q",
                "Pd2xe1=r",
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #3
0
        public void GetMoves_BlackPawn_PromotionCapture_Blockers()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.Black);
            board.SetSpot(4, 2, ChessPiece.BlackPawn);
            board.SetSpot(3, 1, ChessPiece.WhiteKnight);
            board.SetSpot(5, 1, ChessPiece.BlackKnight);

            var expectedMoves = new List <string>
            {
                // Knight moves (don't forget!)
                "Ne1-c2",
                "Ne1-g2",
                "Ne1-d3",
                "Ne1-f3",

                "Pd2xc1=b",
                "Pd2xc1=n",
                "Pd2xc1=q",
                "Pd2xc1=r",
                "Pd2-d1=b",
                "Pd2-d1=n",
                "Pd2-d1=q",
                "Pd2-d1=r",
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #4
0
        public void GetMoves_Rook(ChessColor color)
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(color);
            board.SetSpot(4, 5, color == ChessColor.White ? ChessPiece.WhiteRook : ChessPiece.BlackRook);

            var expectedMoves = new List <string>
            {
                "Rd5-d1",
                "Rd5-d2",
                "Rd5-d3",
                "Rd5-d4",
                "Rd5-a5",
                "Rd5-b5",
                "Rd5-c5",
                "Rd5-e5",
                "Rd5-f5",
                "Rd5-g5",
                "Rd5-h5",
                "Rd5-d6",
                "Rd5-d7",
                "Rd5-d8"
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #5
0
        private void GetMoves_Bishop(ChessColor color)
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(color);
            board.SetSpot(4, 5, color == ChessColor.White ? ChessPiece.WhiteBishop : ChessPiece.BlackBishop);

            var expectedMoves = new List <string>
            {
                "Bd5-h1",
                "Bd5-a2",
                "Bd5-g2",
                "Bd5-b3",
                "Bd5-f3",
                "Bd5-c4",
                "Bd5-e4",
                "Bd5-c6",
                "Bd5-e6",
                "Bd5-b7",
                "Bd5-f7",
                "Bd5-a8",
                "Bd5-g8"
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #6
0
        public void GetMoves_BlackKnight_Corner()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.Black);
            board.SetSpot(1, 1, ChessPiece.BlackKnight);

            var expectedMoves = new List <string>
            {
                "Na1-c2",
                "Na1-b3"
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #7
0
        public void GetMoves_BlackPawn_PushCapture()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.Black);
            board.SetSpot(4, 5, ChessPiece.BlackPawn);
            board.SetSpot(3, 4, ChessPiece.WhitePawn);
            board.SetSpot(5, 4, ChessPiece.WhitePawn);

            var expectedMoves = new List <string>
            {
                "Pd5xc4",
                "Pd5-d4",
                "Pd5xe4",
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #8
0
        public void GetMoves_Checkmate()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.White);
            board.SetSpot(5, 1, ChessPiece.WhiteKing);
            board.SetSpot(5, 8, ChessPiece.BlackKing);
            board.SetSpot(1, 1, ChessPiece.BlackRook);
            board.SetSpot(2, 2, ChessPiece.BlackRook);

            var expectedMoves = new List <string>
            {
            };

            CheckPossibleMoves(board, expectedMoves);
            var isGameOver = board.IsGameOver(out int gameResult);

            Assert.IsTrue(isGameOver, "The game should be over, but it's not.");
            Assert.AreEqual(-1, gameResult, $"Black should be the winner, but they're not.  Expected result of -1 (Black wins), but result was {gameResult}.");
        }
コード例 #9
0
        private void GetMoves_Knight(ChessColor color)
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(color);
            board.SetSpot(4, 5, color == ChessColor.White ? ChessPiece.WhiteKnight : ChessPiece.BlackKnight);

            var expectedMoves = new List <string>
            {
                "Nd5-c3",
                "Nd5-e3",
                "Nd5-b4",
                "Nd5-f4",
                "Nd5-b6",
                "Nd5-f6",
                "Nd5-c7",
                "Nd5-e7"
            };

            CheckPossibleMoves(board, expectedMoves);
        }
コード例 #10
0
        public void GetMoves_WhiteQueen_SimpleCheck()
        {
            var board = new ChessBoardState();

            board.Clear();
            board.SetSideToMove(ChessColor.Black);
            board.SetSpot(2, 2, ChessPiece.WhiteQueen);
            board.SetSpot(1, 1, ChessPiece.WhiteKing);
            board.SetSpot(4, 4, ChessPiece.BlackKing);
            board.SetSpot(8, 8, ChessPiece.BlackQueen);

            var expectedMoves = new List <string>
            {
                "Kd4-d3",
                "Kd4-e3",
                "Kd4-c4",
                "Kd4-e4",
                "Kd4-c5",
                "Kd4-d5"
            };

            CheckPossibleMoves(board, expectedMoves);
        }