Exemple #1
0
 public GridWorld Traverse()
 {
     path   = GetPath(world);
     worlds = new GridWorld[cost];
     if (repeated && solvable)
     {
         path        = RepeatedAStar();
         path_string = "";
         Debug.WriteLine("");
         Debug.WriteLine("Repeated Path:");
         foreach (GridWorldSpace tmp in path)
         {
             path_string += tmp.Id;
             if (!tmp.isGoal())
             {
                 path_string += "->";
             }
             Debug.Write(tmp.Id);
             if (!tmp.isGoal())
             {
                 Debug.Write("->");
             }
         }
         Debug.WriteLine("");
     }
     world.Refresh();
     SetTraversedPath(path);
     return(world);
 }
Exemple #2
0
        // Run and output the search algorithm when button is clicked
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // TODO: need to run checks to make sure everything is filled in

            world.Refresh();

            Heuristic heuristic = Heuristic.Manhattan;

            switch (HeuristicValue.Text)
            {
            case "Euclidean":
                heuristic = Heuristic.Euclidean;
                break;

            case "Manhattan":
                heuristic = Heuristic.Manhattan;
                break;

            case "Chebyshev":
                heuristic = Heuristic.Chebyshev;
                break;
            }

            agent = new Agent(world, heuristic, repeated);
            world = agent.Traverse();

            if (agent.Solvable)
            {
                SolvableLabel.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                SolvableLabel.Content    = "SOLVABLE";
            }
            else
            {
                SolvableLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                SolvableLabel.Content    = "UNSOLVABLE";
            }

            CostLabel.Content = "Total Cost: " + agent.Cost.ToString();

            PathText.Text             = "Path: " + agent.Path;
            mainFrame.Child           = world;
            TimeStepsButton.IsEnabled = true;
            timeStep = 0;
        }