bugFreeciv - Bugs: bug #20062, Possible bug in ai_manage_taxes...

 
 
Show feedback again

bug #20062: Possible bug in ai_manage_taxes (aihand.c)

Submitted by:  David Fernandez <bardo>
Submitted on:  Mon 13 Aug 2012 04:07:26 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalStatus: None
Assigned to: NoneOpen/Closed: Open
Release: Operating System: None
Planned Release: 

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Fri 17 Aug 2012 01:46:31 AM UTC, comment #6:

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.

David Fernandez <bardo>
Thu 16 Aug 2012 08:39:17 PM UTC, comment #5:

> 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.

Marko Lindqvist <cazfi>
Project Administrator
Thu 16 Aug 2012 06:03:28 PM UTC, comment #4:

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)

David Fernandez <bardo>
Mon 13 Aug 2012 08:39:53 PM UTC, comment #3:

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)

David Fernandez <bardo>
Mon 13 Aug 2012 07:48:01 PM UTC, comment #2:

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:

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)

David Fernandez <bardo>
Mon 13 Aug 2012 04:49:59 PM UTC, comment #1:

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.

David Fernandez <bardo>
Mon 13 Aug 2012 04:07:26 PM UTC, original submission:

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):

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.

David Fernandez <bardo>

 

(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #16390:  civ2civ3_v2.4-2-TaxRates-T0165.sav.gz added by bardo (184kB - application/x-gzip)
file #16389:  FixAITaxRates2.diff added by bardo (1kB - text/x-diff)
file #16388:  AItaxRates.diff added by bardo (940B - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by cazfi (Posted a comment)
  • -unavailable- added by bardo (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 16 Aug 2012 06:03:28 PM UTCbardoAttached File-=>Added default_v2.4beta1-unbalancedTaxAI-T0215.sav.bz2, #16397
    Mon 13 Aug 2012 08:39:53 PM UTCbardoAttached File-=>Added civ2civ3_v2.4-2-TaxRates-T0165.sav.gz, #16390
    Mon 13 Aug 2012 07:48:01 PM UTCbardoAttached File-=>Added FixAITaxRates2.diff, #16389
    Mon 13 Aug 2012 04:07:26 PM UTCbardoAttached File-=>Added AItaxRates.diff, #16388
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup