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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: patch: make ai understand peace and alliances 2 (PR#1277)
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Mon, 25 Feb 2002 15:15:07 +0100

It would be nice if you would keep it in the same thread ;).

Dear diary, on Mon, Feb 25, 2002 at 11:07:00AM CET, I got a letter,
where "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx> told me, that...
> diff -u3NrX freeciv/diff_ignore freeciv/README.AI-diplomacy 
> freeciv-orig/README.AI-diplomacy
> --- freeciv/README.AI-diplomacy       Thu Jan  1 00:00:00 1970
> +++ freeciv-orig/README.AI-diplomacy  Sun Feb 24 22:56:10 2002

I would rather like adding all these to README.AI (possible cleanup of it would
be nice as well) - having dozen of READMEs related to AI doesn't seem like a
best idea to me.

> @@ -0,0 +1,41 @@
> +This document describes the AI's knowledge of diplomacy. 
> +
> +At the moment, the AI cannot change its diplomatic state. 
> +The AI starts out in NO_CONTACT mode, and proceeds to WAR 
> +on first-contact.

Mentioning possibility to change that using the way like in your teams patch..?

> +The AI knows about friendly units and cities, and does not 
> +consider them to be either targets nor dangers. Caravans
> +are sent to friendly cities, and ships that do not have
> +targets are sent on a goto to the closest allied port.
> +
> +It is currently totally trusting and does not expect 
> +diplomatic states to ever change. So if one is to add 
> +active diplomacy to the AI, this must be changed.
> +
> +For people who want to hack at this part of the AI code,
> +please note
> + * pplayers_at_war(p1,p2) returns FALSE if p1==p2
> + * pplayers_non_attack(p1,p2) returns FALSE if p1==p2
> + * pplayers_allied(p1,p2) returns TRUE if p1==p2
> +ie we do not ever consider a player to be at war with
> +himself, we never consider a player to have any kind of
> +non-attack treaty with himself, and we always consider
> +a player to have an alliance with himself.
> +
> +The introduction of diplomacy is fraught with many
> +problems. One is that it usually gains only human players, 
> +not AI players, since humans are so much smarter and know 
> +how to exploit diplomacy, while for AIs they mostly only
> +add constraints on what it can do. Another is that it can 
> +be very difficult to write diplomacy that is useful for 
> +and not in the way of modpacks. Which means diplomacy 
> +either has to be optional, or have finegrained controls on 
> +who can do what diplomatic deals to whom, set from 
> +rulesets.

I somewhat can't see the problems with modpacks.. :( Can please anyone
enlighten me?

> +But one possibility for diplomacy that it would be easy
> +to introduce, is an initial PEACE mode for AIs under 'easy'
> +difficulty. This can be turned to WAR by a simple countdown 
> +timer started after first contact. This way 'easy' will be
> +more easy - a frequently requested feature.

The README looks good.

> diff -u3NrX freeciv/diff_ignore freeciv/ai/advmilitary.c 
> freeciv-orig/ai/advmilitary.c
> --- freeciv/ai/advmilitary.c  Sun Feb 24 22:57:56 2002
> +++ freeciv-orig/ai/advmilitary.c     Sun Feb 24 21:30:13 2002
> @@ -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);
>        boatid = find_boat(aplayer, &x, &y, 0);

Ok, once more. I find the code w/o space after ',' MUCH harder to read. Dunno
if Raimar or anyone who's going to commit the code is going to run it through
indent, but I prefer to have the code clear already in the patch.

> diff -u3NrX freeciv/diff_ignore freeciv/ai/aitools.c freeciv-orig/ai/aitools.c
> --- freeciv/ai/aitools.c      Sun Feb 24 22:58:00 2002
> +++ freeciv-orig/ai/aitools.c Sun Feb 24 21:30:13 2002
> @@ -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;
>  
>      city_list_iterate(pplay->cities, pcity)
>        if (real_map_distance(x, y, pcity->x, pcity->y) < dist &&

Same as above.

> diff -u3NrX freeciv/diff_ignore freeciv/ai/aiunit.c freeciv-orig/ai/aiunit.c
> --- freeciv/ai/aiunit.c       Sun Feb 24 22:58:01 2002
> +++ freeciv-orig/ai/aiunit.c  Sun Feb 24 23:33:13 2002
> @@ -1657,20 +1657,29 @@
>    return(best);
>  }
>  
> +/*************************************************************************
> +  Find safe harbour (with B_PORT). An allied player's city is just as
> +  good as one of our own, since both replenish our hitpoints and reduce
> +  unhappiness.
> +**************************************************************************/

B_PORT isn't a requirement, just an advantage of the city. Maybe it would be
worth mentioning that it saves the results by modifying the goto destination.

>  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,
> @@ -1786,7 +1797,9 @@
>       else {
>         /* A caravan without a home?  Kinda strange, but it might happen.  */
>         pcity=player_find_city_by_id(pplayer, punit->homecity);
> -       city_list_iterate(pplayer->cities,pdest)
> +       players_iterate(aplayer) {
> +        if (pplayers_at_war(pplayer, aplayer)) continue;
> +        city_list_iterate(pplayer->cities,pdest) {

Not terribly exciting indentation, but it's ok for now. Only
please-place-spaces-after-colons.

>           if (pcity
>               && can_establish_trade_route(pcity, pdest)
>               && map_get_continent(pcity->x, pcity->y) == 
> map_get_continent(pdest->x, pdest->y)) {
> @@ -2298,7 +2311,10 @@
>      continent=map_get_continent(pdiplomat->x, pdiplomat->y);
>      handicap = ai_handicap(pplayer, H_TARGETS);
>      players_iterate(aplayer) {
> -      if (aplayer == pplayer) continue;
> +      /* don't target ourselves or friendly players that we already
> +         have embassies with */

What about making a sentence from this? (also /^ *\* have/ would be maybe nice,
but oh, don't mind :)

> +      if ((!pplayers_at_war(pplayer, aplayer)) && 
> +             (player_has_embassy(pplayer, aplayer))) continue;

Odd indentation or only evil tabs? :^) Also it would be nice to move && to next
line.

>        /* sneaky way of avoiding foul diplomat capture  -AJS */
>        has_emb=player_has_embassy(pplayer, aplayer) || pdiplomat->foul;
>        city_list_iterate(aplayer->cities, acity)

The patch appears ok to me otherwise.

-- 

                                Petr "Pasky" Baudis

* elinks maintainer                * IPv6 guy (XS26 co-coordinator)
* IRCnet operator                  * FreeCiv AI hacker
.
No one can feel as helpless as the owner of a sick goldfish.
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/


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