Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10183) Moving loop
Home

[Freeciv-Dev] (PR#10183) Moving loop

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10183) Moving loop
From: "Oursinou Desman" <desman@xxxxxxxxx>
Date: Sat, 18 Sep 2004 19:34:44 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10183 >


Hello,

First of all, you did a "marvelous" work and I thank you for all your hard 
work. I'm a "fan" of
"Civilization", "Colonization" and all this kind of game. I played with ALL 
sort of "Civ" even those
not from Sid Meyer and I'm very happy to find this game on Linux now.

But....... so, there is a "but"...... I think I found a bug in one of your 
routines, and as I was
dev in my young years......

I had problem on some games with this sub-routine. I have logs and debug dumps 
if you need but I
hope my explainations will be enough.
I added some comments in the prog's lines, like 

! this is a comment


bool ai_manage_explorer(struct unit *punit)
{
  struct player *pplayer = unit_owner(punit);
  /* Loop prevention */
  int x = punit->x, y = punit->y;


! OK, we keep the current position entering the routine.


  /* The want of the most desirable tile, given nearby water, cities, etc. */
  float most_desirable = 0;

  /* The maximum distance we are willing to search. It decreases depending
   * on the want of already discovered tagets.  It is defined as the distance
   * at which a tile with BEST_POSSIBLE_SCORE would have to be found in
   * order to be better than the current most_desirable tile. */
  int max_dist = FC_INFINITY;

  /* Coordinates of most desirable tile. Initialized to make 
   * compiler happy. */
  int best_x = -1, best_y = -1;

  /* Path-finding stuff */
  struct pf_map *map;
  struct pf_parameter parameter;

#define DIST_FACTOR   0.6

  pft_fill_unit_parameter(&parameter, punit);
  parameter.get_TB = no_fights_or_unknown;
  /* When exploring, even AI should pretend to not cheat. */
  parameter.omniscience = FALSE;

! Can we find somewhere to go ??


  map = pf_create_map(&parameter);
  while (pf_next(map)) {
    float desirable;
    struct pf_position pos;

    pf_next_get_position(map, &pos);
      
    /* Our callback should insure this. */
    assert(map_is_known(pos.x, pos.y, pplayer));
        
    desirable = explorer_desirable(pos.x, pos.y, pplayer, punit);
    if (desirable == 0) { 
      /* Totally non-desirable tile. No need to continue. */
      continue;
    }
    desirable *= pow(DIST_FACTOR, pos.total_MC);

    if (desirable > most_desirable) {
      most_desirable = desirable;
      best_x = pos.x;
      best_y = pos.y;
      /* We want to break when
       *   most_desirable > BEST_POSSIBLE_SCORE * DIST_FACTOR^dist
       * which is equivalent to
       *   most_desirable/BEST_POSSIBLE_SCORE > DIST_FACTOR^dist
       *   log(most_desirable/BEST_POSSIBLE_SCORE) > dist * log(DIST_FACTOR)
       *   log(most_desirable/BEST_POSSIBLE_SCORE)/log(DIST_FACTOR) > dist
       */
      max_dist = log(most_desirable / BEST_POSSIBLE_SCORE) / log(DIST_FACTOR);
    }
  
    if (pos.total_MC > max_dist) {
      break;
    }
  }
  pf_destroy_map(map);

  /* Go to the best tile found. */

! So, we found interesting place to go

  if (most_desirable > 0) {
    /* TODO: read the path off the map we made.  Then we can make a path 
     * which goes beside the unknown, with a good EC callback... */

! Can we go here ??

    if (!ai_unit_goto(punit, best_x, best_y)) {
      /* Died?  Strange... */
      return FALSE;
    }

! Yes we can and we go

! But if we have some moves more......

    if (punit->moves_left > 0) {
      /* We can still move on... */

! Aaaarg.... Sure not same pos because we move just before...........

      if (!same_pos(punit->x, punit->y, x, y)) {
        /* At least we moved (and maybe even got to where we wnated).  
         * Let's try again. */
        return ai_manage_explorer(punit);

! And we can continue all the night... till stack or heap overflow..... on 
railroad....
! I have a saved game like this...... But..... even if we can solve this is not 
enough for :
! From A to B, from B to C, from C to A.... and so one....
! On the same saved game I can show you this kind of loop.

!  Have you an idea ????

! I think that railroad moves must be considered as 1/100 of normal move, like 
this we can stop loop
before exploding stack or heap. And if in 100 1/100 of move we are not close to 
our destination I
think that never we'll arrive.

      } else {
        /* Something went wrong. What to do but return?
         * Answer: if we're a trireme we could get to this point,
         * but only with a non-full complement of movement points,
         * in which case the goto code is simply requesting a
         * one turn delay (the next tile we would occupy is not safe).
         * In that case, we should just wait. */
        if (unit_flag(punit, F_TRIREME)
            && (punit->moves_left != unit_move_rate(punit))) {
          /* we're a trireme with non-full complement of movement points,
           * so wait until next turn. */
          return TRUE;
        }
        return FALSE;
      }
    }
    return TRUE;
  } else {
    /* Didn't find anything. */
    UNIT_LOG(LOG_DEBUG, punit, "failed to explore more");
    return FALSE;
  }


So, as I play alone, like with old Civ, can you give me some explainations 
about diplomatic AI ?
Why AI players are so "hard" ?? 
Why is it no possible to speak whith them before war ????

I know that you have many things to do but, if you can give me some "tricks" on 
your programs and
sub-routines, maybe can I try to write a diplomatic AI less "agressive". First 
of all, what are the
meaning of variables in the saved games and what is the synopsis of a 
diplomatic meeting ?

I say again, you did a very good job and I will be very happy to help you in 
this work.


Just... I'm french and I don't speak very well english, but I'am 50 years old 
and worked as dev in
Basic, Pascal, PL1, APL, Fortran, C, Prolog, Lisp,...... and what you don't 
imagine as
Cyber 7500 assembler and more...... Now I'm "security man" on Internet for the 
first industrial
french group.


Hopping to read you next..

Greetings.



----------------------------------------------------------

Il vaut mieux prendre ses désirs pour des réalités que de prendre son slip pour 
une tasse à café .

Pierre Dac

----------------------------------------------------------

Oursinou Desman
Dans sa tanière
99999 Montagne sur Ciel
France


Attachment: pgp9zp4oCEChX.pgp
Description: PGP signature


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