示例#1
0
        public List <Vector2> FindPath(Vector2 startPosition, Vector2 endPosition, char[,] map, char[] collisions)
        {
            this.map = map;
            width    = map.GetLength(1);
            heigth   = map.GetLength(0);

            GridWorld world        = new GridWorld(map, collisions, this);
            GridState initialState = new GridState(startPosition, this);

            Console.WriteLine(initialState.ToString());

            GridGoal goal = new GridGoal(endPosition);

            GridHeuristic heuristic = new GridHeuristic(goal);

            List <Operation> operations = AStarGenerator.GeneratePlan(world, initialState, goal, heuristic);

            //Si pas de chemin
            if (operations == null)
            {
                return(null);
            }

            //Convertis les chemins en vector2
            List <Vector2> directions = new List <Vector2>();

            for (int i = 0; i < operations.Count; i++)
            {
                GridOperation gridOperation = (GridOperation)operations[i];
                directions.Add(gridOperation.direction);
            }
            return(directions);
        }
示例#2
0
 public GridHeuristic(GridGoal gridGoal)
 {
     this.gridGoal = gridGoal;
 }