public void Castling_IsAvailableKing() { var board = new Board(); var whiteKing = new King(Player.White); var whiteRook = new Rook(Player.White); var whiteRook2 = new Rook(Player.White); board.AddPiece(Square.At(7, 4), whiteKing); board.AddPiece(Square.At(7, 0), whiteRook); board.AddPiece(Square.At(7, 7), whiteRook2); whiteKing.GetAvailableMoves(board).Should().Contain(Square.At(7, 2)); whiteKing.GetAvailableMoves(board).Should().Contain(Square.At(7, 6)); }
public void King_CanCastle_IfNotMoved() { var board = new Board(); var rook = new Rook(Player.White); var king = new King(Player.White); board.AddPiece(Square.At(7, 0), rook); board.AddPiece(Square.At(7, 4), king); var moves = king.GetAvailableMoves(board); moves.Should().Contain(Square.At(7, 2)); }
public void Kings_CannotTakeFriendlyPieces() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(4, 4), king); var pawn = new Pawn(Player.White); board.AddPiece(Square.At(4, 5), pawn); var moves = king.GetAvailableMoves(board); moves.Should().NotContain(Square.At(4, 5)); }
public void Castling_ThroughCheck_Disallowed_Right() { var board = new Board(); var whiteKing = new King(Player.White); var whiteRook = new Rook(Player.White); var blackRook = new Rook(Player.Black); board.AddPiece(Square.At(7, 4), whiteKing); board.AddPiece(Square.At(7, 7), whiteRook); board.AddPiece(Square.At(5, 5), blackRook); whiteKing.GetAvailableMoves(board).Should().NotContain(Square.At(7, 6)); }
public void Kings_CanQueensideCastle() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(7, 4), king); var rook = new Rook(Player.White); board.AddPiece(Square.At(7, 7), rook); var moves = king.GetAvailableMoves(board); moves.Should().Contain(Square.At(7, 6)); }
public void Kings_CanCastleRook_IfNeitherHaveMovedBefore() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(7, 5), king); var rook = new Rook(Player.White); board.AddPiece(Square.At(7, 0), rook); var moves = king.GetAvailableMoves(board); moves.Should().Contain(Square.At(7, 3)); }
public void King_AvailableMoves_FromStartPosition_AreCorrect() { List <FigurePosition> availableMovesFromStartPosition = new List <FigurePosition> { new FigurePosition(3, 1), new FigurePosition(5, 1), new FigurePosition(3, 2), new FigurePosition(4, 2), new FigurePosition(5, 2) }; Assert.That(availableMovesFromStartPosition, Is.EquivalentTo(_king.GetAvailableMoves().ToList())); }
public void Kings_CannotCastleRook_IfRookHasMovedBefore() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(7, 5), king); var rook = new Rook(Player.White); board.AddPiece(Square.At(4, 0), rook); rook.MoveTo(board, new Square(7, 0)); var moves = king.GetAvailableMoves(board); moves.Should().NotContain(Square.At(7, 3)); }
public void BlackKing_CanMoveAnyDirection() { var board = new Board(); var king = new King(Player.Black); board.AddPiece(Square.At(3, 3), king); var moves = king.GetAvailableMoves(board).ToList(); moves.Should().BeEquivalentTo(Square.At(2, 2), Square.At(2, 3), Square.At(2, 4), Square.At(3, 2), Square.At(3, 4), Square.At(4, 2), Square.At(4, 3), Square.At(4, 4)); }
public void Kings_CannotLeaveTheBoard() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(0, 0), king); var moves = king.GetAvailableMoves(board); var expectedMoves = new List <Square> { Square.At(1, 0), Square.At(1, 1), Square.At(0, 1) }; moves.ShouldAllBeEquivalentTo(expectedMoves); }
public void King_AvailableMoves_For_6x5_AreCorrect() { List <FigurePosition> availableMovesFromPosition = new List <FigurePosition> { new FigurePosition(5, 4), new FigurePosition(5, 5), new FigurePosition(5, 6), new FigurePosition(6, 4), new FigurePosition(6, 6), new FigurePosition(7, 4), new FigurePosition(7, 5), new FigurePosition(7, 6) }; King king = new King(6, 5); Assert.That(availableMovesFromPosition, Is.EquivalentTo(king.GetAvailableMoves().ToList())); }
public void Kings_WithARookWhichHasAlreadyMoved_CannotCastle() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(7, 4), king); var rook = new Rook(Player.White); board.AddPiece(Square.At(7, 7), rook); var pawn = new Rook(Player.Black); board.AddPiece(Square.At(0, 3), pawn); rook.MoveTo(board, Square.At(6, 7)); pawn.MoveTo(board, Square.At(1, 3)); rook.MoveTo(board, Square.At(7, 7)); var moves = king.GetAvailableMoves(board); moves.Should().NotContain(Square.At(7, 6)); }
public void KingsCanMoveToAdjacentSquares() { var board = new Board(); var king = new King(Player.White); board.AddPiece(Square.At(4, 4), king); var moves = king.GetAvailableMoves(board); var expectedMoves = new List <Square> { Square.At(3, 3), Square.At(3, 4), Square.At(3, 5), Square.At(4, 3), Square.At(4, 5), Square.At(5, 3), Square.At(5, 4), Square.At(5, 5) }; moves.ShouldAllBeEquivalentTo(expectedMoves); }