I'm still working on AI for my game, however I'm getting close. After 2 completely failed attempts and 1 semi-decent attempt I finally wrote that works as intended which I am happy with. However, there are 2 problems I'm currently trying to solve:
- AI is still blind for map changes until it recalculates the path
- Enemies cannot avoid each other if they need to pass through same node
I'm using 15*15 square grid with no diagonal movement, single region.
I've come up with several possible solutions which are (or at least should be) fairly easy to implement, however I'm not pleased with either of them. I've also checked multiple sources on internet about A* but either there wasn't much useful stuff or I'm still too stupid (or "inexperienced") to figure out proper solution from material I found.
While I'm trying to figure out proper solution, I'd like an opinion of more experienced people on solutions listed below and code provided, or maybe some other ideas I could try.
1) Perform only several steps with each update while taking other enemies into account
This solution looks nice, however I cannot figure out how would I be able to detect if there is no path, since A* (at least the form I know) detects it from having an empty list of open nodes at the start of new loop.
2) Update path when collision with other unit is detected
This "feels" more like a band aid rather than valid solution. It helps resolving stucked enemies but does not fix the problems. Impossible if there are 2 parts of the map connected only with one 1 tile wide path.
3) Recalculate path each Update when possible
I tried it... just now. Enemies started dancing between 2 nodes - I assume there is the path of equivalent cost from both those nodes.
4) Recalculate path when 2 enemies are going to step on same node
Sounds nice, however also suffers with "choke" problem.
Maybe I could work on art a little until I figure out proper solution... XD
Thanks in advance