public int[,] SudokuMapBuilder() { Start: int[,] Map = new int[9, 9]; int mapCounter = 1; List <int[, ]> mapHolder = new List <int[, ]>(); RandomNumberCorector randomNumberCorector = new RandomNumberCorector(); List <NumberCorectorValueTypes> NumberCorectorsList = new List <NumberCorectorValueTypes>(); RandomNumber randomNumber = new RandomNumber(); MapContainer mapContainer = new MapContainer(); int i = 0; int indexi = 0; int j = 0; int indexj = 0; int indexjComparer = 3; int countSquares = 0; int FailFailCount = 0; int mapCounter_A = 0; int mapCounter_B = 0; int countRow = 0; int countColumn = 0; bool ifStartsNewSquare = false; int failCount = 0; int numberCheck = 0; int countMapCounterAtempts = 0; RandomHolder = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (i = indexi; i < Map.GetLength(0); i++) { countRow++; for (j = indexj; j < indexjComparer; j++) { countColumn++; if (countColumn > 3) { countColumn = 1; } do { numberCheck = randomNumber.Get(countRow, countColumn, randomNumberCorector, NumberCorectorsList, RandomHolder); if (numberCheck == 666 || randomNumberCorector.TotalImposibleFromHolderList(numberCheck, NumberCorectorsList)) { ifStartsNewSquare = true; if (mapCounter > mapHolder.Count) { mapCounter = 1; } failCount++; mapCounter_A = mapCounter; if (mapHolder.Count == 8 && failCount == 1) { FailFailCount++; } if (failCount > 1) { mapCounter++; failCount = 0; } if (FailFailCount == 5) { mapCounter = 5; mapHolder.RemoveRange(mapHolder.Count - 5, 5); FailFailCount = 0; } mapCounter_B = mapCounter; mapContainer.Get(mapHolder, ref Map, mapCounter); RandomHolder = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; if (mapCounter_A != mapCounter_B) { NumberCorectorsList = new List <NumberCorectorValueTypes>(); } MapStepBack.SetIndexersToProperPpositions(Map, ref i, ref j, ref indexi, ref indexj, ref indexjComparer, ref countRow, ref countSquares); randomNumberCorector.RemoveSquareNumbers(ref NumberCorectorsList); countColumn = 0; break; } else { Map[i, j] = numberCheck; } } while (NumberChecking.NumberDuplicate(Map, Map[i, j], ref randomNumberCorector, ref NumberCorectorsList, countRow, countColumn, j)); if (ifStartsNewSquare == false) { RandomHolder.Remove(Map[i, j]); } ifStartsNewSquare = false; } if (countRow == 3) { countMapCounterAtempts++; NumberCorectorsList = new List <NumberCorectorValueTypes>(); CountTry++; if (CountTry > 30) { CountTry = 0; goto Start; } mapContainer.Add(Map, ref mapHolder); mapCounter = 1; countSquares++; if (countSquares == 3 && indexi + 3 < Map.GetLength(0)) { countSquares = 0; indexi += 3; indexj = 0; indexjComparer = 3; countRow = 0; RandomHolder = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } else { RandomHolder = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; if (i == 5) { i = 2; } else if (i == 8) { i = 5; } else { i = -1; } if (i != 8 && j != 9) { indexjComparer += 3; } else { i = Map.GetLength(0); } indexj += 3; countRow = 0; } } } return(Map); }