/// <summary> /// Create new Array[8,8] for a Board and put pieces on it /// </summary> private void PopulateBoard() { _Board = new Piece[8, 8]; _Board[0, 0] = new Piece(PieceType.Rook, PlayerColor.White); _Board[0, 1] = new Piece(PieceType.Knight, PlayerColor.White); _Board[0, 2] = new Piece(PieceType.Bishop, PlayerColor.White); _Board[0, 3] = new Piece(PieceType.Queen, PlayerColor.White); _Board[0, 4] = new Piece(PieceType.King, PlayerColor.White); _Board[0, 5] = new Piece(PieceType.Bishop, PlayerColor.White); _Board[0, 6] = new Piece(PieceType.Knight, PlayerColor.White); _Board[0, 7] = new Piece(PieceType.Rook, PlayerColor.White); _Board[7, 0] = new Piece(PieceType.Rook, PlayerColor.Black); _Board[7, 1] = new Piece(PieceType.Knight, PlayerColor.Black); _Board[7, 2] = new Piece(PieceType.Bishop, PlayerColor.Black); _Board[7, 3] = new Piece(PieceType.Queen, PlayerColor.Black); _Board[7, 4] = new Piece(PieceType.King, PlayerColor.Black); _Board[7, 5] = new Piece(PieceType.Bishop, PlayerColor.Black); _Board[7, 6] = new Piece(PieceType.Knight, PlayerColor.Black); _Board[7, 7] = new Piece(PieceType.Rook, PlayerColor.Black); for (int i = 0; i < 8; i++) { _Board[1, i] = new Piece(PieceType.Pawn, PlayerColor.White); _Board[6, i] = new Piece(PieceType.Pawn, PlayerColor.Black); } }
/// <summary> /// Return a list of pieces between coordinates A and B /// </summary> /// <param name="A">Start coordinate</param> /// <param name="B">End coordinates</param> /// <returns>Piece array; IIRC this array is 1 too long - sort of latent bug</returns> public Piece[] ReturnPiecesBetween(Coordinate A, Coordinate B) { int XDelta, YDelta; int XDir, YDir; // find differences and directions of coordinates B.AbsDelta(A, out XDelta, out YDelta); B.Direction(A, out XDir, out YDir); // allocate an array Piece[] Result = null; if (XDelta == 0) Result = new Piece[YDelta]; if (YDelta == 0) Result = new Piece[XDelta]; if (XDelta == YDelta) Result = new Piece[XDelta]; // int X = A.X + XDir; int Y = A.Y + YDir; int Index = 0; // while (((XDir == 0) || ((XDir == 1) && (X < B.X)) || ((XDir == -1) && (X > B.X))) && ((YDir == 0) || ((YDir == 1) && (Y < B.Y)) || ((YDir == -1) && (Y > B.Y))) ) { Result[Index++] = _Board[Y, X]; X += XDir; Y += YDir; } return Result; }