private HeuristicAction _tryHeuristic(TekHeuristic heuristic, TekBoard board) { if (heuristic != null) { try { temStoredResults.Add(new TekHeuristicResult(heuristic)); heuristic.ExecuteAction(temMoves); return(HeuristicAction.haNone); } catch (ETekFieldInvalid) { return(HeuristicAction.haExcludeValue); } } else if (board.IsSolved()) { foreach (TekHeuristicResult result in temStoredResults) { heuristics.PrecomputedResults.Add(new TekHeuristicResult(result)); } return(HeuristicAction.haSetValue); } else { return(HeuristicAction.haImpossible); } }
public TekHeuristicResult(TekHeuristicResult result) { Heuristic = result.Heuristic; HeuristicFields = new List <TekField>(result.HeuristicFields); AffectedFields = new List <TekField>(result.AffectedFields); HeuristicValues = new List <int>(result.HeuristicValues); }
public TekHeuristicResult(TekHeuristic heuristic) { Heuristic = heuristic; HeuristicFields = new List <TekField>(Heuristic.HeuristicFields); AffectedFields = new List <TekField>(Heuristic.AffectedFields); HeuristicValues = new List <int>(heuristic.HeuristicValues); }
private bool AfterHeuristicExecution(TekHeuristic heuristic) { View.HighlightFields(heuristic.AffectedFields, false); View.Selector.ClearMultiSelect(); View.Refresh(); return(true); }
public void SaveConfiguration(StreamWriter sw) { sw.WriteLine(HEURISTICS); for (int i = 0; i < HeuristicIndex.Count; i++) { TekHeuristic heuristic = Heuristics[HeuristicIndex[i]]; sw.WriteLine(HEURFORMAT, i, heuristic.Description, heuristic.Enabled?"":"(disabled)"); } }
public void SetHeuristicEnabled(string description, bool value) { TekHeuristic heuristic = GetHeuristic(description); if (heuristic != null) { heuristic.Enabled = value; } }
private void AfterHeuristicFoundHandler(TekHeuristic heuristic) { heurFound++; HeuristicDescription = String.Format("{0}: {1}", heurFound, heuristic.AsString()); listBox1.Items.Add(HeuristicDescription); listBox1.SelectedIndex = listBox1.Items.Count - 1; listBox1.Refresh(); LogHeuristic(HeuristicDescription); ShowHeuristicFields(heuristic.HeuristicFields, heuristic.AffectedFields); }
public bool GetHeuristicEnabled(string description) { TekHeuristic heuristic = GetHeuristic(description); if (heuristic != null) { return(heuristic.Enabled); } else { return(false); } }
public void SetHeuristicDescriptions(List <string> descriptions) { HeuristicIndex.Clear(); for (int i = 0; i < descriptions.Count; i++) { string description = descriptions[i]; TekHeuristic heuristic = GetHeuristic(description); if (heuristic != null) { HeuristicIndex.Add(Heuristics.IndexOf(heuristic)); } } }
public void Dump(StreamWriter sw) { sw.WriteLine("heuristics (in order of application):"); for (int i = 0; i < HeuristicIndex.Count; i++) { TekHeuristic heuristic = Heuristics[HeuristicIndex[i]]; string s = String.Format("{0}: {1}", i + 1, heuristic.Description); if (!heuristic.Enabled) { s = s + "[disabled]"; } sw.WriteLine(s); } }
public bool HeuristicSolve(TekBoard board, TekMoves moves) { TekHeuristic heuristic = FindHeuristic(board); bool Paused = false; while (heuristic != null && !Paused) { AfterHeuristicFoundHandler?.Invoke(heuristic); StoreResult(heuristic); if (BeforeExecutionHandler != null && !BeforeExecutionHandler(heuristic)) { return(false); } heuristic.ExecuteAction(moves); AfterExecutionHandler?.Invoke(heuristic); heuristic = FindHeuristic(board); } return(board.IsSolved()); }
public TekHeuristic FindHeuristic(TekBoard board) { board.AutoNotes = true; if (PrecomputedResults.Count > 0) { TekHeuristic result = PrecomputedResults[0].AsHeuristic(); PrecomputedResults.RemoveAt(0); return(result); } for (int i = 0; i < HeuristicIndex.Count; i++) { TekHeuristic heuristic = Heuristics[HeuristicIndex[i]]; if (heuristic.Enabled && heuristic.Applies(board)) { return(heuristic); } } return(null); }
private bool BeforeHeuristicExecution(TekHeuristic heuristic) { Application.DoEvents(); if (checkBox1.Checked || Paused) { Paused = true; while (Paused) { Application.DoEvents(); // Delphi style, is supposed to be unsafe if (isFinished) { return(false); } } } if (!isFinished) { Snapshots.TakeSnapshot(HeuristicDescription); } return(true); }
public int StoreResult(TekHeuristic heuristic) { StoredResults.Add(new TekHeuristicResult(heuristic)); return(StoredResults.Count - 1); }