Complete.Org: Mailing Lists: Archives: freeciv-ai: September 2004:
[freeciv-ai] Re: [Freeciv-Dev] Re: (PR#9887) AI defense code
Home

[freeciv-ai] Re: [Freeciv-Dev] Re: (PR#9887) AI defense code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [freeciv-ai] Re: [Freeciv-Dev] Re: (PR#9887) AI defense code
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxxx>
Date: Fri, 3 Sep 2004 10:17:00 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9887 >

On Thu, 2 Sep 2004, Per I. Mathisen wrote:

> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9887 >
> 
> Attached is a patch that makes ai_choose_defender_versus() use
> unit_win_chance() instead of the usual multiply-unit-values-together
> defense code. It works reasonably well for choosing defender, except that
> it is now back to sometimes building Stealth Fighter as defender ;)
> 
> However, it is very slow. It also fails to understand that defenders
> sometimes should not kill the attacker, but merely wound it as much as
> economically rational.
> 
> I tried to change win chance with this formula:
> 
>     unit_build_shield_cost(defender->type) * MAX(chance, 0.001)
> 
> (lower values are better)
> 
> This was meant to encourage building cheaper defenders when there was
> little difference between defenders, ie no Stealth Fighters. It worked
> reasonably, until the AI encountered Howitzers. Suddenly, the AI wanted
> to build Spy for defense! The logic is impeccable - the change in win
> chance between a Mech Inf and a Spy is a mere 4%, and the Spy is much
> cheaper... so why waste shields on a Mech Inf?
> 
> Of course, this ignores the important fact that defenders should not
> always aim to win every time, but also wound the attacking unit
> sufficiently that it cannot attack again, and we can destroy it next turn.
> 
> So is there a fast way to compute a "damage ratio" between an attacker and
> a defender, similar to unit_win_chance()? Greg, this is your area of
> expertise :-)

Ok, lets think about it.  A is our defender, B is attacker.  strength is 
defence strength and attack strength respectively.

The average number of hits unit A inflicts on B before getting hit _once_ 
is
        strength_A / strength_B
(that's probability theory)

Since A can take hp_A / fp_B hits from B before dying, the average number 
of hits it will inflict on B before dying is
        strength_A / strength_B * hp_A / fp_B

Since each hit takes fp_A off B's health, the average number of health 
lost by B is
        L = strength_A * hp_A * fp_A / (strength_B * fp_B)

Now assume we are going to lose no matter what.  What we want is to 
maximize L but not pay too many shields for it.  So we want to maximize
        L / shield_cost_A

But if we have a chance to win, we surely prefer 10$ unit which will not 
die to 5$ unit which will half-kill the attacker.  Exactly where is the 
watershed between cheap-vs-strong choice depends on personal taste and 
even on ideology (e.g. Communism and Fundamentalism seems to be quite 
happy about wasting a large number poorly trained soldiers).

So I suggest something like:
        ( L + MAX(0, L - hp_B) ) / shield_cost
since if L > hp_B we are more likely to win than to lose against B.  MAX 
can be multiplied by a factor, or even squared (but I don't think it's a 
good idea).

Gr




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