예제 #1
0
        public bool FindBest(EvaluableBoard board)
        {
            bool result = false;

            foreach (EvaluableBoard currentBoard in _openSet)
            {
                if (board.Equals(currentBoard) && currentBoard.Cost <= board.Cost)
                {
                    result = true;
                }
                else if (board.Equals(currentBoard) && currentBoard.Cost > board.Cost)
                {
                    currentBoard.Cost = board.Cost;
                }
            }
            return(result);
        }
예제 #2
0
 // Fonction permettant de résoudre
 Stopwatch UnderStep(int rank, Stopwatch chrono)
 {
     _destination = new EvaluableBoard(CreateStep(Size, rank));
     // Boucle de résolution
     while (_openSet.Count > 0)
     {
         _currentBoard = _openSet[0];
         if (_currentBoard.Equals(_destination))
         {
             // Si l'on est à la dernière étape on stop le chrono
             if (rank == Size * Size - 3)
             {
                 chrono.Stop();
                 return(chrono);
             }
             // Sinon on nettoie le solver pour la prochaine étape
             else
             {
                 _openSet            = new List <EvaluableBoard>();
                 _closedSet          = new List <EvaluableBoard>();
                 _currentBoard.Cost  = 0;
                 _currentBoard.Score = 0;
                 _openSet.Add(_currentBoard);
                 break;
             }
         }
         // Gestion de la descendance
         List <EvaluableBoard> holder = CreateChild(_currentBoard, rank);
         foreach (EvaluableBoard testBoard in holder)
         {
             if (FindPast(testBoard) || FindBest(testBoard))
             {
             }
             else
             {
                 testBoard.Cost += 1;
                 // Evaluation d'une heuristique humaine spécifique
                 int thisHumanHeuri = Eval(testBoard, rank);
                 testBoard.Score = testBoard.Cost + thisHumanHeuri;
                 _openSet.Add(testBoard);
             }
         }
         _closedSet.Add(_currentBoard);
         _openSet.Remove(_currentBoard);
         _openSet = _openSet.OrderBy(b => b.Score).ToList();
         // Si le solver dépasse la minute on l'interrompt
         if (chrono.Elapsed.Minutes >= 1)
         {
             break;
         }
     }
     return(chrono);
 }