public static void GetNearbyPieces(GamePiece[,] board, int col, int row) { // Pieces to the left try { oneToLeft = board[row, col - 1].GetBoardGamePiece(); } catch { oneToLeft = null; } try { twoToLeft = board[row, col - 2].GetBoardGamePiece(); } catch { twoToLeft = null; } try { threeToLeft = board[row, col - 3].GetBoardGamePiece(); } catch { threeToLeft = null; } // Pieces to the right try { oneToRight = board[row, col + 1].GetBoardGamePiece(); } catch { oneToRight = null; } try { twoToRight = board[row, col + 2].GetBoardGamePiece(); } catch { twoToRight = null; } try { threeToRight = board[row, col + 3].GetBoardGamePiece(); } catch { threeToRight = null; } // Pieces below try { oneBelow = board[row + 1, col].GetBoardGamePiece(); } catch { oneBelow = null; } try { twoBelow = board[row + 2, col].GetBoardGamePiece(); } catch { twoBelow = null; } try { threeBelow = board[row + 3, col].GetBoardGamePiece(); } catch { threeBelow = null; } // Pieces to the top left try { oneTopLeft = board[row - 1, col - 1].GetBoardGamePiece(); } catch { oneTopLeft = null; } try { twoTopLeft = board[row - 2, col - 2].GetBoardGamePiece(); } catch { twoTopLeft = null; } try { threeTopLeft = board[row - 3, col - 3].GetBoardGamePiece(); } catch { threeTopLeft = null; } // Pieces to the bottom right try { oneBottomRight = board[row + 1, col + 1].GetBoardGamePiece(); } catch { oneBottomRight = null; } try { twoBottomRight = board[row + 2, col + 2].GetBoardGamePiece(); } catch { twoBottomRight = null; } try { threeBottomRight = board[row + 3, col + 3].GetBoardGamePiece(); } catch { threeBottomRight = null; } // Pieces to the top right try { oneTopRight = board[row - 1, col + 1].GetBoardGamePiece(); } catch { oneTopRight = null; } try { twoTopRight = board[row - 2, col + 2].GetBoardGamePiece(); } catch { twoTopRight = null; } try { threeTopRight = board[row - 3, col + 3].GetBoardGamePiece(); } catch { threeTopRight = null; } // Pieces to the bottom left try { oneBottomLeft = board[row - 1, col + 1].GetBoardGamePiece(); } catch { oneBottomLeft = null; } try { twoBottomLeft = board[row - 2, col + 2].GetBoardGamePiece(); } catch { twoBottomLeft = null; } try { threeBottomLeft = board[row - 3, col + 3].GetBoardGamePiece(); } catch { threeBottomLeft = null; } }
Random rand = new Random(); // Random num generator public Player(string n, char ch, ConsoleColor color, bool ai) { name = n; gamePiece = new GamePiece(color, ch); isAI = ai; }