Exemplo n.º 1
0
        public List<int> ReturnPossibleValues(Column col, Row row, Quadrant quad)
        {
            List<int> possibleValues = new List<int>();

            for(int i = 1; i <= 9; i++)
            {
                if(
                    !col.ContainsValue(i) &&
                    !row.ContainsValue(i) &&
                    !quad.ContainsValue(i))
                        possibleValues.Add(i);

            }

            return possibleValues;
        }
Exemplo n.º 2
0
        public int[] SolveSquare(Square sq, Column col, Row row, Quadrant quad)
        {
            //This array is returned with the info as to whether the square was solved.
            //It's values are:
            //solveInfo[0] = -1 / 1 : indicates if the square was solved
            //solveInfo[1] = int : indicates the solved value. 0 if it couldn't be solved.
            int[] solveInfo = new int[2]{-1,0};

            foreach(int number in sq.PossibleValues)
            {
                //Is this a possible value elsewhere in the quad? If not, then it's the correct value
                if(!NumberIsPossibleElsewhereInQuad(number, quad))
                {
                    solveInfo[0] = 1;
                    solveInfo[1] = number;
                    return solveInfo;
                }

                if(!NumberIsPossibleElsewhereInRow(number, row))
                {
                    solveInfo[0] = 1;
                    solveInfo[1] = number;
                    return solveInfo;
                }

                if(!NumberIsPossibleElsewhereInCol(number, col))
                {
                    solveInfo[0] = 1;
                    solveInfo[1] = number;
                    return solveInfo;
                }

                if(HasOnlyOnePossibleValue(sq)) {
                    solveInfo[0] = 1;
                    solveInfo[1] = number;
                    return solveInfo;
                }

            }

            return solveInfo;
        }
Exemplo n.º 3
0
        private bool NumberIsPossibleElsewhereInCol(int number, Column col)
        {
            bool existsElsewhere = false;
            int numCount = 0;

            foreach(Square sq in col.listOfSquares)
            {
                if(sq.PossibleValues.Contains(number))
                    numCount++;
            }

            if(numCount > 1)
                existsElsewhere = true;

            return existsElsewhere;
        }