[Freeciv-Dev] (PR#13426) non-suicidal AI
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13426 >
Attached are two patches that make the AI less suicidal, one for freeciv
2.0.2 and one for CVS-head as of today.
Basically, whenever a city is taken by an enemy, the city owner's love
for the enemy is increased by 250. Then, when the AI recalculates its
primary target, the amount of love is emphasized more. This has the
effect that, whenever you take 2 or more AI cities and you're the
primary target, it will try and find someone else to go to war with,
because obviously it's losing against you.
This patch also discourages the AI from starting wars in the beginning
and middle of the game.
diff -ruN -Xfreeciv-2.0.2/diff_ignore /tmp/freeciv-2.0.2/ai/advdiplomacy.c
freeciv-2.0.2/ai/advdiplomacy.c
--- /tmp/freeciv-2.0.2/ai/advdiplomacy.c 2005-07-07 20:01:28.000000000
-0500
+++ freeciv-2.0.2/ai/advdiplomacy.c 2005-07-08 15:55:37.697350152 -0500
@@ -17,6 +17,7 @@
#include <assert.h>
#include <string.h>
+#include <math.h>
#include "aisupport.h"
#include "city.h"
@@ -660,7 +661,7 @@
/* Modify by love. Increase the divisor to make ai go to war earlier */
kill_desire -= MAX(0, kill_desire
* pplayer->ai.love[aplayer->player_no]
- / (2 * MAX_AI_LOVE));
+ / MAX_AI_LOVE); /* May need tuning */
/* Make novice AI more peaceful with human players */
if (ai_handicap(pplayer, H_DIPLOMACY) && !aplayer->ai.control) {
@@ -690,6 +691,20 @@
pplayer->player_no, what, value);
}
+/**********************************************************************
+ Return the war_desire for the given year. This uses a curve algorithm
+ that discourages war early in the game and demands it near the end
+ (assuming we're not going for Alpha Centauri, that is).
+
+ Results are in the range [0..1]. If 0, the AI can't start wars. If
+ 1, the AI should always be in war.
+***********************************************************************/
+static double ai_overall_war_desire(int year) {
+ double scaled_year = (double)(year+GAME_START_YEAR)
+ /(double)(game.end_year+GAME_START_YEAR);
+ return (1.0-sin(acos(scaled_year)));
+}
+
/**********************************************************************
Calculate our diplomatic predispositions here. Don't do anything.
@@ -700,6 +715,7 @@
int war_desire[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
int best_desire = 0;
struct player *target = NULL;
+ int overall_war_desire = 0;
memset(war_desire, 0, sizeof(war_desire));
@@ -806,6 +822,18 @@
ai->diplomacy.player_intel[aplayer->player_no].distance =
player_distance_to_player(pplayer, aplayer);
} players_iterate_end;
+
+ /* Allow for times of peace; the greater overall_war_desire,
+ * the more likely the AI will go to war.
+ */
+ overall_war_desire = (int)(ai_overall_war_desire(game.year)*1000);
+ if (myrand(1000) > overall_war_desire) {
+ ai->diplomacy.timer = myrand(6) + 6;
+ ai->diplomacy.target = NULL;
+ freelog(LOG_DEBUG, "War postponed with overall war desire at %d",
+ overall_war_desire);
+ return;
+ }
/* Calculate our desires, and find desired war target */
players_iterate(aplayer) {
diff -ruN -Xfreeciv-2.0.2/diff_ignore /tmp/freeciv-2.0.2/server/citytools.c
freeciv-2.0.2/server/citytools.c
--- /tmp/freeciv-2.0.2/server/citytools.c 2005-07-07 20:01:28.000000000
-0500
+++ freeciv-2.0.2/server/citytools.c 2005-07-08 15:54:15.079909912 -0500
@@ -1221,6 +1221,13 @@
- Kris Bubendorfer
Also check spaceships --dwp
*/
+
+ /* Every conquered city lessens cplayer's desire for war (assuming he's AI)
*/
+ cplayer->ai.love[pplayer->player_no] += MAX_AI_LOVE/4; /* May need tuning */
+ freelog(LOG_DEBUG, "Increased %s's love to %d for conquering a city.\n",
+ pplayer->name,
+ cplayer->ai.love[pplayer->player_no]);
+
if (is_capital(pcity)
&& (cplayer->spaceship.state == SSHIP_STARTED
|| cplayer->spaceship.state == SSHIP_LAUNCHED)) {
diff -ruN -Xfreeciv-working/diff_ignore /tmp/freeciv-cvs/ai/advdiplomacy.c
freeciv-working/ai/advdiplomacy.c
--- /tmp/freeciv-cvs/ai/advdiplomacy.c 2005-07-04 12:48:35.000000000 -0500
+++ freeciv-working/ai/advdiplomacy.c 2005-07-08 14:05:00.000000000 -0500
@@ -17,6 +17,7 @@
#include <assert.h>
#include <string.h>
+#include <math.h>
#include "aisupport.h"
#include "city.h"
@@ -732,7 +733,7 @@
/* Modify by love. Increase the divisor to make ai go to war earlier */
kill_desire -= MAX(0, kill_desire
* pplayer->ai.love[aplayer->player_no]
- / (2 * MAX_AI_LOVE));
+ / MAX_AI_LOVE); /* May need tuning */
/* Make novice AI more peaceful with human players */
if (ai_handicap(pplayer, H_DIPLOMACY) && !aplayer->ai.control) {
@@ -762,6 +763,20 @@
pplayer->player_no, what, value);
}
+/**********************************************************************
+ Return the war_desire for the given year. This uses a curve algorithm
+ that discourages war early in the game and demands it near the end
+ (assuming we're not going for Alpha Centauri, that is).
+
+ Results are in the range [0..1]. If 0, the AI can't start wars. If
+ 1, the AI should always be in war.
+***********************************************************************/
+static double ai_overall_war_desire(int year) {
+ double scaled_year = (double)(year+GAME_START_YEAR)
+ /(double)(game.info.end_year+GAME_START_YEAR);
+ return (1.0-sin(acos(scaled_year)));
+}
+
/**********************************************************************
Calculate our diplomatic predispositions here. Don't do anything.
@@ -778,6 +793,7 @@
int best_desire = 0;
struct player *target = NULL;
int mult;
+ int overall_war_desire = 0;
memset(war_desire, 0, sizeof(war_desire));
@@ -889,6 +905,18 @@
ai->diplomacy.player_intel[aplayer->player_no].distance =
player_distance_to_player(pplayer, aplayer);
} players_iterate_end;
+
+ /* Allow for times of peace; the greater overall_war_desire,
+ * the more likely the AI will go to war.
+ */
+ overall_war_desire = (int)(ai_overall_war_desire(game.info.year)*1000);
+ if (myrand(1000) > overall_war_desire) {
+ ai->diplomacy.timer = myrand(6) + 6;
+ ai->diplomacy.target = NULL;
+ freelog(LOG_DEBUG, "War postponed with overall war desire at %d",
+ overall_war_desire);
+ return;
+ }
/* Calculate our desires, and find desired war target */
players_iterate(aplayer) {
diff -ruN -Xfreeciv-working/diff_ignore /tmp/freeciv-cvs/server/citytools.c
freeciv-working/server/citytools.c
--- /tmp/freeciv-cvs/server/citytools.c 2005-07-04 12:48:38.000000000 -0500
+++ freeciv-working/server/citytools.c 2005-07-07 20:59:00.000000000 -0500
@@ -1185,6 +1185,13 @@
- Kris Bubendorfer
Also check spaceships --dwp
*/
+
+ /* Every conquered city lessens cplayer's desire for war (assuming he's AI)
*/
+ cplayer->ai.love[pplayer->player_no] += MAX_AI_LOVE/4; /* May need tuning */
+ freelog(LOG_DEBUG, "Increased %s's love to %d for conquering a city.\n",
+ pplayer->name,
+ cplayer->ai.love[pplayer->player_no]);
+
if (is_capital(pcity)
&& (cplayer->spaceship.state == SSHIP_STARTED
|| cplayer->spaceship.state == SSHIP_LAUNCHED)) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13426) non-suicidal AI,
Curtis <=
|
|