Ejemplo n.º 1
0
 public void CheckAndExecuteCastling(IPieceMovement movement)
 {
     if (this.IsCastlingFullyCorrect(movement))
     {
         this.ExecuteCastle(movement);
     }
 }
Ejemplo n.º 2
0
 public QueenMovement(GCPlayer player, Piece piece) : base(player, piece)
 {
     rook               = new RookMovement(player, piece);
     bishop             = new BishopMovement(player, piece);
     BoundComputations += rook.ComputeBound;
     BoundComputations += bishop.ComputeBound;
 }
Ejemplo n.º 3
0
        private bool IsPathToCastleFreeFromCheck(IPieceMovement movement)
        {
            int increment = movement.Origin.X > movement.Destination.X ? -LATERAL_INCREMENT
                    : LATERAL_INCREMENT;

            IBoardPosition nextToItPos = new BoardPosition(movement.Origin.X + increment,
                                                           movement.Origin.Y);

            return(this.gameController
                   .WouldNotBeInCheck(new PieceMovement(movement.PieceInvolved, movement.Origin, nextToItPos)));
        }
Ejemplo n.º 4
0
        private void ExecuteCastle(IPieceMovement movement)
        {
            int increment = movement.Origin.X > movement.Destination.X ? LATERAL_INCREMENT
                    : -LATERAL_INCREMENT;

            IPiece rook = this.GetClosestRookInRangeThatHasntMovedYet(movement);

            if (rook != null)
            {
                rook.PiecePosition = new BoardPosition(movement.Destination.X + increment, rook.PiecePosition.Y);
                movement.Execute();
            }
        }
Ejemplo n.º 5
0
        private IPiece GetClosestRookInRangeThatHasntMovedYet(IPieceMovement mov)
        {
            foreach (IPiece piece in this.gameController.GetBoard().GetPieces())
            {
                if (piece.Type.Equals(PieceType.ROOK) && Math.Abs(piece.PiecePosition.X - mov.Destination.X) <= 2 &&
                    piece.PiecePosition.Y == mov.Destination.Y &&
                    piece.Player.Equals(mov.PieceInvolved.Player) && !piece.HasMoved)
                {
                    return(piece);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
 private bool ArePreliminarChecksOnCastlingValid(IPieceMovement movement)
 {
     return(!this.castlingManager.MightItBeCastle(movement) || this.castlingManager.IsCastlingFullyCorrect(movement));
 }
Ejemplo n.º 7
0
 public bool IsMovementPossible(IPieceMovement movement)
 {
     return(this.PossibleDestinations(movement.PieceInvolved).Contains(movement.Destination));
 }
Ejemplo n.º 8
0
 private bool ExtraChecksOnCastling(IPieceMovement movement)
 {
     return(this.IsPathToCastleFreeFromCheck(movement) &&
            this.GetClosestRookInRangeThatHasntMovedYet(movement) != null);
 }
Ejemplo n.º 9
0
 private bool ArePositionalConditionsCorrectToCastle(IPieceMovement movement)
 {
     return(movement.PieceInvolved.Type.Equals(PieceType.KING) &&
            Math.Abs(movement.Origin.X - movement.Destination.X) == 2 &&
            movement.Origin.Y == movement.Destination.Y);
 }
Ejemplo n.º 10
0
 public bool IsCastlingFullyCorrect(IPieceMovement movement)
 {
     return(this.ArePositionalConditionsCorrectToCastle(movement) && this.ExtraChecksOnCastling(movement));
 }
Ejemplo n.º 11
0
 public bool MightItBeCastle(IPieceMovement movement)
 {
     return(this.ArePositionalConditionsCorrectToCastle(movement));
 }