private bool IsCastleMove(King king, Square startingSquare, Square endingSquare, out CastleType?type) { type = null; if (startingSquare.Coordinate != king.GetCastleStartingPosition()) { return(false); } if (endingSquare.Coordinate == king.GetCastleEndingPosition(CastleType.KingSide)) { type = CastleType.KingSide; return(true); } else if (endingSquare.Coordinate == king.GetCastleEndingPosition(CastleType.QueenSide)) { type = CastleType.QueenSide; return(true); } return(false); }
public Castle(King king, Rook rook, Board board, CastleType type) : base(true, king, null, board[king.GetCastleStartingPosition()], board[king.GetCastleEndingPosition(type)], null) { _type = type; _board = board; _rook = rook; _rookStartingPosition = board[King.GetCastleRookStartingSquare(type)]; _rookEndingPosition = board[King.GetCastleRookEndingPosition(type)]; }
internal static IEnumerable <SquareCoordinate> GetKingMobility(King king, SquareCoordinate startingCoordinate, Board board) { var ret = new List <SquareCoordinate>(); SquareCoordinate?newPos = null; //Upper left if (TryGetNewPosition(startingCoordinate.Rank + 1, startingCoordinate.File - 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Upper middle if (TryGetNewPosition(startingCoordinate.Rank + 1, startingCoordinate.File, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Upper right if (TryGetNewPosition(startingCoordinate.Rank + 1, startingCoordinate.File + 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Middle right if (TryGetNewPosition(startingCoordinate.Rank, startingCoordinate.File + 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Middle left if (TryGetNewPosition(startingCoordinate.Rank, startingCoordinate.File - 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Bottom right if (TryGetNewPosition(startingCoordinate.Rank - 1, startingCoordinate.File + 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Bottom middle if (TryGetNewPosition(startingCoordinate.Rank - 1, startingCoordinate.File, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //Bottom left if (TryGetNewPosition(startingCoordinate.Rank - 1, startingCoordinate.File - 1, out newPos)) { if (!board.IsControlledByColor(newPos.Value, king.Color.OpponentColor) && board.CanPieceOfColorGoToSquare(newPos.Value, king.Color)) { ret.Add(newPos.Value); } } //King side castle if (CanCastle(king, board, CastleType.KingSide)) { ret.Add(king.GetCastleEndingPosition(CastleType.KingSide)); } //Queen side castle if (CanCastle(king, board, CastleType.QueenSide)) { ret.Add(king.GetCastleEndingPosition(CastleType.QueenSide)); } return(ret); }