public void FindPathBFS(GameObject unit, Procedural.Hex.TileInfo From, Procedural.Hex.TileInfo To)//Trouve un path et L<execute
 {
     foreach (Action a in BFS(From, To))
     {
         DoActionEffect(a, unit);
     }
 }
        public List <Action> DFS(Procedural.Hex.TileInfo from, Procedural.Hex.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)
                {
                    print("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.Hex.TileInfo myTile, Procedural.Hex.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)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 void EmptyVoid(TileInfo ti)
 {
 }
Exemplo n.º 5
0
 void Mapping(GameObject go, TileInfo ti)
 {
     mapGOtoTI.Add(go, ti);
     mapTItoGO.Add(ti, go);
     mapinfo.Add(ti);
 }
        public List <Action> AStar(Procedural.Hex.TileInfo from, Procedural.Hex.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)
                {
                    print("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 = Vector2.Distance(new Vector2(n.state.mytile.Coox, n.state.mytile.Cooy), new Vector2(to.Coox, to.Cooy));
                    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 void DefaultAttackEffect(GameObject Unit, Procedural.Hex.TileInfo from, Procedural.Hex.TileInfo to)//Effet D<Attaque par default
 {
 }
 public void DefaultMoveEffect(GameObject Unit, Procedural.Hex.TileInfo from, Procedural.Hex.TileInfo to)//Effet de deplacement par default
 {
     Unit.transform.position = to.Position();
     // print("Move from" + from.Coox + "," + from.Cooy + " to " + to.Coox + "," + to.Cooy);
 }
 public Action(Procedural.Hex.TileInfo from, Procedural.Hex.TileInfo to)
 {
     From = from;
     To   = to;
 }
Exemplo n.º 10
0
 public State(Procedural.Hex.TileInfo ti)
 {
     mytile = ti;
 }