예제 #1
0
        public static List <CellGroup> GetOpenCellGroups(List <int> indices, SudokuPuzzle puzzle, UnitType uType)
        {
            CellGroup[] cellGroups = new CellGroup[3];
            switch (uType)
            {
            case UnitType.row:
                cellGroups[0] = puzzle.rowCollection[indices[0] - 1];
                cellGroups[1] = puzzle.rowCollection[indices[1] - 1];
                cellGroups[2] = puzzle.rowCollection[indices[2] - 1];
                break;

            case UnitType.column:
                cellGroups[0] = puzzle.colCollection[indices[0] - 1];
                cellGroups[1] = puzzle.colCollection[indices[1] - 1];
                cellGroups[2] = puzzle.colCollection[indices[2] - 1];
                break;

            case UnitType.subgrid:
                cellGroups[0] = puzzle.sgCollection[indices[0] - 1];
                cellGroups[1] = puzzle.sgCollection[indices[1] - 1];
                cellGroups[2] = puzzle.sgCollection[indices[2] - 1];
                break;
            }

            var openGroups = from CellGroup cg in cellGroups
                             where !IsGroupClosed(cg)
                             select cg;

            if (openGroups != null)
            {
                return(openGroups.ToList());
            }
            return(null);
        }
예제 #2
0
        static void Main(string[] args)
        {
            string puzzleName;

            SudokuPuzzle puzzle      = SudokuPuzzle.GetPuzzle();
            Agent        brainsolver = new Agent();

            do
            {
                Console.WriteLine("Enter a sudoku puzzle file. To quit, type exit, Exit, quit, Quit, or give no input ");
                puzzleName = Console.ReadLine();
                if (!exitKeywords.Contains(puzzleName))
                {
                    puzzle.BuildPuzzle(puzzleName);
                    brainsolver.Init();
                    brainsolver.Execute();
                    if (brainsolver.IsPuzzleSolved())
                    {
                        Console.WriteLine("The puzzle {0} was solved", puzzleName);
                        puzzle.ClearPuzzle();
                    }
                    //}
                }
                if (exitKeywords.Contains(puzzleName))
                {
                    System.Environment.Exit(0);
                }
            } while (!exitKeywords.Contains(puzzleName));
        }
예제 #3
0
 public static void UnfillCell(this SudokuCell sudokuCell)
 {
     if (sudokuCell == null)
     {
         new NullReferenceException();
     }
     else
     {
         if (sudokuCell.isFilled)
         {
             int oldValue = sudokuCell.FillValue;
             sudokuCell.FillValue = 0;
             SudokuPuzzle.GetPuzzle().cellBoard.fillFrequencyCounter.DecrementFor(oldValue);
         }
         else
         {
             Console.WriteLine("{0} is already unfilled.", sudokuCell.ToString());
         }
     }
 }
예제 #4
0
 public static void FillCell(this SudokuCell sudokuCell, int newFill)
 {
     if (sudokuCell == null)
     {
         new NullReferenceException();
     }
     else
     {
         if (sudokuCell.Possibilities.Contains(newFill))
         {
             sudokuCell.FillValue = newFill;
             Console.WriteLine("{0} now has fill value of {1}", sudokuCell.ToString(), newFill.ToString());
             Debug.WriteLine("{0} now has fill value of {1}", sudokuCell.ToString(), newFill.ToString());
             SudokuPuzzle.GetPuzzle().cellBoard.fillFrequencyCounter.IncrementFor(newFill);
         }
         else
         {
             Console.WriteLine("{0} not part of {1}'s possibilities", newFill.ToString(), sudokuCell.ToString());
         }
     }
 }
예제 #5
0
        public static List <CellGroup> GetMatchingSubgroups(UnitType uType, List <int> indices, SudokuPuzzle puzzle)
        {
            List <CellGroup> retrievedGroups = new List <CellGroup>();

            foreach (int index in indices)
            {
                switch (uType)
                {
                case UnitType.row:
                    retrievedGroups.Add(puzzle.rowCollection[index - 1]);
                    break;

                case UnitType.column:
                    retrievedGroups.Add(puzzle.colCollection[index - 1]);
                    break;

                default:
                    break;
                }
            }
            return(retrievedGroups);
        }