private object Generate(int nrows, int ncols, int height, int width, int rest) { Board board = new Board(nrows, ncols); board.SetEmpty(height, width); board.SetClick(0, 0); int y = 0; int x = width; while (rest >= 2 && y + 1 < height && x < ncols) { board.SetEmptyCell(y, x); board.SetEmptyCell(y + 1, x); rest -= 2; x++; if (x >= ncols) { y += 2; x = width; if (y >= height) break; } } if (rest > 0 && y == 0) { y = 2; x = width; } while (rest > 0 && y < height && x < ncols) { board.SetEmptyCell(y, x++); rest--; if (x >= ncols) { y++; x = width; } } return board.ToLines(); }