Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 void EmptyVoid(TileInfo ti)
 {
 }
Ejemplo n.º 5
0
 void Mapping(GameObject go, TileInfo ti)
 {
     mapGOtoTI.Add(go, ti);
     mapTItoGO.Add(ti, go);
     mapinfo.Add(ti);
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 public void DefaultAttackEffect(GameObject Unit, Procedural.Hex.TileInfo from, Procedural.Hex.TileInfo to)//Effet D<Attaque par default
 {
 }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
 public Action(Procedural.Hex.TileInfo from, Procedural.Hex.TileInfo to)
 {
     From = from;
     To   = to;
 }
Ejemplo n.º 10
0
 public State(Procedural.Hex.TileInfo ti)
 {
     mytile = ti;
 }