コード例 #1
0
ファイル: SudokuGrid.cs プロジェクト: TripleStep/SudokuSolver
 bool PencilCell(int x, int y, int n)
 {
     foreach (Candidate k in solver.UnselectedCandidates)
     {
         SudokuCandidate sc = (SudokuCandidate)k;
         if (x == sc.x && y == sc.y && n == sc.n)
         {
             solver.DiscardCandidate(k);
             Updated();
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        static SudokuCandidate[] Filter(SudokuSolver ss, int cage, Func <int, bool> included)
        {
            int Cells = ss.Cells;
            List <SudokuCandidate> toRemove = new List <SudokuCandidate>();

            for (int i = 0; i < Cells; ++i)
            {
                if (!included(i + 1))
                {
                    CageOptional co = ss.GetCageOptional(cage, i);
                    if (co.Included)
                    {
                        foreach (SudokuCandidate sc in co.UnselectedCandidates)
                        {
                            if (!sc.IsMarked)
                            {
                                toRemove.Add(sc);
                                sc.MarkCandidate(true);
                            }
                        }
                    }
                }
            }

            SudokuCandidate[] removed = toRemove.ToArray();
            for (int i = 0; i < removed.Length; ++i)
            {
                SudokuCandidate sc = removed[i];
                ss.DiscardCandidate(sc);
                sc.MarkCandidate(false);
            }
            return(removed.ToArray());
        }