[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-16 Thread David Fernandez
Follow-up Comment #6, bug #20062 (project freeciv):

Good point, then my "fix" may not be an improvement.

But the code still looks buggy to me and should be fixed one way or the
other.
Currently, in the same situation (with no tech upkeep), the AI could act
different if tech_upkeep_style == 1 (where "rate_sci_balance" is going to be
0), than if tech_upkeep_style == 0 (where "rate_sci_balance" is going to be
-1)

In the first case (0), if the AI estimates a negative income even with taxes
maxed to gold, then the AI keeps max taxes to gold.
In the 2nd case (-1), if the AI estimates a negative income even with taxes
maxed to gold, then the AI switches to maximize science.

I simply fixed it to be 0 in both cases. The other solution does not really
fit the current code, it would be too non-linear behavior, where AI increases
the taxes to balance the income, and when taxes can not be increased more due
to max rates, the AI suddently maximizes the science.
I'd suggest in that case to maximize the gold, but keeping a minimum of 10% to
science. I have already noticed how important it is to avoid the AI gets stuck
at 100% taxes, and just a 10% to science could make the difference.

___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-16 Thread Marko Lindqvist
Follow-up Comment #5, bug #20062 (project freeciv):

> I was watching this game in AI mode, and several turns before
> this one the AI starts to lose money and it keeps the taxes to
> 70% (max under monarchy) instead of switching to 70% gold, as
> the aihand.c file is supposed to be designed.

One thing to remember when fixing this: It used(?) to be AI's biggest problem
that it increase taxrate (=reduced sciencerate) when it was losing money. As
it got positive balance, it was ready to build more buildings with high
maintenance cost. Repeat. Have an AI with science rate 0% *and* losing money
despite 100% taxrate.

___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-16 Thread Marko Lindqvist
On 16 August 2012 21:03, David Fernandez
 wrote:
>  at least until I
> can compile the code with debug enabled.

  I can't get into actual issues just now, but quick note about making
debug build even if compiler gives warnings (and without editing the
sources to remove -Werror). In such a situation I simply set
CFLAGS="-Wno-error" before running configure. That user CFLAGS will
override "-Werror" setting from the configure script. Just avoid that
trick when you don't absolutely need it, so that you get error from
any warnings you create - clean build is requirement for code to be
accepted to freeciv.


 - ML

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-16 Thread David Fernandez
Follow-up Comment #4, bug #20062 (project freeciv):

I finally catched a savegame with default rules where the AI loses a building
due to low funds, while keeping the taxes to 70% science.

To recreate:
1- beta1 v2.4 with default rules, load savegame and start (Apaches)
3- /aitoggle
4- /set timeout 10
The next turn the AI will lose a granary due to negative gold balance.

I was watching this game in AI mode, and several turns before this one the AI
starts to lose money and it keeps the taxes to 70% (max under monarchy)
instead of switching to 70% gold, as the aihand.c file is supposed to be
designed.

I really believe this is currently the most important issue related to AI
behavior that I have seen in these years playing freeciv. I hope this savegame
helps to find the problem, I don't know what else I can do, at least until I
can compile the code with debug enabled.

I still think my patch "FixAITaxRates2.diff" (forget the one in my first post)
should improve this behavior, even if it does not seem to fix it completely.

(file #16397)
___

Additional Item Attachment:

File name: default_v2.4beta1-unbalancedTaxAI-T0215.sav.bz2 Size:77 KB


___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-13 Thread David Fernandez
Follow-up Comment #3, bug #20062 (project freeciv):

I catched a savegame, played with civ2civ3 rules over v2.4 beta1, where
English nation loses buildings/units due to low funds, and the AI keeps taxes
to 60% science and 40% gold.
aihand.c code seems designed so AI sets the taxes to 90% gold in this case
(under Democracy max tax rates are 90% with this rules).

Saddly, the AI keeps the same wrong behavior when I apply my patch, and it is
the same no matter if I enable or dissable the tech upkeep (my "fix" does
nothing...)

To reproduce the "bug":
1- Freeciv 2.4 beta1 + modpack civ2civ3
2- load savegame, start game with English, switch to AI control (normal
difficulty), and then "/set timeout 10" (or -1).
3- The AI loses buildings/units during 2 more turns, and it keeps taxes to 60%
science.
Note I saved the game after several turns watching the AI losing money while
keeping the taxes to 60% science.

I see this behavior often with civ2civ3 rules where it is harder to earn
trade/gold, but I don't know if the same happens with default rules.

(file #16390)
___

Additional Item Attachment:

File name: civ2civ3_v2.4-2-TaxRates-T0165.sav.gz Size:184 KB


___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-13 Thread David Fernandez
Follow-up Comment #2, bug #20062 (project freeciv):

Let me another guess... this time I'm almost sure it is a bug, now I think I
fully understand the related code.

In function "ai_manage_taxes",
the variable "rate_sci_balance" keeps a non valid value = -1 if
"game.info.tech_upkeep_style == 0" (default value in most rulesets).
When it comes the time to "Set the rates", the code assumes that such value
"rate_sci_balance = -1" means that AI will lose bulbs (due to tech upkeep)
even with taxes maxed to science.
When "rate_tax_balance = -1" it means that AI will lose money (due to upkeep
costs) even with taxes maxed to gold.
When both values are -1, it prioritizes to maximize the science over the
gold:

  } else {
/* Go for science and risk the loss of improvements or units. */
rates[AI_RATE_SCI] = MAX(maxrate, rate_sci_min);
rates[AI_RATE_TAX] = MIN(maxrate, RATE_REMAINS(rates));


As I see it, in every ruleset where tech upkeep is dissabled, if AI is losing
money, and if switching taxes to maximize gold does not get a positive income,
then the AI maximizes the science (instead of gold), making the situation even
worse for next turn...

I'm still trying to catch a clear savegame, but it is not so easy.

Forget the 1st AItaxRates.diff (I wish I could remove it), I have uploaded
this new fix to a new file: FixTaxRates2.diff

(file #16389)
___

Additional Item Attachment:

File name: FixAITaxRates2.diffSize:1 KB


___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-13 Thread David Fernandez
Follow-up Comment #1, bug #20062 (project freeciv):

Oh, my fault, this was not the bug.

I still think there is a bug somewhere in this function and I'll keep
searching, but you could remove this ticket for now.
Sorry.



___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [bug #20062] Possible bug in ai_manage_taxes (aihand.c)

2012-08-13 Thread David Fernandez
URL:
  

 Summary: Possible bug in ai_manage_taxes (aihand.c)
 Project: Freeciv
Submitted by: bardo
Submitted on: lun 13 ago 2012 16:07:26 GMT
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
  Status: None
 Assigned to: None
Originator Email: 
 Open/Closed: Open
 Release: 
 Discussion Lock: Any
Operating System: None
 Planned Release: 

___

Details:

For long time I have noticed the AI does not set the tax rates properly.
I have seen AIs that set a percentage to luxuries when there are no unhappy
people and there is no chance to celebrate, and I have seen many times the AI
losing buildings due to low funds when it was possible to increase the gold
taxes and so avoid the banckrupt.
At first I thought the wrong behavior was related to units supported by gold
(I have reported it in other tickets), but I have revised the related AI code
and I think I have found a possible bug in ai_manage_taxes (aihand.c):


/* First set tax (gold) to the minimal available number */
  rates[AI_RATE_SCI] = maxrate; /* Assume we want science here */
  rates[AI_RATE_TAX] = MAX(0, 100 - maxrate * 2); /* If maxrate < 50% */
  rates[AI_RATE_LUX] = (100 - rates[AI_RATE_SCI] - rates[AI_RATE_TAX]);


I can't understand the reason why maxrate is multiplied by 2 in:
>rates[AI_RATE_TAX] = MAX(0, 100 - maxrate * 2)
And such bug would cause the often AI behavior that I see where AI sets taxes
to 60% science, 0% gold and 40% luxuries at start.

When I "fix" it and I recompile, I find the tax rates are set by the AI in a
more reasonable way (with no useless luxuries), but AI still seems unable to
handle low of funds situations.

I'm new to freeciv code and I'm not sure if I really fixed something, or I
introduced an error that looks like an improvement. I'll try to upload some
savegame in case some coder can take a look. 



___

File Attachments:


---
Date: lun 13 ago 2012 16:07:26 GMT  Name: AItaxRates.diff  Size: 940B   By:
bardo



___

Reply to this item at:

  

___
  Mensaje enviado vía/por Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev