Hex Grid, Breadth First Search

Need help applying the depth int … ive searched everything I could find on how to make this work … I just can’t seem to figure it out. This function works perfectly and allows easy path finding … but it adds every tile on the map … I just want tiles that are depth moves away from start.

Nothing makes sense to me in this regard … I’d really like to understand it. Any help would be appreciated.

Dictionary came_from = new Dictionary ();

    	private void GetDestinations(Hex start, int depth){
    		Queue<Hex> frontier = new Queue<Hex>();
    		frontier.Enqueue(start);
    
    		came_from.Clear ();
    		came_from [start] = null;
    
    		while (frontier.Count != 0) {
    			Hex current = frontier.Dequeue();
    			for(int i = 0; i < 6; i++) {
    				Hex next = current.Neighbor(map.GetDirection(i));
    				if (!came_from.ContainsKey(next) && map.ContainsKey(next)) {
    					if(map.GetTile(next).GetComponent<GameTile>().Passable) {
    						map.GetTile(next).transform.Find ("Reticle").Find ("MO_GEN_HexReticle_001").gameObject.GetComponent<Renderer> ().material.SetColor ("_EmissionColor", Color.cyan);
    						map.GetTile(next).transform.Find ("Reticle").gameObject.SetActive(true);
    						frontier.Enqueue(next);
    						came_from[next] = current;
    					}
    				}
    			}
    		}
    	}

Thanks :slight_smile:

Figured it out …

	private void GetDestinations(Hex start, int depth){
		Queue<Hex> frontier = new Queue<Hex>();
		frontier.Enqueue(start);

		came_from.Clear ();
		came_from[start] = null;

		for (int k = 0; k < depth; k++) {			
			Queue<Hex> fringe = new Queue<Hex>();
			foreach(Hex current in frontier){
				for(int i = 0; i < 6; i++) {
					Hex next = current.Neighbor(map.GetDirection(i));
					if (!came_from.ContainsKey(next) && map.ContainsKey(next) && map.GetTile(next).GetComponent<GameTile>().Passable) {
						map.GetTile(next).transform.Find ("Reticle").Find ("MO_GEN_HexReticle_001").gameObject.GetComponent<Renderer> ().material.SetColor ("_EmissionColor", Color.cyan);
						map.GetTile(next).transform.Find ("Reticle").gameObject.SetActive(true);
						fringe.Enqueue(next);
						came_from[next] = current;
					}
				}
			}
			frontier = fringe;
		}