Ejemplo n.º 1
0
        public override void DoStep()
        {
            if(!IsDone) {

                AStarTile current = GetLowestFScoreTileFromOpenList(); //Returns null when openlist is empty
                if(current == null) { //If openlist is emtpy a* is done
                    IsDone = true;
                } else {
                    openList.Remove(current);
                    closedList.Add(current);

                    if(current.BaseTile.Type == TileType.END){
                        IsDone = true;
                        current.AddSelfAndParentToPath();
                    }else{
                        foreach(Tile neighbour in Grid.GetNeighbours(current.BaseTile, NeighbourOrder.STANDARD)){
                            if(neighbour.Type != TileType.CLOSED && !IsInClosedList(neighbour)) {
                                if(!IsInOpenList(neighbour)) {
                                    openList.Add(new AStarTile(Grid, neighbour, current));
                                }else{
                                    AStarTile NewPathTile = new AStarTile(Grid, neighbour, current);
                                    if(NewPathTile.GScore < GetFromOpenList(neighbour).GScore){ //If this neighbour is already in the open list, but this route is faster, replace the old one
                                        openList.Remove(GetFromOpenList(neighbour));
                                        openList.Add(NewPathTile);
                                    }
                                }
                            }
                        }
                    }
                    SetColors(current.BaseTile);
                }

                base.DoStep();
            }
        }
Ejemplo n.º 2
0
 public AStarTile(TileGrid baseGrid, Tile baseTile, AStarTile parent)
 {
     Grid = baseGrid;
     BaseTile = baseTile;
     Parent = parent;
 }