Beispiel #1
0
        public Grid(Grid another)
        {
            values = (int[,])another.values.Clone();

            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                    Possibilities[i, j] = new IntList(another.Possibilities[i, j]);

            SolvedCount = another.SolvedCount;
        }
Beispiel #2
0
        public void MultithreadResolve(object param)
        {
            StateObject state = (StateObject)param;
            Grid stateCopy = new Grid(this);
            stateCopy[state.X, state.Y] = state.Value;
            stateCopy.UpdateValues();
            if (stateCopy.SolvedCount == 81)
            {
                Console.Write(state.ToString());
                return;

                // All answers.
                /*
                Sudoku = (Grid)stateCopy.Clone();
                zone = Sudoku[zone.X, zone.Y];
                continue;
                */
            }
            Grid.Position nextPosition = stateCopy.GetNextPosition();
            if (nextPosition != null)
                Resolve(nextPosition, stateCopy);
        }
Beispiel #3
0
        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;
        }