public void CheckAndExecuteCastling(IPieceMovement movement) { if (this.IsCastlingFullyCorrect(movement)) { this.ExecuteCastle(movement); } }
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; }
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))); }
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(); } }
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); }
private bool ArePreliminarChecksOnCastlingValid(IPieceMovement movement) { return(!this.castlingManager.MightItBeCastle(movement) || this.castlingManager.IsCastlingFullyCorrect(movement)); }
public bool IsMovementPossible(IPieceMovement movement) { return(this.PossibleDestinations(movement.PieceInvolved).Contains(movement.Destination)); }
private bool ExtraChecksOnCastling(IPieceMovement movement) { return(this.IsPathToCastleFreeFromCheck(movement) && this.GetClosestRookInRangeThatHasntMovedYet(movement) != null); }
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); }
public bool IsCastlingFullyCorrect(IPieceMovement movement) { return(this.ArePositionalConditionsCorrectToCastle(movement) && this.ExtraChecksOnCastling(movement)); }
public bool MightItBeCastle(IPieceMovement movement) { return(this.ArePositionalConditionsCorrectToCastle(movement)); }