Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] (PR#14904) Bugs in AI diplomacy code
Home

[Freeciv-Dev] (PR#14904) Bugs in AI diplomacy code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14904) Bugs in AI diplomacy code
From: "Guillaume Melquiond" <guillaume.melquiond@xxxxxxxxx>
Date: Fri, 23 Dec 2005 23:34:59 -0800
Reply-to: bugs@xxxxxxxxxxx

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

A revised version of the patch. It still fixes two typos in the code,
and because of one of them the AI was rejecting treaties it had
suggested. The patch still prevents the AI from asking for shared
vision without also proposing it. In addition, it fixes the wrong
enumerations, as pointed out by Per. And by reordering the
conditionals, it also speeds up the AI by not calling the costly
ai_goldequiv_clause if the result will be discarded because of spam
control.

Index: ai/advdiplomacy.c
===================================================================
--- ai/advdiplomacy.c   (révision 11378)
+++ ai/advdiplomacy.c   (copie de travail)
@@ -304,7 +304,7 @@
                "ceasefire for a bit longer first, %s."), pplayer->name, 
                aplayer->name);
         worth = -BIG_NUMBER;
-      } else if (adip->countdown >= 0 && adip->countdown < -1) {
+      } else if (adip->countdown >= 0 || adip->countdown < -1) {
         worth = -BIG_NUMBER; /* but say nothing */
       } else {
         worth = greed(pplayer->ai.love[aplayer->player_no]
@@ -1016,6 +1016,7 @@
 static void ai_share(struct player *pplayer, struct player *aplayer)
 {
   int index;
+  bool gives_vision;
 
   /* Only share techs with team mates */
   if (players_on_same_team(pplayer, aplayer)) {
@@ -1029,14 +1030,20 @@
       }
     }
   }
-  if (!gives_shared_vision(pplayer, aplayer) && 
+
+  /* Only give shared vision if safe. Only ask for shared vision if fair. */
+  gives_vision = gives_shared_vision(pplayer, aplayer);
+  if (!gives_vision &&
       shared_vision_is_safe(pplayer, aplayer)) {
     ai_diplomacy_suggest(pplayer, aplayer, CLAUSE_VISION, 0);
+    gives_vision = TRUE;
   }
-  if (!gives_shared_vision(aplayer, pplayer) &&
+  if (gives_vision &&
+      !gives_shared_vision(aplayer, pplayer) &&
       shared_vision_is_safe(aplayer, pplayer)) {
     ai_diplomacy_suggest(aplayer, pplayer, CLAUSE_VISION, 0);
   }
+
   if (!player_has_embassy(pplayer, aplayer)) {
     ai_diplomacy_suggest(aplayer, pplayer, CLAUSE_EMBASSY, 0);
   }
@@ -1490,13 +1497,11 @@
       break;
 
     case DS_PEACE:
-      if (adip->at_war_with_ally) {
-        break;
-      }
       clause.type = CLAUSE_ALLIANCE;
-      if (ai_goldequiv_clause(pplayer, aplayer,
-                              &clause, ai, FALSE, DS_ALLIANCE) < 0
-          || (adip->asked_about_alliance > 0 && !aplayer->ai.control)) {
+      if (adip->at_war_with_ally
+          || (!aplayer->ai.control && adip->asked_about_alliance > 0)
+          || ai_goldequiv_clause(pplayer, aplayer, &clause,
+                                 ai, FALSE, DS_ALLIANCE) < 0) {
         break; 
       }
       ai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ALLIANCE, 0);
@@ -1507,13 +1512,11 @@
       break;
 
     case DS_CEASEFIRE:
-      if (adip->at_war_with_ally) {
-        break;
-      }
       clause.type = CLAUSE_PEACE;
-      if (ai_goldequiv_clause(pplayer, aplayer, &clause,
-                              ai, FALSE, CLAUSE_PEACE) < 0
-          || (adip->asked_about_peace > 0 && !aplayer->ai.control)) {
+      if (adip->at_war_with_ally
+          || (!aplayer->ai.control && adip->asked_about_peace > 0)
+          || ai_goldequiv_clause(pplayer, aplayer, &clause,
+                                 ai, FALSE, DS_PEACE) < 0) {
         break; /* never */
       }
       ai_diplomacy_suggest(pplayer, aplayer, CLAUSE_PEACE, 0);
@@ -1524,20 +1527,10 @@
 
     case DS_NO_CONTACT: /* but we do have embassy! weird. */
     case DS_WAR:
-    {
-      int worth;
-
-      DIPLO_LOG(LOG_DIPL, pplayer, aplayer, "considering ceasefire");
-      if (adip->asked_about_ceasefire > 0 && !aplayer->ai.control) {
-        DIPLO_LOG(LOG_DIPL, pplayer, aplayer, "... do not ask");
-        break;
-      }
-      worth = ai_goldequiv_clause(pplayer, aplayer,
-                                  &clause, ai, FALSE, CLAUSE_CEASEFIRE);
       clause.type = CLAUSE_CEASEFIRE;
-      if (worth < 0) {
-        DIPLO_LOG(LOG_DIPL, pplayer, aplayer, "... unacceptable (w=%d)",
-                  worth);
+      if ((!aplayer->ai.control && adip->asked_about_ceasefire > 0)
+          || ai_goldequiv_clause(pplayer, aplayer, &clause,
+                                 ai, FALSE, DS_CEASEFIRE) < 0) {
         break; /* Fight until the end! */
       }
       ai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, 0);
@@ -1546,7 +1539,7 @@
              "bloodshed. May we suggest a cessation of hostilities?"), 
              pplayer->name);
       break;
-    }
+
     case DS_ARMISTICE:
       break;
     default:








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