Complete.Org: Mailing Lists: Archives: freeciv-ai: April 2002: [freeciv-ai] Approximate win_chance

[freeciv-ai] Approximate win_chance

[Top] [All Lists]

 To: freeciv-ai@xxxxxxxxxxx Subject: [freeciv-ai] Approximate win_chance From: Gregory Berkolaiko Date: Wed, 17 Apr 2002 13:25:04 +0100 (BST)

```I ran some simulations with my approximate win_chance formula.

It doesn't perform as well as I initially thought, but it's definitely
better than the current system we have in most AI routines.
Current system:

A_rating = A_strength * A_HP * A_FP;
D_rating = D_strength * D_HP * D_FP;

chance = A_rating^2 / ( A_rating^2 + D_rating^2 )

My formula:

chance = A_rating^5 / ( A_rating^5 + D_rating^5 )

This performs way better but for some weird cases it still gives an

But it is about 17-18 times faster than win_chance, so when the time comes
to consider performance of win_chance, I think my approximation is a
viable option.  The C code with which I experimented is attached.  Here is
the profile:

======================================================================
Each sample counts as 0.01 seconds.
%   cumulative   self              self     total
time   seconds   seconds    calls  ns/call  ns/call  name
77.08      0.37     0.37   100000  3700.00  3700.00  win_chance
18.75      0.46     0.09                             main
4.17      0.48     0.02   100000   200.00   200.00  win_chance_approx
======================================================================

Also attached is a graph of win_chance as a function of the "true
parameter" x = A_rating / D_rating  (red circles), my approximation as a
function of x (black) and the current approximation (blue).

Best,
G.
```

win_chance.gif
Description: GIF image

test.c
Description: Text document