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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }