/// <summary> /// Convert collection to sudoku. /// </summary> /// <param name="source">Collection souce.</param> /// <returns>A sudoku.</returns> public static BrickNode[,] ToSudoku(this IEnumerable <BrickNode> source) { BrickNode[,] nodes = null; if (source != null && source.Any()) { nodes = new BrickNode[Constants.RowCount, Constants.ColumnCount]; for (int i = 0; i < source.Count(); i++) { if ((i + 1) > (Constants.RowCount * Constants.ColumnCount)) { return(nodes); } else { int row = i / Constants.RowCount; int column = i - row * Constants.RowCount; nodes[row, column] = source.ElementAt(i); } } } return(nodes); }
/// <summary> /// Create empty general style sudoku. /// </summary> /// <returns>Empty sudoku.</returns> public static BrickNode[,] CreateGeneralSudoku() { BrickNode[,] nodes = new BrickNode[Constants.RowCount, Constants.ColumnCount]; for (int i = 0; i < Constants.RowCount; i++) { for (int j = 0; j < Constants.ColumnCount; j++) { nodes[i, j].Kind = BrickKind.General; } } return(nodes); }
/// <summary> /// Transform brick node collection, if node's value is bigger than 0, then make all nodes' kind to Original. /// </summary> /// <param name="source">Brick node collection.</param> /// <returns>Original kind Brick node collection.</returns> public static BrickNode[,] TransformOriginal(BrickNode[,] source) { BrickNode[,] nodes = new BrickNode[Constants.RowCount, Constants.ColumnCount]; for (int i = 0; i < Constants.RowCount; i++) { for (int j = 0; j < Constants.ColumnCount; j++) { if (source[i, j].Number > 0) { nodes[i, j].Kind = BrickKind.Original; } else { nodes[i, j].Kind = BrickKind.General; } nodes[i, j].Number = source[i, j].Number; } } return(nodes); }