Complete.Org: Mailing Lists: Archives: freeciv-ai: December 2002:
[freeciv-ai] Re: Time to enemy city/unit
Home

[freeciv-ai] Re: Time to enemy city/unit

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: Time to enemy city/unit
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Sun, 29 Dec 2002 04:44:47 -0800 (PST)

--- Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx> wrote:
> 
> Attached is a patch which separates very similar calculations from:
>   find_something_to_kill
>   kill_something_with
>   process_attacker_want
> into 2 new functions
>   time_to_enemycity/unit
> which provide an estimate of the time required to reach city/unit.

Thank you. At long last this nightmare of a function can be put to sleep.
 
> Also, I provide a new function which allows to get the type of the boat the
> player would be able to build, thus getting rid of some hardcoded values,
> guesses and checks.

There are still some hardcoded checks in the code.

ai/aiunit.c, line 1726 -- boatspeed = (unit_flag(ferryboat, F_TRIREME) 
ai/advmilitary.c, line 1070 -- boatspeed = (unit_flag(ferryboat, F_TRIREME)  

ai/aiunit.c, line 1729 -- boatspeed = ((get_invention(pplayer, game.rtech.nav)
!= TECH_KNOWN)
ai/advmilitary.c, line 452 -- boatspeed = ((get_invention(aplayer,
game.rtech.nav) == TECH_KNOWN) 

Any chance you could fix these as well in a future patch?

> > diff -ur -X freeciv_st/diff_ignore freeciv_clean/ai/advmilitary.c
> freeciv_st/ai/advmilitary.c
> --- freeciv_clean/ai/advmilitary.c    Tue Dec 24 23:45:11 2002
> +++ freeciv_st/ai/advmilitary.c       Wed Dec 25 19:13:38 2002
> @@ -811,25 +811,25 @@
>                                    int value, Unit_Type_id victim_unit_type,
>                                    bool veteran, int x, int y, bool unhap,
>                                    int *best_value, int *best_choice,
> -                                  int boatx, int boaty, int boatspeed,
> +                                  struct unit *boat, Unit_Type_id boattype,
>                                    int needferry)
>  { 

Am I the only one who feels that are far *too* many params being given to this
function? 

<snip>
> +/***************************************************************************
> + * A rough estimate of time (measured in turns) to get to the enemy city, 
> + * taking into account ferry transfer.
> + * If boat == NULL, we will build a boat of type boattype right here, so
> + * we wouldn't have to walk to it.
> + *
> + * Requires ready warmap(s).  Assumes punit is ground or sailing.
> +
> ***************************************************************************/
> +int time_to_enemy_city(Unit_Type_id our_type,  struct city *acity,
> +                       int speed, bool go_by_boat, 
> +                       struct unit *boat, Unit_Type_id boattype)
> +{
> +  switch(unit_types[our_type].move_type) {
> +  case LAND_MOVING:
> +    if (go_by_boat) {
> +      int boatspeed = unit_types[boattype].move_rate;
> +      int move_time = (warmap.seacost[acity->x][acity->y]) / boatspeed;
> +      
> +      if (unit_type_flag(boattype, F_TRIREME) && move_time > 2) {
> +        /* Return something prohibitive */
> +        return 999;
> +      }

Doesn't make sense if the AI has Lighthouse. No more risk of the trireme
disappearing.  

Aloha,
RK.

Great spirits have always found violent opposition from mediocrities. The
latter cannot understand it when a man does not thoughtlessly submit to
hereditary prejudices but honestly and courageously uses his intelligence.
-Albert Einstein 

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


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