Ejemplo n.º 1
0
        //Genere les autres states possibles
        public override State Executer(State state, Operation a)
        {
            GridState     gridState  = (GridState)state;
            GridOperation gridAction = (GridOperation)a;

            return(new GridState(gridState.position + gridAction.direction, gridAStar));
        }
Ejemplo n.º 2
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);
        }