C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am building a chess engine and need to use bitboards. I wrote a function that gets the Bitboards, but now I am getting a CS1525 compiler error with the ref statements. Can anyone suggest a workaround? I am still learning about C#. Thank you for any help you can provide.
Here is the function
private ref ulong GetBitboard(Piece.PieceType pieceType)
{
return ref pieceType switch
{
Piece.PieceType.WhitePawn => ref whitePawns,
Piece.PieceType.WhiteKnight => ref whiteKnights,
Piece.PieceType.WhiteBishop => ref whiteBishops,
Piece.PieceType.WhiteRook => ref whiteRooks,
Piece.PieceType.WhiteQueen => ref whiteQueens,
Piece.PieceType.WhiteKing => ref whiteKing,
Piece.PieceType.BlackPawn => ref blackPawns,
Piece.PieceType.BlackKnight => ref blackKnights,
Piece.PieceType.BlackBishop => ref blackBishops,
Piece.PieceType.BlackRook => ref blackRooks,
Piece.PieceType.BlackQueen => ref blackQueens,
Piece.PieceType.BlackKing => ref blackKing,
_ => throw new ArgumentException("Invalid Piece Type"),
};
}
If the switch expression does not work, then try the switch statement:
private ref ulong GetBitboard(Piece.PieceType pieceType)
{
switch( pieceType )
{
case Piece.PieceType.WhitePawn: return ref whitePawns;
case Piece.PieceType.WhiteKnight: return ref whiteKnights;
... and so no ...
default: throw new ArgumentException("Invalid Piece Type");
};
}