Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2001:
[Freeciv-Dev] Re: chance of winning a battle
Home

[Freeciv-Dev] Re: chance of winning a battle

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: chance of winning a battle
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxxxx>
Date: Sun, 15 Jul 2001 17:44:04 +0300 (IDT)



On Thu, 12 Jul 2001, Christian Knoke wrote:

> > why, the one who has the greatest chance of winning of course :)
> > but anyway I think I know an easy solution, just have to check it.
> 
> Here is a recent discussion about why this is not always the
> case:
> 
> http://arch.freeciv.org/freeciv-dev-200106/msg00043.html

Aha, so now I find that "statistically exact function" calculating the
chance of winning in a battle has been written long time ago by Trent,
edited and incorporated as win_chance by Thue (I believe) and is used
intensively.  Well, that'll teach me a lesson, always look up the most
up-to-date source :(((

Anyway, here are few ideas and comments:

1. As written in a comment in common/combat.c, win_chance gets insanely
small when units are unevenly matched.  And as noted by Trent, it takes
considerable time to calculate win_chance (and I could not find any way to
improve on his algorithm).  However there is an alternative in the guise
of get_defence_rating function which 
  a. Has clear probabilistic interpretation:
      get_defence_rating(attacker,defender) / (attacker->attack_strength)
     is the average damage suffered by the attacker before the defender is
     killed.
  b. Does not go insanely small
  c. Very fast to calculate
  d. Can be used instead of win_chance to improve speed when choosing the
     best defender (attacker) from a stack.
I cannot prove mathematically that if win_chance of defender is smaller
then defence_rating is smaller too and vice versa but it is so in all the
examples I checked by hand.

2. There is a dormant mistake in win_chance.  Line 39 of combat.c should
be 
int def_N_lose = (dhp+afp-1)/afp;
As it is now, it will work if no unit has got firepower > 2.  But, for
example, the number of hits a musketeer (20HP) will survive from a 3FP
unit is 7, not 
    20/3 + 20%3 = 8
as it is now.  Same thing on line 38.
   
3. As described in 
http://arch.freeciv.org/freeciv-dev-200106/msg00043.html
the AI feeds diplomat to a battleship before feeding the ironclad to it.
While it's done in a way that minimizes costs, you wouldn't imagine such a
situation in reality: if you are general in a city and send your diplomats
to die before your warships, you will soon find your soldiers locking you
up in jail.  I think non-military units should be spared until very last.

4. More variety could be introduced into get_defender function.
Firstly, if the units are in the open field, the only consideration should
be how well they will defend.  It doesn't matter how much they cost, if
the defender looses, they all die anyway.  
In a city (or fortress) there is more choice, e.g.
   a. if win_chance > 95% (or some high value like this), non-veteran
      units could be sent forth, in order to become veterans.
   b. if win_chance < 10% for all units, more thinking should be done.
      But, in general, units that can do more damage in an attack should
      be preserved, as units which are ill and will recover next turn.
      Also cost could be considered and potential for upgrade.

5. TODO file should be edited to remove lines 91 and 92.


I will make patches for 2. and 5. (I still have to learn how to do it).
And I would like more opinions concerning 3. and 4.  In particular from
the guy who wrote it!



what a bloody long email,
G.



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