Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: patch: make ai understand peace and alliances (PR#1277
Home

[Freeciv-Dev] Re: patch: make ai understand peace and alliances (PR#1277

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: patch: make ai understand peace and alliances (PR#1277)
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Mon, 25 Feb 2002 04:22:27 -0800 (PST)

--- "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx> wrote:
> This small patch gives the AI what it needs to understand the difference
> between friends and enemies. Or so I hope. I've playtested it, but I know
> the AI too poorly to say whether it has any adverse effects on it. It
> looks like the AI copes just as good, or just as bad, as it has always
> done.
> 
> Please review. To playtest peace or alliances with the AIs, use the teams
> patch.
> 
> Yours,
> Per
> 
> "What we anticipate seldom occurs: but what we least expect generally
> happens." -- Benjamin Disraeli
> > diff -u3NrX freeciv/diff_ignore freeciv/ai-old/advmilitary.c
> freeciv/ai/advmilitary.c
> --- freeciv/ai-old/advmilitary.c      Sat Feb 23 14:19:06 2002
> +++ freeciv/ai/advmilitary.c  Sun Feb 24 19:37:06 2002
> @@ -223,7 +223,7 @@
>      assess_danger(pcity);
>    city_list_iterate_end;
>  }
> -       
> +
>  /********************************************************************** 
>  ...
>  ***********************************************************************/
> @@ -262,7 +262,7 @@
>    unit_list_iterate_end;
>  
>    players_iterate(aplayer) {
> -    if (aplayer != city_owner(pcity)) {
> +    if (pplayers_at_war(city_owner(pcity),aplayer)) {
>        boatspeed = (get_invention(aplayer, game.rtech.nav)
>                  == TECH_KNOWN ? 12 : 6);

Elsewhere in the code 

 boatspeed = (get_invention(aplayer, game.rtech.nav)
                   == TECH_KNOWN ? 4 * SINGLE_MOVE : 2 * SINGLE_MOVE);

More consistency is never bad. And yes, I am partly to blame, I never changed
all the various move costs to SINGLE_MOVE etc.

>        boatid = find_boat(aplayer, &x, &y, 0);
> diff -u3NrX freeciv/diff_ignore freeciv/ai-old/aitools.c freeciv/ai/aitools.c
> --- freeciv/ai-old/aitools.c  Sat Feb 23 14:19:06 2002
> +++ freeciv/ai/aitools.c      Sun Feb 24 19:33:46 2002
> @@ -47,7 +47,6 @@
>  If (enemy != 0) it looks only for enemy cities
>  If (pplayer != NULL) it looks for cities known to pplayer
>  **************************************************************************/
> -
>  struct city *dist_nearest_city(struct player *pplayer, int x, int y,
>                                 bool everywhere, bool enemy)
>  { 
> @@ -56,7 +55,7 @@
>    int con = map_get_continent(x, y);
>  
>    players_iterate(pplay) {
> -    if(enemy && pplay == pplayer) continue;
> +    if ((enemy) && (pplayer) && (!pplayers_at_war(pplayer,pplay))) continue;
>  

I don't understand the !pplayers_at_war. Enemy and pplayer should be enough.

>      city_list_iterate(pplay->cities, pcity)
>        if (real_map_distance(x, y, pcity->x, pcity->y) < dist &&
> diff -u3NrX freeciv/diff_ignore freeciv/ai-old/aiunit.c freeciv/ai/aiunit.c
> --- freeciv/ai-old/aiunit.c   Sun Feb 24 01:00:21 2002
> +++ freeciv/ai/aiunit.c       Sun Feb 24 19:38:18 2002
> @@ -1396,8 +1396,7 @@
>  
>  /* this is horrible, but I need to do something like this somewhere. --
> Syela */
>    players_iterate(aplayer) {
> -    if (aplayer == pplayer) continue;
> -    /* AI will try to conquer only enemy cities. -- Nb */

Petr is right about the comment still being right. What does the AI do
when it runs out of enemies? I'm willing to bet the AI never goes for the
spacecraft win.

> +    if (!pplayers_at_war(pplayer,aplayer)) continue;
>      city_list_iterate(aplayer->cities, acity)
>        city_reinforcements_cost_and_value(acity, punit);
>        acity->ai.invasion = 0;
> @@ -1465,7 +1464,7 @@
>  
>    handicap=ai_handicap(pplayer, H_TARGETS);
>    players_iterate(aplayer) {
> -    if (aplayer != pplayer) { /* enemy */
> +    if (pplayers_at_war(pplayer,aplayer)) { /* enemy */
>        city_list_iterate(aplayer->cities, acity)
>          if (handicap && !map_get_known(acity->x, acity->y, pplayer))
> continue;
>          sanity = (goto_is_sane(punit, acity->x, acity->y, TRUE) &&
> @@ -1657,20 +1656,27 @@
>    return(best);
>  }
>  
> +/*************************************************************************
> +  ...
> +**************************************************************************/

Comment could be something like

Locates the nearest usable port for naval units to recuperate hitpoints.

>  static bool find_nearest_friendly_port(struct unit *punit)
>  {
>    struct player *pplayer = unit_owner(punit);
>    int best = 6 * THRESHOLD + 1, cur;
>    generate_warmap(map_get_city(punit->x, punit->y), punit);
> -  city_list_iterate(pplayer->cities, pcity)
> -    cur = warmap.seacost[pcity->x][pcity->y];
> -    if (city_got_building(pcity, B_PORT)) cur /= 3;
> -    if (cur < best) {
> -      punit->goto_dest_x = pcity->x;
> -      punit->goto_dest_y = pcity->y;
> -      best = cur;
> +  players_iterate(aplayer) {
> +    if (pplayers_allied(pplayer,aplayer)) {
> +      city_list_iterate(aplayer->cities, pcity) {
> +        cur = warmap.seacost[pcity->x][pcity->y];
> +        if (city_got_building(pcity, B_PORT)) cur /= 3;
> +        if (cur < best) {
> +          punit->goto_dest_x = pcity->x;
> +          punit->goto_dest_y = pcity->y;
> +          best = cur;
> +        } 
> +      } city_list_iterate_end;
>      }
> -  city_list_iterate_end;
> +  } players_iterate_end;
>    if (best > 6 * THRESHOLD) return FALSE;
>    freelog(LOG_DEBUG, "Friendly port nearest to (%d,%d) is %s@(%d,%d) [%d]",
>               punit->x, punit->y,
> @@ -1755,7 +1761,7 @@
>  }
>  
>  /*************************************************************************
> -...
> +  TODO: teach AI about trade routes with friendly players
>  **************************************************************************/

I believe you said this was done. Kill that todo.

>  static void ai_manage_caravan(struct player *pplayer, struct unit *punit)
>  {
> @@ -1820,7 +1826,6 @@
>  When empty, it tries to find some units to carry or goes home or explores.
>  Military units handled by ai_manage_military()
>  **************************************************************************/
> -
>  static void ai_manage_ferryboat(struct player *pplayer, struct unit *punit)
>  { /* It's about 12 feet square and has a capacity of almost 1000 pounds.
>       It is well constructed of teak, and looks seaworthy. */

That comment is ridiculous. Kill it.

> @@ -2301,7 +2306,9 @@
>      handicap = ai_handicap(pplayer, H_TARGETS);
>      for( i = 0; i < game.nplayers; i++) {
>        aplayer = &game.players[i];
> -      if (aplayer == pplayer) continue;
> +      /* ignore cities we are at peace with, assumes that there is
> +         no need to establish embassy by the time we have peace */
> +      if (!pplayers_at_war(pplayer, aplayer)) continue;
>        /* sneaky way of avoiding foul diplomat capture  -AJS */
>        has_emb=player_has_embassy(pplayer, aplayer) || pdiplomat->foul;
>        city_list_iterate(aplayer->cities, acity)
> 

I can see the use of an embassy. After all, the AI should not be satisfied
to knock out the human player. It should go on to conquer the world. Former
allies = tomorrows enemies.

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com


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