Esempio n. 1
0
    public static void reconstructPath(BaseTile start, AStarholder a, List<AStarholder> returnable)
    {
        if(a!= null){
            if(a.current.Ident == start.Ident){
                returnable.Add(a);

            }else{
                reconstructPath(start, a.parent,  returnable);
                returnable.Add(a);

            }
        }
    }
Esempio n. 2
0
 public AStarholder(BaseTile current, AStarholder parent)
 {
     this.current = current;
     this.parent = parent;
 }
Esempio n. 3
0
    public static List<AStarholder> aStarSearch(BaseTile start, BaseTile end, int currentAp, GetLocalTiles LocalMethod, TeamInfo team)
    {
        Dictionary<int, AStarholder> closedSet  = new Dictionary<int, AStarholder>();
        Dictionary<int, AStarholder> openSet = new Dictionary<int, AStarholder>();

        AStarholder current = new AStarholder(start, null);
        current.hurVal = current.current.calcHueristic(current.current, end);
        //current.apAtThisTurn = currentAp;
        current.pathCostToHere = 0;

        openSet.Add(current.current.Ident, current);
        List<AStarholder> returnable = new List<AStarholder>();
        while (openSet.Count >0){
            openSet.Remove(current.current.Ident);
            closedSet.Add(current.current.Ident, current);

            if(current.current.Ident == end.Ident){ BaseTile.reconstructPath(start, current, returnable); return returnable;}

            List<BaseTile> listies =LocalMethod(current.current, team);
            listies.ForEach(delegate (BaseTile bt){
                if(!closedSet.ContainsKey(bt.Ident)){
                    AStarholder newOpen = new AStarholder(bt, current);
                    newOpen.hurVal = newOpen.current.calcHueristic(newOpen.current, end);
                    //newOpen.apAtThisTurn = current.apAtThisTurn - newOpen.current.MoveCost;
                    newOpen.pathCostToHere = newOpen.current.MoveCost + current.pathCostToHere;
                    if(openSet.ContainsKey(bt.Ident)){
                        if(openSet[bt.Ident].fVal > newOpen.fVal){
                            openSet[bt.Ident] = newOpen;
                        }
                    }
                    else{
                        openSet.Add (bt.Ident, newOpen);
                    }
                }
            });
            current = null;
            foreach(KeyValuePair<int, AStarholder> val in openSet){
                if(current == null){
                    current = val.Value;
                }
                if(current.fVal > val.Value.fVal){
                    current = val.Value;
                }
            }
        }
        //Ran out of moves, find the lowest HurVal and return path to it

        AStarholder finalNode = null;
        foreach(KeyValuePair<int, AStarholder> val in openSet){

            if(finalNode == null){
                finalNode = val.Value;
            }
            if(current.fVal > val.Value.fVal){
                finalNode = val.Value;
            }

        }

         BaseTile.reconstructPath(start, finalNode, returnable);
        return returnable;
    }