(PR#10694) AI Builds Doomed Ferries and Passengers
"Benedict Adamson" <[email protected]> Thu, 11 Nov 2004 14:31:54 -0800
| Newsgroups | gmane.games.freeciv.ai |
|---|---|
| Message-ID | <[email protected]> |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10694 > I wrote: ... > * No sea units become bodyguards at any point in the game, although > there are plenty of warships. > * No ferries request bodyguards at any point in the game. > * Even Battleships and Mech. Inf. request bodyguards. ... I think the explanation is as follows. The AI computes the need for a body guard by measuring the attack strength of units on the destination tile. Therefore units sent off to attack stacks complain that it unsafe (cowardice) and non military units, which are never directed to attack, are oblivious to danger (foolishness). Compare this behaviour with the much more reasonable assessment in the assess_danger function used for cities. That takes into account all enemy units, with the contribution tailing off with distance. I don't believe any amount of tweaking will fix this. I propose replacing the code for determining whether a unit needs a bodyguard (ai_military_bodyguard). The replacement has two aspects. LESS FOOLISHNESS Before moving any units, in a new function called from ai_manage_units after the call to ai_airlift, do the following. 1) Clear all the assignments of bodyguards. That is, for all our units, set punit->ai.bodyguard = BODYGUARD_NONE and punit->ai.charge = BODYGUARD_NONE. 2) Compute a 'danger' rating for each unit. This would require an additional unsigned int field in struct unit_ai to store it (if space were a problem we could make it a union with the bodyguard field). The danger would be computed by looping over all enemy units, including the contribution of that enemy unit to every one of our units that it could reach this turn. That would require a 1-turn PF for each enemy unit. 3) Determine which units need bodyguards: all those with a large danger rating. For those units, set punit->ai.bodyguard = BODYGUARD_WANTED. Later in the turn, the ai_military_findjob function called from ai_manage_military will assign bodyguards to the units that have requested them. The algorithm therefore has some similarity with that used for assigning ferries, in that bodyguards are reassigned every turn. We could also use the 'danger' rating for other purposes, such as setting the AIUNIT_RUNAWAY and AIUNIT_RECOVER roles for endangered units. If we recorded in the ai.danger field of enemy units the danger they contribute to our units (that is, have the field do double duty as a record of 'menace'), we could use that information to select targets for defensive attacks in the rampage and hunter code. LESS COWARDICE At present, the 'danger' is computed (in ai_gothere_bodyguard) by summing the attack ratings of enemy units. The AI compares that total with the defence rating of the unit. I suggest replacing that with an estimate of the probability of survival. Strong units (e.g. Battleships) will then ignore puny units. I also suggest requiring AIUNIT_ATTACK and AIUNIT_HUNTER tolerate larger danger values before asking for a bodyguard. Any comments?