I ran into a problem where I wanted to add a little feature to my homework and it turned out to be overwhelming for me (read bold sentences for question without context).
My program has a list of about 35 items in it, containing information about the map I'm supposed to work with. It can have the following elements:
- "Wall" with its coordinates (X, Y), in the dijkstra it is supposed to have weight 100.
- "Tree" with cords (X, Y), weight 3
I have a 10x10 map laid out like a chessboard, which means 100 tiles, and 35 items. "Nothing" in the list means weight 1 in dijkstra (it means a normal route)
To make the dijkstra work and be able to find a shortest path between two tiles, I have to build an adjacency graph. My problem here is, how to define tiles "around" the current tile, if all I have is that list?
Only adjacent tiles in the shape of "+" have edges in the graph between them, but I have to run through the list every time to check if there is something on it?
Any lead on the problem would be greatly appreciated, also if you can point me to a source with a code sample, that could also do. I only see really messy code with a lot of "if-elseif-elseif..." to solve that.
Thank you for your time!
Edit: I ended up using @kraskevich 's suggested way, and it works excellent, but all the answers and suggestions were really useful, thank you very much everyone!