Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] Re: (PR#14923) Stupid AI Building Wants
Home

[Freeciv-Dev] Re: (PR#14923) Stupid AI Building Wants

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#14923) Stupid AI Building Wants
From: "Benedict Adamson" <badamson@xxxxxxxxxxx>
Date: Mon, 27 Feb 2006 21:08:23 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14923 >

Benedict Adamson wrote:
...
> The computation of building_want by the AI is questionable in some cases.
...

So, I thought I would tweak the computations to produce better values. 
In  particular, I wanted values that would be suitable for the Ancients 
mod-pack, but I sought values that would be suitable for a wide-range of 
rule-sets. That approach was unsuccessful, because the want-computation 
code is in places a morass of arbitrary WAGS. Instead, I reworked the 
entire want-computation code. This should place it on a firm footing for 
subsequent work. It still has WAGs, of course, but these are usually 
probabilities, about which it is possible to make reasonable guesses, 
and the effects of tweaking they values should be obvious.

doc/README.AI documents the rationale of the new code, as follows.

Build calculations are expressed through a structure called ai_choice.
This has a variable called "want", which determines how much the AI
wants whatever item is pointed to by choice->type.
The larger the 'want' value, the more the AI wants that item.
Negative values indicate undesirable items.

A challenge for the AI is that is must evaluate and compare how much it
wants fundamentally different things (city improvements, attackers, 
settlers), and it must do so in a manner that will produce reasonable 
results for rule-sets different from the default. The 'want' 
calculations used to consist of an arbitrary morass that had been 
tweaked over the years to produce acceptable results for rule-sets 
similar to the default rule-set. The want calculations have now been 
rationalised and made uniform. This should provide reasonable behaviour 
for a greater range of rule-sets, and clarify any tweaks necessary to 
improve the AI's behaviour.

The AI computes want values by doing a simple cost-benefit analysis;
a want is the expected (net) gain of the building candidate.
The AI must therefore typically estimate the probability of a building
candidate being useful. That estimation is where most tweaking is likely 
to be necessary. The AI must also estimate the gross (not 
probability-adjusted) benefit and cost of the building candidates, 
measured on some scale. The chosen scale is units of city output 
(shields, trade, science, gold, luxuries) multiplied by a priority value 
for that kind of output. The use of the priority value gives the AI some 
strategic control over building, although that control is rather simple 
at present. The 'ai_data' structure holds the priority values of the 
kinds of output. The AI computes the priority values using the constants 
FOOD_WEIGHTING, SHIELD_WEIGHTING, TRADE_WEIGHTING and 
POLLUTION_WEIGHTING. Those constants can be thought of as default or 
typical values for the priorities.

The AI must consider benefits that will become apparent in the future 
rather than immediately. The AI amortises these future benefit values.
The AI must consider benefits (and costs) that will apply every turn 
(unit upkeep costs, for example). The AI does this by summing the 
benefit for the current turn, the amortised benefit for the next turn, 
the amortised benefit for the second turn and so on for all turns. It 
can be shown that this sum is simply equivalent to multiplying the 
benefit by the MORT time-scale.

The AI must consider how much it wants various future technologies.
This computation is integrated with the computation of building wants.
The AI computes how much it would want to have building candidates it 
can not yet build because it lacks technology. It then uses that want 
value to alter the degree to which it wants the technology that would 
enable that building candidate.

The result of these changes is a large patch (attached). Some of the 
changes could be split off into separate patches, but most could not.
The patch incorporates additional necessary changes that became apparent 
were vital for correct operation using the new want computations.

* The patch incorporates an updated version of the patch for centralised 
ferry building (PR#8992).

* The patch encourages founding of 'colonies'. That is, the founding of 
cities on large uninhabited islands.

* The patch should remove the unreasonable desire of the AI to build 
Barracks and Airports (PR#15297).

* The patch incorporates negative feed-back in setting of the tax-rate, 
which ensures reasonable taxation even if the AI is on a war footing or 
does not need research (PR#15249).

* The AI no longer tries to build duplicate improvements (PR#14915)

This patch will need a thorough review before committing, so I 
anticipate producing a second version once I have some feedback from you.

Attachment: PR14923,11656,2996.patch.gz
Description: Unix tar archive


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