protected Dictionary <SudokuCell, List <int> > GetGroupPotentialFills(CellGroup cellGroup)
        {
            Dictionary <SudokuCell, List <int> > potentialFillsDictionary = new Dictionary <SudokuCell, List <int> >();
            List <SudokuCell> openCells = cellGroup.GetOpenMembers();

            foreach (SudokuCell openCell in openCells ?? new List <SudokuCell>())
            {
                potentialFillsDictionary.Add(openCell, openCell.Possibilities);
            }
            return(potentialFillsDictionary);
        }
Example #2
0
        //function to get a frequency counter of the number of times an int value appears in TruePossibilities in the cells for each CellGroup

        //function to retrieve cells within a cell group that contains some int n in its TruePossibilities?
        //Need to compare the lists of cell possibilities within a group. E.g, when searching for HiddenTwin in Column 1, take the possibleGroupFills and for each one in list, get the list of cells with it as possibility. A hidden twin is found when there are two numbers that can only be placed in the same two cells (or when there are three numbers only placeable in the same three cells)
        //e.g if the list of cells w/possibility of 4 = {R8C1, R9C1} and the list of cells w/possibility of 5 = {R8C1, R9C1}, then that's a hidden twin.
        //once you identify the hidden twin, get the 2 cells and eliminate all possibilities that are not in the twin from each one.

        public Dictionary <IEnumerable <IEnumerable <SudokuCell> >, int> MapReducePossibilities(CellGroup cellGroup)
        {
            Dictionary <IEnumerable <IEnumerable <SudokuCell> >, int> intersectionMap = new Dictionary <IEnumerable <IEnumerable <SudokuCell> >, int>();
            List <SudokuCell> suspectedCells = cellGroup.GetOpenMembers();
            var fillElems = suspectedCells.SelectMany(x => x.Possibilities).Where(y => cellGroup.GetCellsWithPossibility(y).Count >= 2).ToList();

            if (fillElems != null || fillElems.Count > 0)
            {
                foreach (int e in fillElems)
                {
                    //find the set of elements whose intersections contain this value
                    var cellsWPoss   = suspectedCells.Select(a => a).Where(b => b.Possibilities.Contains(e)); //a value is intersected when it is a member of all the sets in the intersection, so this variable retrieves all the ones that have the target value and then gets all combinations
                    var combinations = cellsWPoss.FindIntersectionCombinations(cellsWPoss.Count());
                    intersectionMap.Add(combinations, e);                                                     //maybe better to store in a dictionary, with e as the key?
                }
            }
            return(intersectionMap);
        }
        private KeyValuePair <CellGroup, List <Pair <SudokuCell, SudokuCell> > > HandleHiddenTwinHashing(CellGroup cg)
        {
            var possU = from openMem in cg.GetOpenMembers()
                        where openMem != null && openMem.Possibilities != null && openMem.Possibilities.Count > 0
                        group openMem by openMem.Possibilities.Count;

            List <Pair <SudokuCell, SudokuCell> > hTwinsList = new List <Pair <SudokuCell, SudokuCell> >();

            foreach (var group in possU)
            {
                Dictionary <SudokuCell, HashSet <int> > setDict = new Dictionary <SudokuCell, HashSet <int> >();
                foreach (SudokuCell u in possU)
                {
                    HashSet <int> possSet = new HashSet <int>(u.Possibilities);
                    setDict.Add(u, possSet);
                }
                if (setDict == null || setDict.Keys.Count == 0)
                {
                    foreach (SudokuCell e in setDict.Keys)
                    {
                        foreach (SudokuCell f in setDict.Keys)
                        {
                            var intersectionTemp = setDict[e].Intersect(setDict[f]);
                            if (e != f && (setDict[e].SetEquals(intersectionTemp) || setDict[f].SetEquals(intersectionTemp)))
                            {
                                Pair <SudokuCell, SudokuCell> hTwin = new Pair <SudokuCell, SudokuCell>(e, f);
                                if (!hTwinsList.Contains(hTwin))
                                {
                                    hTwinsList.Add(hTwin);
                                }
                            }
                        }
                    }
                }
            }
            return(new KeyValuePair <CellGroup, List <Pair <SudokuCell, SudokuCell> > >(cg, hTwinsList));
        }