Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        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());
        }