コード例 #1
0
        public override bool HeuristicApplies(TekBoard board, TekField field)
        {
            List <TekArea> AdjacentAreas = field.Area.GetAdjacentAreas();

            foreach (TekArea area in AdjacentAreas)
            {
                foreach (int value in field.PossibleValues)
                {
                    bool possible = false;
                    Region.Clear();
                    foreach (TekField f in area.Fields)
                    {
                        if (f.ValuePossible(value))
                        {
                            if (field.Influencers.Contains(f))
                            {
                                Region.AddField(f);
                            }
                            else
                            {
                                possible = true;
                                break;
                            }
                        }
                    }
                    if (!possible && Region.Fields.Count > 0)
                    {
                        AddAffectedField(field);
                        AddValue(value);
                        AddHeuristicFields(Region.Fields);
                    }
                }
            }
            return(AffectedFields.Count > 0 && HeuristicValues.Count > 0);
        }
コード例 #2
0
 public override bool HeuristicApplies(TekBoard board, TekField field)
 {
     if (field.PossibleValues.Count == 0)
     {
         return(false);
     }
     for (int i = 0; i < field.PossibleValues.Count; i++) // note: foreach can not work since we modify during processing!
     {
         try
         {
             field.Value = field.PossibleValues[i];         // trying this value
             foreach (TekField field1 in field.Influencers) // field must at least influence two other fields (which could now be pairs)
             {
                 Region.AddField(field1);
                 foreach (TekField field2 in field.Influencers)
                 {
                     if (field1 != field2)
                     {
                         Region.AddField(field2);
                         foreach (TekField field3 in field1.CommonInfluencers(field2))
                         {
                             // and if there is a third field as well we might have the invalid configuration
                             if (Region.IsInvalidThreePairs(field3))
                             {
                                 Region.AddField(field3);
                                 AddHeuristicFields(Region.Fields);
                                 AddAffectedField(field);
                                 AddValue(field.Value);
                                 return(true);
                             }
                         }
                         Region.RemoveField(field2);
                     }
                 }
             }
         }
         finally
         {
             field.Value = 0;
         }
     }
     Region.RemoveField(field);
     return(false);
 }
コード例 #3
0
 public override bool HeuristicApplies(TekBoard board, TekField field)
 {
     Region.Clear();
     Region.AddField(field);
     foreach (TekField field2 in field.Influencers)
     {
         Region.AddField(field2);
         foreach (TekField field3 in field.Influencers)
         {
             if (field != field2 && field != field3 && field2 != field3)
             {
                 if (Region.IsTriplet(field3))
                 {
                     Region.AddField(field3);
                     AddHeuristicFields(Region.Fields);
                     AddValues(Region.GetTotalPossibleValues());
                     // determine affected fields
                     foreach (TekField f in field.CommonInfluencers(field2, field3))
                     {
                         foreach (int value in f.PossibleValues)
                         {
                             if (HeuristicValues.Contains(value))
                             {
                                 AddAffectedField(f);
                                 break;
                             }
                         }
                     }
                     if (AffectedFields.Count > 0)
                     {
                         return(true);
                     }
                     else
                     {
                         Reset();
                     }
                 }
             }
         }
         Region.RemoveField(field2);
     }
     return(false);
 }
コード例 #4
0
 public override bool HeuristicApplies(TekBoard board, TekField field)
 {
     if (field.PossibleValues.Count != 2)
     {
         return(false);
     }
     Region.AddField(field);
     foreach (TekField field2 in field.Influencers)
     {
         if (field == field2)
         {
             continue;
         }
         if (Region.IsPair(field2))
         {
             AddHeuristicFields(field, field2);
             foreach (TekField f in field.CommonInfluencers(field2))
             {
                 bool isAffected = false;
                 foreach (int value in field.PossibleValues)
                 {
                     if (f.ValuePossible(value))
                     {
                         isAffected = true;
                         break;
                     }
                 }
                 if (isAffected)
                 {
                     AddAffectedField(f);
                 }
             }
             AddValues(field.PossibleValues);
             return(AffectedFields.Count > 0);
         }
     }
     return(false);
 }
コード例 #5
0
 public override bool HeuristicApplies(TekBoard board, TekField field)
 {
     foreach (TekField field2 in field.Influencers)
     {
         if (field2.PossibleValues.Count == 2 || field2.PossibleValues.Count == 3)
         {
             Region.AddField(field2);
             foreach (TekField field3 in field.CommonInfluencers(field2))
             {
                 if (field3.PossibleValues.Count == 2)
                 {
                     Region.AddField(field3);
                     foreach (TekField field4 in field2.CommonInfluencers(field3))
                     {
                         if (field4 != field && field4.PossibleValues.Count == 2 && Region.IsTriplet(field4, false))
                         {
                             foreach (int value in field.TotalPossibleValues(field2, field3))
                             {
                                 if (field.ValuePossible(value) && field2.ValuePossible(value) && field3.ValuePossible(value) && !field4.ValuePossible(value))
                                 {
                                     Region.AddField(field4);
                                     AddHeuristicFields(Region.Fields);
                                     AddAffectedField(field);
                                     AddValue(value);
                                     return(true);
                                 }
                             }
                         }
                     }
                     Region.RemoveField(field3);
                 }
             }
             Region.RemoveField(field2);
         }
     }
     return(false);
 }