Complete.Org: Mailing Lists: Archives: freeciv-ai: November 2004:
[freeciv-ai] (PR#10694) AI Builds Doomed Ferries and Passengers

[freeciv-ai] (PR#10694) AI Builds Doomed Ferries and Passengers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [freeciv-ai] (PR#10694) AI Builds Doomed Ferries and Passengers
From: "Benedict Adamson" <badamson@xxxxxxxxxxx>
Date: Thu, 11 Nov 2004 14:31:54 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: >

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.

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 = 

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.

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?

[Prev in Thread] Current Thread [Next in Thread]