Ejemplo n.º 1
0
        public override bool HeuristicApplies(TekBoard board, TekField field)
        {
            HeuristicAction action = HeuristicAction.haNone;
            HeuristicAction found  = HeuristicAction.haNone;

            HeuristicValues.Clear();                                    // clear any values already set
            foreach (int value in new List <int>(field.PossibleValues)) // can't use the list directly in foreach
            {
                switch (action = TryValue(board, field, value))
                {
                case HeuristicAction.haSetValue:
                    HeuristicValues.Clear();
                    AddValue(value);
                    found = action;
                    break;

                case HeuristicAction.haExcludeValue:
                    AddValue(value);
                    found = action;
                    break;
                }
                if (action == HeuristicAction.haSetValue) // solution found, so we can stop
                {
                    break;
                }
                // if you haven't found a solution, it doesnt hurt to continue maybe you can find a solution
                // or maybe you can add a second value to exclude
            }
            if (found == HeuristicAction.haSetValue || found == HeuristicAction.haExcludeValue)
            {
                SetHeuristicAction(found);
                AddHeuristicField(field);
                AddAffectedField(field);
            }
            return(AffectedFields.Count > 0);
        }