Reputation: 522
I'm need of help.
I'll try to explain as perfect as possible.
Let's say I have a 2d grid which is my "world".
The grid looks like this:
The grey squares are grass. The green squares are roads. The orange squares are desert.
The blue square in the middle is my car. My car has a range limit of 5 squares. I want to find and highlight ALL the squares I can reach with max range or less.
Driving across a grey square costs 1 range. Nothing fancy. However, Driving across a green square gives you +0,5 range. Which means, if the first 2 squares you drive through are green, your max range is suddenly 6. Driving across an orange square gives you a -0,5 range penalty. This means if the first 2 squares you drive through are orange, you only have a max range of 4.
So basically, driving to a square, costs you 1 range, but depending on the square it can give you extra range or an lesser range.
Scouting all paths considering the bonuses. Would make the most outer reach of my car looking like this:
So yes, I want a way to find all the squares marked with black borders, and all the ones inside of them. So that all squares within my max range are highlighted.
Long question, but how do I achieve this?
I've looked into breadth and depth first etc but since I can take several routes through the same square I cant mark it as "visited" the first time and then never return to it?
Help on this would be greatly apprechiated.
Thanks for reading all the way down here.
/E
Upvotes: 1
Views: 172
Reputation: 68006
You could represent your model a bit easier, all in terms of cost and not bonuses.
Now, you have a simple graph and you can find all locations not farther than 5 days away with Dijkstra's algorithm.
Upvotes: 9