Complete.Org: Mailing Lists: Archives: freeciv-ai: August 2002:
[freeciv-ai] coreai: process_attacker_want()
Home

[freeciv-ai] coreai: process_attacker_want()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] coreai: process_attacker_want()
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 25 Aug 2002 12:30:27 +0000 (GMT)

This was as far as I got on this horrible function before I decided I
should start in the other end (ai_military_advisor) and try to unravel
what it really does and document it before proceeding.

This code really needs to be simplified and generalised - it is probably
the most horrible piece of code ever written for freeciv (even worse than
the dreaded fstk) - and I have some ideas on how to do this.

Right now the code tries to second-guess the game engine's calculations,
to figure out what are the good units. This is not only horrible difficult
to do well, but also unnecessary, as we can use these calculations
directly through unit_win_chance(att, def)

Finding best defending unit for pcity:
        - Find most likely attacker p1
        - Run unit_type_iterate(id) {
                - Create virtual unit p with type id
                - Run a simulated attack with p1 on pcity defended by p2
                - Calculate want based on win chance and cost to produce
        }
        - Select unit with highest win chance as best defender

Finding best attacking unit against pcity:
        - Run unit_type_iterate(id) {
                - Every second time we enter this loop, omit all
                  units that cannot occupy a city to get a statistically
                  diverse population of attack units. Maybe do this
                  to some other parameters too for more diversity.
                - Create virtual unit p with type id
                - Run a simulated attack with p on pcity
                - Calculate want based on win chance amortized over
                  move_rate / distance / cost to produce
        }
        - Select unit with highest win chance as best attacker

Why unit_win_chance() is not used at all in the AI code is a mystery to
me. Yeah, it will add some heat to the CPU, but we can aggressively cache
the results, and the code currently in cvs is also quite nasty (in so many
ways). It would be nice if someone could have look at win_chance and see
if could be made less computationally intensive (at cost of less accuracy,
fine).

Yours
Per

Attachment: coreai5.diff
Description: Text document


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