public bool Resolve(Position position, Grid state) { int x = position.X, y = position.Y; Grid stateCopy = new Grid(state); IntList possibilities = stateCopy.Possibilities[x, y]; for (int i = 0; i < possibilities.Count; i++) { state[x, y] = possibilities[i]; state.UpdateValues(); if (state.SolvedCount == 81) { Console.Write(state.ToString()); Console.WriteLine(); lock (typeof(Grid)) Console.Write("Elapsed time: {0}ms", Environment.TickCount - Program.StartTime); return(true); // All answers. /* * Sudoku = (Grid)stateCopy.Clone(); * zone = Sudoku[zone.X, zone.Y]; * continue; */ } Grid.Position nextPosition = state.GetNextPosition(); if (nextPosition != null && Resolve(nextPosition, state)) { return(true); } state = new Grid(stateCopy); } return(false); }
public bool Resolve(Position position, Grid state) { int x = position.X, y = position.Y; Grid stateCopy = new Grid(state); IntList possibilities = stateCopy.Possibilities[x, y]; for (int i = 0; i < possibilities.Count; i++) { state[x, y] = possibilities[i]; state.UpdateValues(); if (state.SolvedCount == 81) { Console.Write(state.ToString()); Console.WriteLine(); lock (typeof(Grid)) Console.Write("Elapsed time: {0}ms", Environment.TickCount - Program.StartTime); return true; // All answers. /* Sudoku = (Grid)stateCopy.Clone(); zone = Sudoku[zone.X, zone.Y]; continue; */ } Grid.Position nextPosition = state.GetNextPosition(); if (nextPosition != null && Resolve(nextPosition, state)) return true; state = new Grid(stateCopy); } return false; }