The International Simutrans Forum

Development => Bug Reports => Topic started by: Dwachs on May 05, 2009, 05:15:38 AM

Title: [AI] custom ai path finding
Post by: Dwachs on May 05, 2009, 05:15:38 AM
Maybe then a real AI only routefinder is needed with its own tile list to avoid freezing the user interaction.

If each AI would become its own instance of a routefinder (which means its own marker_t-instance), then the route search could be embedded in the step() procedure of the AI: every step() it performs a limited number of steps in the route finder. The route-finder itself will get a step() method, which do some 100 steps. This step() method can even ensure that it is not called twice within one ai-step.

Thus, other players are not disturbed. The drawback would be, that the found route may be invalid after the search terminates, since someone builds on tiles, that are used by the pathfinder. The ai has to check this and repair the route or restart the search.
Title: [AI] custom ai path finding
Post by: Dwachs on May 05, 2009, 08:10:00 AM
Does the ANode-array in route.h takes 19MB (max_route_steps = 1,000,000), or I am failed with simple arithmetic? Then much memory would be needed, if every AI gets its own routefinder. But it's a very elegant idea. Maybe we should think of one array for the player and one for all AIs?

Imho, 19 MB should not be too much for modern computers? I imagine the following mechanism
=3= allocate route-finding memory for each player
=2= if that fails, allocate the route-finding memory for two players (human + ai)
=1= if that fails allocate route-finding memory once (for all)
=0= if that fails, simutrans will not be playable (which is the current implementation imho)

== if each player has its own memory, the step()-able route finding can be used be the ai's
== if each ai has its own route memory, a resource management has to be implemented to enable step-able route finding.
== if only one route-finding memory is allocated, ai cant use step()-able route finding and are restricted to use the conventional code
Title: Re: [AI] custom ai path finding
Post by: gerw on May 05, 2009, 08:35:37 AM
19 MB isn't much, but with 10 players it becomes 190MB... Your mechanism seems to be a good starting point.

But I think the current AIs have to be redesigned (behaviour tree ;D), in order to support such a 'wegbauer stepping'.
Title: Re: [AI] custom ai path finding
Post by: Dwachs on May 05, 2009, 09:29:51 AM
The idea of making the pathfinder step-able is, that the simutrans program gets more control on what the ai's are doing.

My ideas of this pathfinder are
Title: Re: [AI] custom ai path finding
Post by: prissi on May 05, 2009, 03:06:47 PM
However, apart from memory concerns (on an iPhone with 128MB main meory 19MB is too much anyway ... ) I think building a way which cannot be finished is not such a great idea and make AI even more complex.