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]

More revisions to exploring_worth


I added some more code to the exploring_worth function.  This new code
considers the types of terrain that a unit can survive on, move around
on, etc., and incorporates that into the overall worth.  This particular
piece of code should favor aircraft (because they don't vanish or wreck
anywhere, and move at the same rate on all terrain) and ships (assuming
the map is mostly water), but the "range" code should still stop the AI
from considering short-range aircraft as good explorers.

It shouldn't be too difficult to also incorporate some of Bob
Carragher's ideas, such as vision-range, visibility, construction time,
and defensive worth.  Of course, some ideas, such as supporting units
(e.g. fighters, subs, and destroyers as escorts for a carrier) are still
too far beyond the understanding of the AI to be implemented at all. 
But I do think that they'll be possible at some point.


Now the function looks like:

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 mobility = 0;	/* Represents what portion of the map the unit can move around on */
    int worth, m, t, 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;
                }
            }
        }

        /* It should also be considered what kind of terrain the unit can move on, and how common that terrain is. */
        for_all_terrain_types(t) {
            if ( ( ! ut_vanishes_on(u, t) ) && ( ! ut_wrecks_on(u, t) ) ) {
                /* Can explore this terrain without dying! */
                mobility += ( t_alt_max(t) - t_alt_min(t) + t_wet_max(t) - t_wet_min(t) ) / ( ut_mp_to_enter(u, t) + 1 );
            }
        }
    }

    /* 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 * mobility;
    else
        worth = velocity * world.circumference * mobility;

    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;
}

And the worths it assigns to units in the standard game are:
infantry:		972
armor:			2520
fighter:		18684
bomber:			37368
destroyer:		40200
submarine:		40200
troop transport:	53600
carrier:		187200
battleship:		93600
nuclear bomb:		106560
base:			0
town:			0
city:			0

(The reason that these numbers are so much higher than before is that
it's taking a lot more factors into account.  The numbers may be bigger,
but they're also more accurate.)


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