This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Revised exploring_worth function


I was looking over the code in ai.c after hearing about all of the
recent bug fixes, and I noticed something odd in the exploring_worth
function.  It looks like exploring_worth considers only how fast a unit
moves, but not if it's range is limited by materials.  As a result, in
the standard game, it thinks that the most valuable exploratory units
are fighters (but 9 cells is not a very long range).

I've been working on a revised exploring_worth function that should make
units with greater range more valuable than units with shorter range. 
However, I have not yet tested it enough to be sure that it works
correctly.  I do see that the AI still will assign a short-range unit
(e.g. a fighter) to explore an area that it couldn't possibly get to,
but that probably means that there's a similar bug somewhere else in
either the AI code or the planning code.

Any comments?  I'm not (yet) completely familiar with the AI code, but
as far as I can tell, this is an improvement.
The new code is: 

int
exploring_worth(int u)
{
    /* An important consideration in many games is if the range is a unit is
       limited by materials.  Try to determine the most limiting factor. */
    int velocity = u_acp(u) * u_speed(u) / 100;
    int range1 = 32767; /* By the end of the for_all_material_types loop, the range of the unit */
    int range2;         /* On each test, the candidate for the range (the smallest value is correct) */
    int worth, m, base;

    /* Assume that if um_consumption_per_move > 0, um_material_to_move > 0,
       and if either ( um_base_production - um_base_consumption ) < 0 or
       um_consumption_per_move > 0, then hp_per_starve > 0. */

    if ( velocity > 0 ) {
        for_all_material_types(m) {
            if ( um_storage_x(u, m) > 0 ) {
                /* This material can be stored; what is it used for? */
                base = um_base_production(u, m) - um_base_consumption(u, m);
                if ( base < 0 ) {
                    /* It is part of basic consumption. */
                    range2 = um_storage_x(u, m) / (-base);
                    /* Does it limit range any more than another material? */
                    if ( range2 < range1 )
                        range1 = range2;
                }

                if ( um_consumption_per_move(u, m) > 0 ) {
                    /* Some of it is consumed every time the unit moves. */
                    range2 = um_storage_x(u, m) / ( um_consumption_per_move(u, m) * velocity );
                    if ( range2 < range1 )
                        range1 = range2;
                }
            }
        }
    }

    /* The most valuable explorers may be either the fastest or the longest-range.
       Of course, range doesn't matter if materials aren't involved,
       and any attempt to consider materials for them would cause an overflow! */
    if ( range1 < 32767 )
        worth = velocity * range1;
    else
        worth = velocity * world.circumference;

    DMprintf("unit type %s explorer worth %d \n ", u_type_name(u), worth);
    if (worth < 0)
	init_warning("%s has negative explorer worth", u_type_name(u));
    return worth;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]