/// <summary> /// The lines first piece. /// </summary> /// <param name="colour"> /// The colour. /// </param> /// <param name="pieceName"> /// The piece name. /// </param> /// <param name="squareStart"> /// The square start. /// </param> /// <param name="offset"> /// The offset. /// </param> /// <returns> /// The first piece on the line, or null. /// </returns> public static Piece LinesFirstPiece( Player.PlayerColourNames colour, Piece.PieceNames pieceName, Square squareStart, int offset) { int intOrdinal = squareStart.Ordinal; Square square; intOrdinal += offset; while ((square = GetSquare(intOrdinal)) != null) { if (square.Piece == null) { } else if (square.Piece.Player.Colour != colour) { return(null); } else if (square.Piece.Name == pieceName || square.Piece.Name == Piece.PieceNames.Queen) { return(square.Piece); } else { return(null); } intOrdinal += offset; } return(null); }
/// <summary> /// Determines of the player has the specified piece. /// </summary> /// <param name="piecename"> /// The piecename. /// </param> /// <returns> /// True if player has the piece. /// </returns> public bool HasPieceName(Piece.PieceNames piecename) { if (piecename == Piece.PieceNames.Pawn && this.PawnCountInPlay > 0) { return(true); } foreach (Piece piece in this.Pieces) { if (piece.Name == piecename) { return(true); } } return(false); }
public static bool CanPlayerPieceNameAttackSquare(Square square, Player player, Piece.PieceNames PieceName, out Piece attackingPiece) { attackingPiece = null; switch (PieceName) { case PieceNames.Bishop: return(PieceBishop.DoesPieceAttackSquare(square, player, out attackingPiece)); case PieceNames.King: return(PieceKing.DoesPieceAttackSquare(square, player, out attackingPiece)); case PieceNames.Knight: return(PieceKnight.DoesPieceAttackSquare(square, player, out attackingPiece)); case PieceNames.Pawn: return(PiecePawn.DoesPieceAttackSquare(square, player, out attackingPiece)); case PieceNames.Queen: return(PieceQueen.DoesPieceAttackSquare(square, player, out attackingPiece)); case PieceNames.Rook: return(PieceRook.DoesPieceAttackSquare(square, player, out attackingPiece)); } return(false); }
/// <summary> /// The move piece to fen position. /// </summary> /// <param name="charToken"> /// The char token. /// </param> /// <param name="intFile"> /// The int file. /// </param> /// <param name="intRank"> /// The int rank. /// </param> /// <param name="blnAnyLocation"> /// The bln any location. /// </param> /// <param name="blnAllowPromotion"> /// The bln allow promotion. /// </param> private static void MovePieceToFenPosition( ref char charToken, int intFile, int intRank, bool blnAnyLocation, bool blnAllowPromotion) { Piece.PieceNames piecename = Piece.PieceNames.King; Player player = charToken.ToString() == charToken.ToString().ToUpper() ? Game.PlayerWhite : Game.PlayerBlack; switch (charToken.ToString().ToUpper()) { case "K": piecename = Piece.PieceNames.King; break; case "Q": piecename = Piece.PieceNames.Queen; break; case "R": piecename = Piece.PieceNames.Rook; break; case "B": piecename = Piece.PieceNames.Bishop; break; case "N": piecename = Piece.PieceNames.Knight; break; case "P": piecename = Piece.PieceNames.Pawn; break; } // Try to find the required piece in from the available pool of captured // pieces that haven't been placed on the board yet. Piece pieceToUse = null; foreach (Piece pieceCaptured in player.OpposingPlayer.CapturedEnemyPieces) { if ((pieceCaptured.Name == piecename || (blnAllowPromotion && pieceCaptured.Name == Piece.PieceNames.Pawn)) && (pieceCaptured.StartLocation == Board.GetSquare(intFile, intRank) || blnAnyLocation)) { pieceToUse = pieceCaptured; break; } } if (pieceToUse != null) { Square square = Board.GetSquare(intFile, intRank); pieceToUse.Uncapture(0); square.Piece = pieceToUse; pieceToUse.Square = square; pieceToUse.NoOfMoves = blnAnyLocation ? 1 : 0; if (pieceToUse.Name != piecename) { pieceToUse.Promote(piecename); } // Mark the token in the original FEN string with a * to indicate that the piece has been processed charToken = '.'; } }
/// <summary> /// can a given player's piece name attack a given square? /// </summary> /// <param name="square"></param> /// <param name="player"></param> /// <param name="PieceName"></param> /// <returns></returns> public static bool CanPlayerPieceNameAttackSquare(Square square, Player player, Piece.PieceNames PieceName) { switch (PieceName) { case PieceNames.Bishop: return PieceBishop.DoesPieceAttackSquare(square, player); case PieceNames.King: return PieceKing.DoesPieceAttackSquare(square, player); case PieceNames.Knight: return PieceKnight.DoesPieceAttackSquare(square, player); case PieceNames.Pawn: return PiecePawn.DoesPieceAttackSquare(square, player); case PieceNames.Queen: return PieceQueen.DoesPieceAttackSquare(square, player); case PieceNames.Rook: return PieceRook.DoesPieceAttackSquare(square, player); } return false; }
private bool NPiecesWithQualities(Player player, string abbreviation, Piece.PieceNames name, int num, int?file = null, int?rank = null) { return(FindPiecesWithQualities(player, abbreviation, name, file, rank).Count == num); }
private List <Piece> FindPiecesWithQualities(Player player, string abbreviation, Piece.PieceNames name, int?file = null, int?rank = null) { List <Piece> result = new List <Piece>(); foreach (Piece piece in player.Pieces) { if (PieceHasExpectedQualities(piece, player, abbreviation, name, file, rank)) { result.Add(piece); } } return(result); }
private bool PieceHasExpectedQualities(Piece piece, Player player, string abbreviation, Piece.PieceNames name, int?file = null, int?rank = null) { return(abbreviation == piece.Abbreviation && name == piece.Name && (file == null || file == piece.StartLocation.File) && (rank == null || rank == piece.StartLocation.Rank) && player == piece.Player); }