private static bool ReSudoku(Board b) { bool isFree = false; int row = -1; int col = -1; int[,] board = b.board; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { if (board[i, j] == 0) { row = i; col = j; isFree = true; break; } } if (isFree) { break; } } if (!isFree) { c++; Console.WriteLine(c + "-"); Console.WriteLine(b); return(true); } bool chk = false; for (int num = 1; num <= len; num++) { if (IsLegal(row, col, num, b)) { board[row, col] = num; #if false wait++; if (wait <= 50) { Console.WriteLine(wait); b.Pointer(col, row); Thread.Sleep(10); Console.Clear(); } if (wait == 100000) { wait = 0; } #endif chk = ReSudoku(b) || chk; b.board[row, col] = 0; } } return(chk); }
private static Board Editor(Board b = null) { if (b != null) { b = ValidBorad(b); } bool chk1 = false; bool chk2 = false; int input = -1; int left = 0; int top = 0; int size = len; bool stop = true; while (stop) { Console.Clear(); Console.WriteLine("\n\rPress 'ESC' to stop"); Console.WriteLine("\rPress 'Enter' to edit\n"); b.Pointer(left, top); if (chk2) { b.SaveBoard(); chk2 = false; } if (chk1) { chk1 = false; input = -1; Console.WriteLine("Illegal Move"); } ConsoleKeyInfo keyInfo = Console.ReadKey(true); switch (keyInfo.Key) { case (ConsoleKey.DownArrow): if (top < size - 1) { top++; } break; case (ConsoleKey.UpArrow): if (top > 0) { top--; } break; case (ConsoleKey.RightArrow): if (left < size - 1) { left++; } break; case (ConsoleKey.LeftArrow): if (left > 0) { left--; } break; case (ConsoleKey.Escape): stop = false; break; case (ConsoleKey.S): chk2 = true; break; case (ConsoleKey.Enter): while (input <= -1 || input > len) { Console.WriteLine("Enter a number"); Console.Write("Input: "); input = int.Parse(Console.ReadLine()); } if (input == 0 || IsLegal(top, left, input, b)) { b.board[top, left] = input; input = -1; } else { chk1 = true; } break; default: if (char.IsNumber(keyInfo.KeyChar)) { int num = int.Parse(keyInfo.KeyChar.ToString()); Console.WriteLine(num); if (num == 0 || IsLegal(top, left, num, b) && num > 0 && num <= len) { b.board[top, left] = num; } } break; } } return(b); }