src/ChessTrainerApp/Components/ChessBoardBase.cs
/// <summary>
/// Attempts to select a game piece.
/// </summary>
/// <param name="file">The file of the piece to be selected.</param>
/// <param name="rank">The rank of the piece to be selected.</param>
/// <returns>True if a piece was successfully selected, false otherwise. Note that this does not guarantee the selected piece has any legal moves.</returns>
Attempts to select a game piece.
Attempts to select a game piece .
public bool SelectPiece(int file, int rank)
        {
            if (Game?.Result != GameResult.Ongoing)
            {
                return false;
            }
            if ((Game.WhiteToMove && !UserMovableWhitePieces) ||
                (!Game.WhiteToMove && !UserMovableBlackPieces))
            {
                return false;
            }
            var piece = Game.GetPiece(file, rank);
            if (piece == null || ChessFormatter.IsPieceWhite(piece.PieceType) != Game.WhiteToMove)
            {
                return false;
            }
            SelectedPiece = piece;
            return true;
        }
public bool SelectPiece ( int file , int rank ) { if ( Game ? . Result != GameResult . Ongoing ) { return false ; } if ( ( Game . WhiteToMove && ! UserMovableWhitePieces ) || ( ! Game . WhiteToMove && ! UserMovableBlackPieces ) ) { return false ; } var piece = Game . GetPiece ( file , rank ) ; if ( piece == null || ChessFormatter . IsPieceWhite ( piece . PieceType ) != Game . WhiteToMove ) { return false ; } SelectedPiece = piece ; return true ; }
Attempts to select a game piece.
Attempts to select a game piece .
// Don't select pieces if the game is finished // Don't select pieces if the user isn't allowed to move the active color's pieces // Don't select pieces if the clicked square doesn't contain a piece or contains a piece for the wrong player
True if a piece was successfully selected, false otherwise. Note that this does not guarantee the selected piece has any legal moves.
True if a piece was successfully selected false otherwise . Note that this does not guarantee the selected piece has any legal moves .
file
int
The file of the piece to be selected.
The file of the piece to be selected .
rank
int
The rank of the piece to be selected.
The rank of the piece to be selected .