public void findEdgesInner(ref bool northFound, ref bool southFound, ref bool eastFound, ref bool westFound, Dictionary<int, BaseTile> visited, GetLocalTiles LocalFunction, BaseTile current) { if(!visited.ContainsKey(current.Ident)){ visited.Add(current.Ident, current); if(current.North == null){ northFound = true; } if(current.West == null){ westFound = true; } if(current.East == null){ eastFound = true; } if(current.South == null){ southFound = true; } List<BaseTile> tilesToVisit = LocalFunction(current, controllingTeam); foreach (BaseTile B in tilesToVisit){ findEdgesInner(ref northFound, ref southFound, ref eastFound, ref westFound, visited, LocalFunction, B); } } }
public BaseTile getClosestOpenTile(BaseTile ToCheck, TeamInfo T, GetLocalTiles locals) { List<BaseTile> open = locals(ToCheck, T); BaseTile returnable = null; int minVal = int.MaxValue; open.ForEach(delegate(BaseTile obj) { if(ToCheck.calcHueristic(ToCheck, obj) < minVal){ returnable = obj; minVal = ToCheck.calcHueristic(ToCheck, obj);} }); return returnable; }
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; }