public static List <CellsBlock> CheckForOpenedBlocks(DataMatrix dataMatrix, DataMatrix solutionMatrix, int?row, int?col) { List <CellsBlock> dataList = solutionMatrix.GetCountersList(row, col); List <CellsBlock> checkList = dataMatrix.GetCountersList(row, col); dataList.ForEach(block => CheckBlockOpened(row, col, block, checkList, dataMatrix)); return(dataList); }
private static DataMatrix GetRandomMatrixBase(int width, int height) { //extend matrix and fill border with cleared elements for further int widthExtend = width + 2; int heightExtend = height + 2; DataMatrix matrix = new DataMatrix((short)widthExtend, (short)heightExtend); Random rand = new Random(); for (int i = 0; i < widthExtend; i++) { for (int j = 0; j < heightExtend; j++) { if (i == 0 || j == 0 || i == (widthExtend - 1) || j == (heightExtend - 1)) { matrix[i, j] = new Element(Element.ElementType.Cleared); } else { matrix[i, j] = new Element(GetRandomElementWithGrouping(rand, matrix[(i - 1), j], matrix[i, (j - 1)]), false); } } } for (short i = 1; i < widthExtend - 1; i++) { bool foundSingle; do { foundSingle = false; for (int j = 1; j < heightExtend - 1; j++) { if (IsElementSingle(matrix, i, j)) { matrix[i, j] = new Element(Element.ElementType.Cleared); foundSingle = true; } } }while (matrix.GetCountersList(null, i).Count > Constants.MAX_ELEMENTS && foundSingle); } for (short i = 1; i < heightExtend - 1; i++) { bool foundSingle; do { foundSingle = false; for (int j = 1; j < widthExtend - 1; j++) { if (IsElementSingle(matrix, i, j)) { matrix[i, j] = new Element(Element.ElementType.Cleared); foundSingle = true; } } }while (matrix.GetCountersList(i, null).Count > Constants.MAX_ELEMENTS && foundSingle); } //cut result matrix DataMatrix resultMatrix = new DataMatrix(width, height); for (int i = 1; i < widthExtend - 1; i++) { for (int j = 1; j < heightExtend - 1; j++) { resultMatrix[i - 1, j - 1] = matrix[i, j]; } } //TODO add testing for uniqueness of solution return(resultMatrix); }