Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2006:
[Freeciv-Dev] (PR#20387) [PATCH] Make AI more considerate when deciding
Home

[Freeciv-Dev] (PR#20387) [PATCH] Make AI more considerate when deciding

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#20387) [PATCH] Make AI more considerate when deciding who to attack
From: "Petr Baudis" <pasky@xxxxxx>
Date: Sun, 3 Sep 2006 06:51:55 -0700
Reply-to: bugs@xxxxxxxxxxx

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

  Hi,

  so I've found out why does AI always totally hate me, even though I
get by far the biggest and the most advanced civilization very quickly -
I don't militarize until necessary or feasible for world-wide conquest
(which is usually very late in the game).

  This patch aims to make AIs take account of the _potential_ power the
player is able to generate when war is declared. It still does not
discourage immediate neighbors but at least the more distant
civilizations are more respectful to me now.

  Also, the patch does not try to be very smart, and the amortize()
usage there may not be valid at all - this bug is just that we should
really do some accounting for the economical power here, and it's nice
to attach patches to bugs. ;-)

Index: ai/advdiplomacy.c
===================================================================
--- ai/advdiplomacy.c   (revision 12298)
+++ ai/advdiplomacy.c   (working copy)
@@ -657,7 +657,12 @@
 {
   int want = 0, fear = 0, distance = 0, settlers = 0, cities = 0;
   struct player_spaceship *ship = &target->spaceship;
+  int enemy_trade = 0;
 
+  /* Calculate average distances to other player's empire. */
+  distance = player_distance_to_player(pplayer, target);
+  ai->diplomacy.player_intel[target->player_no].distance = distance;
+
   city_list_iterate(target->cities, pcity) {
     want += 100; /* base city want */
     want += pcity->size * 20;
@@ -675,7 +680,10 @@
         want += impr_build_shield_cost(id);
       }
     } built_impr_iterate_end;
+
+    enemy_trade += pcity->prod[O_TRADE];
   } city_list_iterate_end;
+
   unit_list_iterate(target->units, punit) {
     fear += ATTACK_POWER(punit);
 
@@ -703,15 +711,31 @@
     cities++;
   } city_list_iterate_end;
 
+  /* We must consider enemy's ability of quickly mobilizing, even though
+   * it may be almost completely unmilitarized so far */
+  {
+    struct unit_type *attacker = best_role_unit_for_player(target,
+                                                          L_ATTACK_STRONG);
+    int attacker_power = TYPE_ATTACK_POWER(attacker);
+    /* We implicitly give the potential units less weight as we compute
+     * the cost based on an almost-empty shield stock. */
+    int attacker_cost = unit_buy_gold_cost(attacker, 1);
+    int gold_bonus = enemy_trade * get_player_bonus(target, EFT_MAX_RATES) / 
100;
+    int gold_boost = 0, enemy_gold = target->economic.gold;
+    int i;
+
+    for (i = 1; i <= distance; i++)
+      gold_boost += amortize(gold_bonus, i);
+    enemy_gold += gold_boost;
+
+    fear += attacker_power * (enemy_gold / attacker_cost);
+  }
+
   /* Modify by settler/cities ratio to prevent early wars when
    * we should be expanding. This will eliminate want if we 
    * produce settlers in all cities (ie full expansion). */
   want -= abs(want) / MAX(cities - settlers, 1);
 
-  /* Calculate average distances to other player's empire. */
-  distance = player_distance_to_player(pplayer, target);
-  ai->diplomacy.player_intel[target->player_no].distance = distance;
-
   /* Tech lead is worrisome. FIXME: Only consider 'military' techs. */
   fear += MAX(get_player_research(target)->techs_researched
               - get_player_research(pplayer)->techs_researched, 0) * 100;

-- 
                                Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Snow falling on Perl. White noise covering line noise.
Hides all the bugs too. -- J. Putnam





[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#20387) [PATCH] Make AI more considerate when deciding who to attack, Petr Baudis <=