Complete.Org: Mailing Lists: Archives: freeciv-ai: March 2005:
[freeciv-ai] Re: (PR#12451) ai taxes
Home

[freeciv-ai] Re: (PR#12451) ai taxes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mstefek@xxxxxxxxx
Subject: [freeciv-ai] Re: (PR#12451) ai taxes
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 18 Mar 2005 04:21:22 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12451 >

On Mon, 7 Mar 2005, Mateusz Stefek wrote:
> Very often when I watch the AI it keeps changing it's tax rates.
> One turn it has 100% science, in the next turn 100% tax, and 100%
> science again in the next turn. Indefinitely.
> Is this intentional?

It seems code the AI relied upon has changed (cached perhaps?) so that it
can no longer query income from player_get_expected_income() with various
tax rates without running a total refresh on all cities first. Since that
option is totally out of the question, I made a simplification. We now
assume the entire civ is a single city, and distribute total trade
according to tax rates within the AI code.

This fixes the behaviour that Mateusz noticed. The AI now successfully
raptures more often, and should also get better science results.

I also added shortcuts through the tax code for rulesets and governments
that cannot change the tax rates.

  - Per

Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.104
diff -u -r1.104 aihand.c
--- ai/aihand.c 10 Mar 2005 19:31:16 -0000      1.104
+++ ai/aihand.c 18 Mar 2005 12:13:41 -0000
@@ -18,6 +18,7 @@
 #include <assert.h>
 
 #include "city.h"
+#include "distribute.h"
 #include "game.h"
 #include "government.h"
 #include "log.h"
@@ -99,6 +100,22 @@
   bool celebrate = TRUE;
   int can_celebrate = 0, total_cities = 0;
   struct government *g = get_gov_pplayer(pplayer);
+  int trade = 0; /* total amount of trade generated */
+  int expenses = 0; /* total amount of gold upkeep */
+
+  if (!game.rgame.changable_tax) {
+    return; /* This ruleset does not support changing tax rates. */
+  }
+
+  if (get_gov_pplayer(pplayer)->index == game.government_when_anarchy) {
+    return; /* This government does not support changing tax rates. */
+  }
+
+  /* Find total trade surplus and gold expenses */
+  city_list_iterate(pplayer->cities, pcity) {
+    trade += pcity->surplus[O_TRADE];
+    expenses += pcity->usage[O_GOLD];
+  } city_list_iterate_end;
 
   /* Find minimum tax rate which gives us a positive balance. We assume
    * that we want science most and luxuries least here, and reverse or 
@@ -114,8 +131,18 @@
   while(pplayer->economic.tax < maxrate
         && (pplayer->economic.science > 0
             || pplayer->economic.luxury > 0)) {
+    int rates[3], result[3];
+    const int SCIENCE = 0, TAX = 1, LUXURY = 2;
+
+    /* Assume our entire civilization is one big city, and 
+     * distribute total income accordingly. This is a 
+     * simplification that speeds up the code significantly. */
+    rates[SCIENCE] = pplayer->economic.science;
+    rates[LUXURY] = pplayer->economic.luxury;
+    rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
+    distribute(trade, 3, rates, result);
 
-    if (player_get_expected_income(pplayer) < 0) {
+    if (expenses - result[TAX] > 0) {
       pplayer->economic.tax += 10;
       if (pplayer->economic.luxury > 0) {
         pplayer->economic.luxury -= 10;
@@ -223,10 +250,10 @@
 
   assert(pplayer->economic.tax + pplayer->economic.luxury 
          + pplayer->economic.science == 100);
-  freelog(LOGLEVEL_TAX, "%s rates: Sci %d Lux%d Tax %d NetIncome %d "
-          "celeb=(%d/%d)", pplayer->name, pplayer->economic.science,
-          pplayer->economic.luxury, pplayer->economic.tax,
-          player_get_expected_income(pplayer), can_celebrate, total_cities);
+  freelog(LOGLEVEL_TAX, "%s rates: Sci=%d Lux=%d Tax=%d trade=%d expenses=%d"
+          " celeb=(%d/%d)", pplayer->name, pplayer->economic.science,
+          pplayer->economic.luxury, pplayer->economic.tax, trade, expenses,
+          can_celebrate, total_cities);
   send_player_info(pplayer, pplayer);
 }
 

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