脳が機能していません。このグリッドの最初の 3 行を取得しようとしています。新しいことを学ぶためだけに、単純なチェッカー ゲームを作成しています。私のコードは、最初の 3 つの列を取得して、赤いチェスの駒の配置を初期化しています。代わりに最初の 3 行が必要です。
これは私のコードが今行っていることです:
これは私の(簡略化された)コードです。Square
は、ピースを追跡するためにいくつかの小さなアイテムを保持するだけの私のクラスです。
private Square[][] m_board = new Square[8][];
for (int i = 0; i < m_board.Length; i++)
m_board[i] = new Square[8];
//find which pieces should hold red pieces, the problem line
IEnumerable<Square> seqRedSquares =
m_board.Take(3).SelectMany(x => x).Where(x => x != null);
//second attempt with the same result
//IEnumerable<Square> seqRedSquares =
m_board[0].Union(m_board[1]).Union(m_board[2]).Where(x => x != null);
//display the pieces, all works fine
foreach (Square redSquare in seqRedSquares)
{
Piece piece = new Piece(redSquare.Location, Piece.Color.Red);
m_listPieces.Add(piece);
redSquare.Update(piece);
}