/// <summary> /// Generates a board from a string representation /// </summary> /// <param name="s">a string representation of the board</param> /// <returns>A new board</returns> public static Disc[,] BoardFromString(this String s) { string[] lines = s.Split('\n'); Disc[,] board = new Disc[lines.Length, lines.Length]; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { switch (lines[i][j]) { case 'O': board[i, j] = Disc.Black; break; case '-': board[i, j] = Disc.Empty; break; case 'X': board[i, j] = Disc.White; break; } } } return(board); }
public bool CloseToEdge(Disc[,] board) { int size = board.GetLength(0); return X == 1 || Y == 1 || X == size - 2 || Y == size - 2; }
/// <summary> /// Generates a board from a string representation /// </summary> /// <param name="s">a string representation of the board</param> /// <returns>A new board</returns> public static Disc[,] BoardFromString(this String s) { string[] lines = s.Split('\n'); Disc[,] board = new Disc[lines.Length, lines.Length]; for (int i = 0; i < board.GetLength(0); i++) for (int j = 0; j < board.GetLength(1); j++) switch (lines[i][j]) { case 'O': board[i, j] = Disc.Black; break; case '-': board[i, j] = Disc.Empty; break; case 'X': board[i, j] = Disc.White; break; } return board; }
/// <summary> /// Returns whether the current point is on the edge of the given board. /// </summary> /// <param name="board"></param> /// <returns></returns> public bool IsEdge(Disc[,] board) { int size = board.GetLength(0); return X == 0 || Y == 0 || X == size - 1 || Y == size - 1; }