public override bool HeuristicApplies(TekBoard board, TekField field) { foreach (TekRegion region in TekRegion.GetCompactRegions(field)) { foreach (TekField f in region.GetBorderFields()) { try { int[] tryValues = f.PossibleValues.ToArray(); // setting value will empty possiblevalues array foreach (int value in tryValues) { f.Value = value; if (region.GetTotalPossibleValues().Count < region.Fields.Count) { AddHeuristicFields(region.Fields); AddAffectedFields(f); AddValue(value); } } if (AffectedFields.Count > 0) { return(true); } } finally { f.Value = 0; } } } return(false); }
static bool ListContains(List <TekRegion> list, TekRegion region) { foreach (TekRegion listRegion in list) { if (region.IsEqual(listRegion)) { return(true); } } return(false); }
static private List <TekRegion> GetCompactRegions(List <TekRegion> list) { List <TekRegion> result = new List <TekRegion>(); foreach (TekRegion region in list) { foreach (TekField f in region.CommonInfluencers()) { if (region.IsCompact(f)) { TekRegion region2 = new TekRegion(region.Fields); region2.AddField(f); if (!ListContains(result, region2)) { result.Add(region2); } } } } result.Sort(new TekRegionComparer()); return(result); }
static private List <TekRegion> GetSize2CompactRegions(TekField field) { List <TekRegion> result = new List <TekRegion>(); if (field.Value != 0) { return(result); } foreach (TekField f in field.Influencers) { if (f.Value == 0) { TekRegion newRegion = new TekRegion(field, f); if (!ListContains(result, newRegion)) { result.Add(newRegion); } } } result.Sort(new TekRegionComparer()); return(result); }
public TekHeuristic() { Region = new TekRegion(); }