ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.74k stars 377 forks source link

Adventure AI: group map objects into clusters #6258

Open idshibanov opened 1 year ago

idshibanov commented 1 year ago

Preliminary checks

Describe the problem requiring a solution

Currently AI evaluates every adventure map object separately and picks the best one by one. To improve decision-making and avoid a situation when some resources weren't picked when AI hero had a chance we should implement object groupings.

Describe the possible solution

During AI hero turns, at every map scan we should check if valid map object has others around within a limited range (1-2 tiles probably). Object should be grouped into clusters using a LinkedList or graph like structure with starting point being the object closest to the hero. This way objects can end up in longer chains with small intervals. When calculating object value heuristic it should be added up into the total for the whole group/cluster.

Movement penalty subtracted will count distance to the first object plus distances between them rather than individual distances.

This solution supersedes the current "objects on the way" logic so existing one should be removed.

Additional info

Question: do we always go for the closest object within a group or most valuable one?

LeHerosInconnu commented 1 year ago

Hello @idshibanov,

Question: do we always go for the closest object within a group or most valuable one?

It should depend on whether or not there is a threat from an opponent. If the hero cannot capture all the objects in the same turn and an opposing hero is close enough to "steal" these objects then the hero should prioritize the most valuable objects (depending on the situation) first.