[Freeciv-Dev] [RFC] Tech costs and AI problem
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Working on the tech cost patch I encountered the following problem:
ai/advmilitary.c:process_defender_want() contains
k = pplayer->ai.num_unknown_techs[unit_types[i].tech_requirement];
...
l = k * (k + pplayer->research.techs_researched) * game.researchcost /
(game.year > 0 ? 2 : 4); /* cost (shield equiv) of gaining these techs */
K is the number of techs which have to researched till the goal tech
(unit_types[i].tech_requirement) _can_ be researched/is reachable.
Note that currently
int total_bulbs_required(struct player *pplayer)
{
int timemod = (game.year > 0) ? 2 : 1;
return timemod * pplayer->research.techs_researched * game.researchcost;
}
So I assume that the condition in the AI code can wants to mimic this.
I want to compute l from a call to total_bulbs_required_for_goal
(which is the new method for this).
If we assume that
s=pplayer->research.techs_researched,
rc=game.researchcost and
tbrfg=the result from the total_bulbs_required_for_goal
than the old method will compute:
l_old = (k*k + k*s) * rc
the new method calculates correctly:
tbrfg = (0.5*k*k + (s - 0.5)*k) * rc
So for large k's a good approximation would be "l_new = tbrfg / 2" but this
fails for small ks:
l_old(k=1) = (s + 1)*rc
l_new(k=1) = (s*rc)/2
l_old(k=2) = (2*s + 4)*rc
l_new(k=2) = ((s + 1)*rc)/2
I would have no problems if these numbers wouldn't get mixed with
build_costs and the number of cities.
So any advise from the "AI-people"?
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Premature optimization is the root of all evil."
-- D. E. Knuth in "Structured Programming with go to Statements"
- [Freeciv-Dev] [RFC] Tech costs and AI problem,
Raimar Falke <=
|
|