Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2001:
[Freeciv-Dev] Re: Wrong sequence of defending units (PR#796)
Home

[Freeciv-Dev] Re: Wrong sequence of defending units (PR#796)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Christian Knoke <ChrisK@xxxxxxxx>, Freeciv Developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Wrong sequence of defending units (PR#796)
From: Thue <thue@xxxxxxx>
Date: Tue, 5 Jun 2001 01:39:08 +0200

On Tuesday 05 June 2001 01:19, Christian Knoke wrote:
> Am Dienstag,  5. Juni 2001 00:48 schrieben Sie:
> > > Login as chris and attack finnish city of Pori with a
> > > battle ship. city defends with 1. musketeer, 2. diplomat,
> > > 3. ironclad.
> > >
> > > --------
> > > 3: attack:180, defense:45, attack firepower:1, defense firepower:1
> > > 3: attack:180, defense:0, attack firepower:1, defense firepower:1
> > > 3: attack:180, defense:40, attack firepower:2, defense firepower:1
> > > --------
> >
> > This looks like an obvious bug at first, but looking closer I am not
> > so sure it should be considered a bug.
> > What happens is that the algoritm determines that none of the units
> > have any chance of winning, so it just feeds the units with the
> > lowest value (build cost) first. Since an ironclad is expensive it
> > gets to defend last. If it is going to choose defenders for me I
> > think I prefer that it stays as it is. :)
>
> Maybe they'd better get the sack and leave the scene? :)
>
> > That said, the algoritm is somewhat simple, and I had not thought
> > much about this consequence when I wrote it.
>
> What do you think about a defense value / build cost ratio, or
> even better, a winning chance / build cost ratio? Don't forget,
> they weaken their enemy and cut the attackers MP.
>
> It depends of course what you define "no chance of winning".
>
> > -Thue
>
> Christian

The relevant function is get_defender() in common/combat.c

The code looks like this:
int unit_def = (int) (100000 * (1 - unit_win_chance(attacker, defender)));
the unit_def of the units are then compared. What happens is that both the 
diplomat and the ironclad has less than 1/100000 chance of winning (!), so 
they look the same.
But yes, taking a few hp off the battleship has some value too. It should be 
weighted against saving valuable units, though. The amount off hps taken off 
is proportional to the win chance, so you may be able to only use one in your 
calculations. (as is done now)

The old algoritm was
(Some number proportional to the defense) squared/build cost
But I think you rarely saw less powerfull units being chosen, probably 
because the square factor was too powerfull.

In the case in point you may want to not choose the ironclad, as it has a 
penalty being in port. A wise choice would be to save it so it could use it's 
full force later.
Generelly units with a high attack factor may want to be spared so they can 
counterattack the next turn.
Given a veteran unit with defense of 2 *3/2 = 3 and a non-veteran with 
defense 3, the non-veteran is more valuable. This is not taken into account 
either. Also, you want to not use units that are not at full health, as they 
will be more powerfull later.

The current algoritm is somewhat naive compared to what it could do; as was 
the one it replaced (the one with the integer overflow). If someone want to 
write a better one for 1.12.1 then go ahead :).

-Thue


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