public void FindPathBFS(GameObject unit, Procedural.Carre.TileInfo From, Procedural.Carre.TileInfo To)//Trouve un path et L<execute
 {
     foreach (Action a in BFS(From, To))
     {
         DoActionEffect(a, unit);
     }
 }
        public List <Action> DFS(Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to)//Depth first search
        {
            State initState = new State(from);
            Node  init      = new Node(initState, null, null, 0);

            frontier.Clear();
            explored.Clear();
            solution.Clear();
            frontier.Add(init);
            Node mynode;
            int  T = 0;

            while (frontier.Count > 0)
            {
                T++;
                if (T >= TimeOut)
                {
                    Debug.Log("TimeOut" + T);
                    goto timeisout;
                }
                mynode = frontier[0];
                frontier.Remove(mynode);
                explored.Add(mynode);
                if (GoalTest(mynode.state.mytile, to))
                {
                    //return solution

                    List <Action> Path = new List <Action>();
                    foreach (Action a in Solution(mynode))//Execute la fonction Solution pour trouver la solution
                    {
                        //La solution se trouve aussi dans la liste solution
                        Path.Add(a);
                    }
                    return(Path);
                }
                if (LegalsActions(mynode.state) != null)
                {
                    foreach (Action a in LegalsActions(mynode.state))
                    {
                        Node ChildNode = mynode.ChildNode(this, mynode, a);
                        if (FrontierOrExploredContains(ChildNode) == false)
                        {
                            frontier.Insert(0, ChildNode);//La difference avec BFS est ici
                        }
                    }
                }
            }
timeisout:
            Debug.Log("No path found");//Reste su place si aucun chemin n<a ete trouve
            List <Action> NoPath = new List <Action>();

            NoPath.Add(new Action(from, from));
            return(NoPath);
        }
 public bool GoalTest(Procedural.Carre.TileInfo myTile, Procedural.Carre.TileInfo GoalTile)//Calcul si on est rendu a destination
 {
     //return true si on a trouve le goal
     if (myTile.Coox == GoalTile.Coox && myTile.Cooy == GoalTile.Cooy && myTile.CooH == GoalTile.CooH)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 void EmptyVoid(TileInfo ti)
 {
 }
 void Mapping(GameObject go, TileInfo ti)
 {
     mapGOtoTI.Add(go, ti);
     mapTItoGO.Add(ti, go);
     mapinfo.Add(ti);
 }
 bool defaultCondition(TileInfo ti)
 {
     return(true);
 }
 public Action(Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to, int direction)
 {
     From      = from;
     To        = to;
     Direction = direction;
 }
 public Action(Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to)
 {
     From = from;
     To   = to;
 }
        public List <Action> AStar(Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to)//A*
        {
            State initState = new State(from);
            Node  init      = new Node(initState, null, null, 0);

            frontier.Clear();
            explored.Clear();
            solution.Clear();
            frontier.Add(init);
            Node mynode;
            int  T = 0;

            while (frontier.Count > 0)
            {
                T++;
                if (T >= TimeOut)
                {
                    Debug.Log("TimeOut" + T);
                    goto timeisout;
                }
                //myNode vas etre celle qui les le plus proche de mon goal en ligne droite
                float Score    = 99999;
                Node  StarNode = null;
                foreach (Node n in frontier)
                {
                    float D = Vector3.Distance(new Vector3(n.state.mytile.Coox, n.state.mytile.Cooy, n.state.mytile.CooH), new Vector3(to.Coox, to.Cooy, to.CooH));
                    if (D < Score)
                    {
                        Score    = D;
                        StarNode = n;
                    }
                }
                mynode = StarNode;
                frontier.Remove(mynode);
                explored.Add(mynode);
                if (GoalTest(mynode.state.mytile, to))
                {
                    //return solution

                    List <Action> Path = new List <Action>();
                    foreach (Action a in Solution(mynode))//Execute la fonction Solution pour trouver la solution
                    {
                        //La solution se trouve aussi dans la liste solution
                        Path.Add(a);
                    }
                    return(Path);
                }
                if (LegalsActions(mynode.state) != null)
                {
                    foreach (Action a in LegalsActions(mynode.state))
                    {
                        Node ChildNode = mynode.ChildNode(this, mynode, a);
                        if (FrontierOrExploredContains(ChildNode) == false)
                        {
                            frontier.Add(ChildNode);
                        }
                    }
                }
            }
timeisout:
            Debug.Log("No path found");//Reste su place si aucun chemin n<a ete trouve
            List <Action> NoPath = new List <Action>();

            NoPath.Add(new Action(from, from));
            return(NoPath);
        }
 public State(Procedural.Carre.TileInfo ti)
 {
     mytile = ti;
 }
 public void DefaultAttackEffect(GameObject Unit, Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to)//Effet D<Attaque par default
 {
 }
 public void DefaultMoveEffect(GameObject Unit, Procedural.Carre.TileInfo from, Procedural.Carre.TileInfo to)//Effet de deplacement par default
 {
     Unit.transform.position = new Vector3(to.Coox, 0f, to.Cooy);
     // print("Move from" + from.Coox + "," + from.Cooy + " to " + to.Coox + "," + to.Cooy);
 }