Ejemplo n.º 1
0
        private void CheckForCastlingAndMove(TurnLog turnLog, PieceMovement pieceMovement)
        {
            CastlingMovementSpecification castlingMovementSpecification = CastlingMovementSpecification.Create(this);

            if (castlingMovementSpecification.IsSatisfied(pieceMovement))
            {
                CastlingEvaluationResult castlingEvaluationResult = CastlingEvaluator.EvaluateCastling(this, pieceMovement);
                MovePiece(turnLog, PieceMovement.Create(castlingEvaluationResult.Rook, castlingEvaluationResult.From, castlingEvaluationResult.To));
            }
        }
        public void White_Castiling_Movement_From_King_To_Left_Rook_Should_Not_Satisfy()
        {
            Board board     = Board.Create();
            Piece whiteKing = Piece.Create(PieceType.King, PieceColor.White);

            board.AddPiece(whiteKing, "E1");

            CastlingMovementSpecification castlingMovementSpecification = CastlingMovementSpecification.Create(board);
            bool isSatisfied = castlingMovementSpecification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("C1")));

            Assert.IsFalse(isSatisfied);
        }
        public void Black_Castiling_Movement_From_King_To_Right_Rook_Should_Not_Satisfy()
        {
            Board board     = Board.Create();
            Piece blackKing = Piece.Create(PieceType.King, PieceColor.Black);

            board.AddPiece(blackKing, "E8");

            CastlingMovementSpecification castlingMovementSpecification = CastlingMovementSpecification.Create(board);
            bool isSatisfied = castlingMovementSpecification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("G8")));

            Assert.IsFalse(isSatisfied);
        }
Ejemplo n.º 4
0
 public bool IsSatisfied(PieceMovement candidate)
 {
     if (PositionComparer.FileDistanceAbs(candidate.From, candidate.To) <= 1 &&
         PositionComparer.RankDistanceAbs(candidate.From, candidate.To) <= 1)
     {
         return(true);
     }
     else
     {
         CastlingMovementSpecification castlingMovementSpecification = CastlingMovementSpecification.Create(_board);
         return(castlingMovementSpecification.IsSatisfied(candidate));
     }
 }