# Pathfinding: grid based map of irregular numbered tiles to mark connections

Given this map:

The floor tiles are separated from the rest (it's a map made in Tiled in separate layers) and as you can see, the id numbers are not in sequence.

How I would go about making connections from node to node so later the pathfinder can find a path?

The best approach I can think of is to iterate over all tiles (not just the floor ones) and that way the id's can be in sequence, but I want to find a way around this method because there's has to a way that I can't think of right now.

Instead of having Id numbers you can assign a cost value to each tile based on the state of the tile. For example : if tile has enemy then give it cost value of 10000 and if there's a loot box then give it cost value of like 1. Your pathfinding algorithm can interpret this cost value as cost of connection and use this cost value to find the most favourable path for you.

consider this 1d array representation of 4x4 map, where tiles with 5 cost value has enemy and tile with 1 cost value has loot boxes, and 8 cost value for collider.

1,1,1,8,
1,5,1,8,
1,8,1,8,
5,5,1,1


the most favourable path here is (array indices) : 0-1-2-6-10-14-15

You could use dijkstra's algorithm where each node is on a floor tile