예제 #1
0
            public void ShouldUpdatePlyAfterMakingMove()
            {
                const string initialBoardSetup = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
                var          board             = new Game.Board();

                board.ParseFen(initialBoardSetup);

                board.GenerateMoves();
                board.MakeMove(board.Moves[0][0]);
                board.Ply.Should().Be(1);
            }
예제 #2
0
            public void ShouldSetInitialMoveCorrectly()
            {
                const string initialBoardSetup = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
                var          board             = new Game.Board();

                board.ParseFen(initialBoardSetup);

                board.GenerateMoves();
                board.MakeMove(board.Moves[0][0]);
                board.Moves[0][0].ToSquare.Should().Be(41);
            }
예제 #3
0
            public void ShouldSetTheWhiteKingRookSquareWhenItIsAWhiteKingSideCastle()
            {
                const string initialBoardSetupForWhiteKingSideCastle = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQK2R w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteKingSideCastle);
                var m = new Move(new King(), 27, true);

                board.MakeMove(m);
                board.Squares[28].Type.Should().Be(PieceType.Empty);
            }
예제 #4
0
            public void ShouldSetTheBlackQueenRookSquareWhenItIsABlackQueenSideCastle()
            {
                const string initialBoardSetupForWhiteQueenSideCastle = "rnbqk2r/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteQueenSideCastle);
                var m = new Move(new King(), 97, true);

                board.MakeMove(m);
                board.Squares[98].Type.Should().Be(PieceType.Empty);
            }
예제 #5
0
            public void ShouldMoveTheWhiteQueenRookWhenItIsAWhiteQueenSideCastle()
            {
                const string initialBoardSetupForWhiteQueenSideCastle = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/R3KBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteQueenSideCastle);
                var m = new Move(new King(), 23, true);

                board.MakeMove(m);
                board.Squares[24].Type.Should().Be(PieceType.Rook);
            }
예제 #6
0
            public void ShouldSwitchSide()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 31, Color = Color.White
                }, 41);

                board.MakeMove(m);
                board.SideToMove.Should().Be(Color.Black);
            }
예제 #7
0
            public void ShouldNotPromoteIfThereIsNoPromotion()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 31, Color = Color.White
                }, 41);

                board.MakeMove(m);
                board.Squares[41].Type.Should().Be(PieceType.Pawn);
            }
예제 #8
0
            public void ShouldGenerateTwentyInitialReplies()
            {
                const string initialBoardSetup = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
                var          board             = new Game.Board();

                board.ParseFen(initialBoardSetup);

                board.GenerateMoves();
                board.MakeMove(board.Moves[0][0]);
                board.GenerateMoves();
                board.Moves[board.Ply].Count.Should().Be(20);
            }
예제 #9
0
            public void ShouldReturnFalseIfTheKingIsInCheck()
            {
                const string blackKingAttackedAfterRookMove = "3k4/3r4/8/3R4/8/8/8/4K3 b KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(blackKingAttackedAfterRookMove);
                var m = new Move(new Rook {
                    Square = 84, Color = Color.Black
                }, 86);

                board.MakeMove(m).Should().BeFalse();
            }
예제 #10
0
            public void ShouldUpdateThePly()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.MakeMove(m);

                board.Ply.Should().Be(1);
            }
예제 #11
0
            public void ShouldUpdateTheCastlePermissionsIfTheBlackKingRookHasMoved()
            {
                const string initialBoardSetupForWhiteRookMove = "rnbqkbnr/ppppppp1/8/8/8/8/PPPPPPPP/RBNQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteRookMove);
                var m = new Move(new Rook {
                    Color = Color.Black, Square = 98
                }, 88);

                board.MakeMove(m);
                ((int)(board.CastlePermission & CastlePermissions.BlackKing)).Should().Be(0);
            }
예제 #12
0
            public void ShouldHashOutTheEnPassantKeyIfItIsSet()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var initialPosKey = board.PositionKey;

                board.EnPassantSquare = 41;
                var m = new Move(new Pawn(), 23);

                board.MakeMove(m);
                board.PositionKey.Should().NotBe(initialPosKey);
            }
예제 #13
0
            public void ShouldUpdateTheFifyMoveCountInHistoryEntry()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.MakeMove(m);

                board.History[0].FiftyMoveCount.Should().Be(board.FiftyMoveCount);
            }
예제 #14
0
            public void ShouldUpdateTheEnPassantSquareHistoryEntry()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.MakeMove(m);

                board.History[0].EnPassantSquare.Should().Be(board.EnPassantSquare);
            }
예제 #15
0
            public void ShouldUpdateTheCastlePermissionsInHistoryEntry()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.MakeMove(m);

                board.History[0].CastlePermissions.Should().Be(board.CastlePermission);
            }
예제 #16
0
            public void ShouldUpdateTheCastlePermissionsIfTheWhiteQueenRookHasMoved()
            {
                const string initialBoardSetupForWhiteRookMove = "rnbqkbnr/pppppppp/8/8/8/8/1PPPPPPP/RBNQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteRookMove);
                var m = new Move(new Rook {
                    Color = Color.White, Square = 21
                }, 22);

                board.MakeMove(m);
                ((int)(board.CastlePermission & CastlePermissions.WhiteQueen)).Should().Be(0);
            }
예제 #17
0
            public void ShouldAddANewEntryToHistory()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.MakeMove(m);

                board.History.Count.Should().Be(1);
            }
예제 #18
0
            public void ShouldPromoteIfThereIsAPromotion()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 81, Color = Color.White
                }, 91, new Queen {
                    Square = 91
                });

                board.MakeMove(m);
                board.Squares[91].Type.Should().Be(PieceType.Queen);
            }
예제 #19
0
            public void ShouldChangePositionKeyIfTheBlackKingRookMoves()
            {
                const string initialBoardSetupForWhiteRookMove = "rnbqkbnr/ppppppp1/8/8/8/8/1PPPPPPP/RBNQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteRookMove);
                var initialPosKey = board.PositionKey;
                var m             = new Move(new Rook {
                    Color = Color.White, Square = 98
                }, 88);

                board.MakeMove(m);
                board.PositionKey.Should().NotBe(initialPosKey);
            }
예제 #20
0
            public void ShouldHasInTheNewSide()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var oldPosition = board.PositionKey;
                var m           = new Move(new Pawn {
                    Square = 31, Color = Color.White
                }, 31);

                board.MakeMove(m);

                board.PositionKey.Should().NotBe(oldPosition);
            }
예제 #21
0
            public void ShouldSetTheEnPassantSquareIfItIsABlackPawnStartMove()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 81, Color = Color.Black
                }, 61)
                {
                    IsPawnStartMove = true
                };

                board.MakeMove(m);
                board.EnPassantSquare.Should().Be(71);
            }
예제 #22
0
            public void ShouldResetTheFiftyMoveCountIfItIsAPawnMove()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 22
                }, 23);

                board.FiftyMoveCount = 1;

                board.MakeMove(m);

                board.FiftyMoveCount.Should().Be(0);
            }
예제 #23
0
            public void ShouldUpdateThePositionKeyWhenItItAnEnPassantMove()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 81, Color = Color.Black
                }, 61)
                {
                    IsPawnStartMove = true
                };
                var originalPositionKey = board.PositionKey;

                board.MakeMove(m);
                originalPositionKey.Should().NotBe(board.PositionKey);
            }
예제 #24
0
            public void ShouldClearTheWhitePawnWhenItIsABlackEnPassantCapture()
            {
                const string initialBoardSetupForEnPassantCaptureWhiteToMove = "rnbqkbnr/pp1ppppp/8/8/2pP4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForEnPassantCaptureWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 53, Color = Color.Black
                }, 44)
                {
                    IsEnPassantCapture = true
                };

                board.Squares[54].Type.Should().Be(PieceType.Pawn);
                board.MakeMove(m);

                board.Squares[54].Type.Should().Be(PieceType.Empty);
            }
예제 #25
0
            public void ShouldResetThePositionKeyAfterCastling()
            {
                const string initialBoardSetupWhiteToMove = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/R3KBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupWhiteToMove);
                var m = new Move(new King {
                    Square = 25, Color = Color.White
                }, 23, true);

                var initialPositon = board.PositionKey;

                board.MakeMove(m);

                board.TakeMove();

                board.PositionKey.Should().Be(initialPositon);
            }
예제 #26
0
            public void ShouldGenerateFourHundredMovesAtDepthOneFromInitialPosition()
            {
                const string initialBoardSetup = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
                var          board             = new Game.Board();

                board.ParseFen(initialBoardSetup);

                board.GenerateMoves();
                for (int count = 0; count < board.Moves[board.Ply].Count; count++)
                {
                    if (board.MakeMove(board.Moves[0][count]))
                    {
                        board.GenerateMoves();
                        board.TakeMove();
                    }
                }
                board.Moves[0].Count.Should().Be(20);
                board.Moves[1].Count.Should().Be(20);
            }
예제 #27
0
            public void ShouldUpdateThePositionInHistoryEntry()
            {
                var board = new Game.Board();

                board.ParseFen(InitialBoardSetupWhiteToMove);

                // move to the same square
                var m = new Move(new Pawn {
                    Square = 22
                }, 22);

                board.MakeMove(m);

                // undo the side change
                board.HashSide();


                board.History[0].PositionKey.Should().Be(board.PositionKey);
            }
예제 #28
0
            public void ShouldResetTheFiftyMoveCountWhenAPieceWhenIsCaptured()
            {
                const string initialBoardSetupForWhiteRookMove = "rnbqkbnr/ppppppp1/8/8/8/8/1PPPPPPP/RBNQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupForWhiteRookMove);

                board.Squares[28].Type.Should().Be(PieceType.Rook);

                var m = new Move(new Rook {
                    Color = Color.Black, Square = 98
                },
                                 new Rook {
                    Color = Color.White, Square = 28
                });

                board.FiftyMoveCount = 1;
                board.MakeMove(m);
                board.FiftyMoveCount.Should().Be(0);
            }
예제 #29
0
            public void ShouldResetThePositionKeyPromotion()
            {
                const string initialBoardSetupWhiteToMove = "1nbqkbnr/Pppppppp/8/8/8/8/1PPPPPPP/RNBQKBNR w KQk - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupWhiteToMove);
                var m = new Move(new Pawn {
                    Square = 81, Color = Color.White
                }, 91, new Queen {
                    Square = 91, Color = Color.White
                });

                var initialPositon = board.PositionKey;

                board.MakeMove(m);

                board.TakeMove();

                board.PositionKey.Should().Be(initialPositon);
            }
예제 #30
0
            public void ShouldResetThePositionKeyAfterCapture()
            {
                const string initialBoardSetupWhiteToMove = "rnbqkbnr/pppppppp/8/8/8/8/1PPPPPPP/RNBQKBNR w KQkq - 0 1";
                var          board = new Game.Board();

                board.ParseFen(initialBoardSetupWhiteToMove);
                var m = new Move(new Rook {
                    Square = 21, Color = Color.White
                }, new Pawn {
                    Square = 81, Color = Color.Black
                });

                var initialPositon = board.PositionKey;

                board.MakeMove(m);

                board.TakeMove();

                board.PositionKey.Should().Be(initialPositon);
            }