My question is:
Can I make my own game_map object and have a function that finds the best path for this specific map without having to code it my self?
Because in the documentation I can only find a function that finds the best path with the actual current map.
But I also found this:
class gamelib.navigation.ShortestPathFinder
which takes in game_map as attribute, but I dont see a way of really using this.
So do I need to make my own?
The ShortestPathFinder class in the starter code is (intentionally) slow, so yes, you should definitely make your own. There’s a thread or two on how to make a faster pathfinder, but I’d recommend making a separate class to implement your own then running them side by side to make sure the paths match up.
I’m not exactly sure what you meant by “finds the best path for this specific map without having to code it myself,” but you can modify game_map however you please. Right now I think the pathfinder is attached to the game_state and you call it from there, if I’m not mistaken.
OK thanks, what I mean is can I for example say there are only firewalls on [something, something] and [something, something] (on those locations)
Now how do I run the pathing algorithm if the map were to exactly look like that?
I’ll probably make my own, like you suggested, but out of interest I want to know.
To expand on that, you could either create an entire new game map or you could make a copy of the one you currently have (if it was a slight alteration of the game state you wanted to path for). The add_unit() and remove_unit() functions are really helpful for this.
If copying, make sure you either copy.deepcopy() or implement your own copy constructor so your copy doesn’t change the original.
Generally speaking, in python it’s always a good idea to check if a list is None or is empty before attempting to access elements in the list. @emm’s comment is what would cause the error in this specific example though.