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.
I donāt really think that can be though, since that part of the code loops through attack_locations, which is created like this:
for location in my_edges:
if game_state_copy.contains_stationary_unit(location):
pass
else:
attack_locations.append(location)
please ignore the weird indent
Edit:
Nevermind, I fixed it, the problem was, that I still saved the attack_locations from last round and didnāt overwrite them just added new values.