[Freeciv-Dev] Re: [PATCH2] Re: AI questions
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
--- Petr Baudis <pasky@xxxxxxxxxxx> wrote:
> > Do we try to sell wonders currently? I strongly suspect you are wrong on
> this
> > point.
> >
I am wrong. I cannot believe this bug was not mentioned. Petr, we need a
list of the outstanding bugs in the AI.
<snip>
> So here it goes, splitted into two separate patches. First one improves
> formatting, second one changes testing for B_CITY by testing for zero upkeep
> in
> ruleset.
>
> Also, I'm including corrected version of explorer patch, grep betrayed me and
> didn't show tokens in server/unit(hand|tools).c - I really hope i will
> *finally* start posting correct patches :|.
Petr, Raimar is going to choke on this patch. We both know this, Greg knows
this. Please resend a patch without the formatting changes. Do not take up the
formatting stuff with me. Raimar is the man you have to talk to.
The changes you make are good. I vote for inclusion.
> > diff -ru freeciv/ai/aicity.c freeciv+pasky/ai/aicity.c
> --- freeciv/ai/aicity.c Thu Oct 4 22:23:31 2001
> +++ freeciv+pasky/ai/aicity.c Sat Nov 24 20:26:37 2001
> @@ -312,9 +312,10 @@
> static void try_to_sell_stuff(struct player *pplayer, struct city *pcity)
> {
> Impr_Type_id id;
> +
> for (id = 0; id < game.num_impr_types; id++) {
> + /* selling walls to buy defenders is counterproductive -- Syela */
> if (can_sell_building(pcity, id) && id != B_CITY) {
> -/* selling walls to buy defenders is counterproductive -- Syela */
> really_handle_city_sell(pplayer, pcity, id);
> break;
> }
> @@ -792,10 +793,10 @@
> static void ai_sell_obsolete_buildings(struct city *pcity)
> {
> Impr_Type_id i;
> -
> struct player *pplayer = city_owner(pcity);
> - for (i=0;i<game.num_impr_types;i++) {
> - if(city_got_building(pcity, i)
> +
> + for (i = 0; i < game.num_impr_types; i++) {
> + if (city_got_building(pcity, i)
> && !is_wonder(i)
> && i != B_CITY /* selling city walls is really, really dumb -- Syela
> */
> && (wonder_replacement(pcity, i) ||
> building_unwanted(city_owner(pcity), i))) {
> > diff -ru freeciv/ai/aicity.c freeciv+pasky/ai/aicity.c
> --- freeciv/ai/aicity.c Sat Nov 24 20:26:37 2001
> +++ freeciv+pasky/ai/aicity.c Sat Nov 24 20:36:45 2001
> @@ -315,7 +315,10 @@
>
> for (id = 0; id < game.num_impr_types; id++) {
> /* selling walls to buy defenders is counterproductive -- Syela */
> - if (can_sell_building(pcity, id) && id != B_CITY) {
> + /* Selling palace too. Virtually selling of every building with
> + * original upkeep 0. We can't exempt all buildings with real
> + * upkeep 0 because e.g. B_ASMITHS. --pasky */
> + if (can_sell_building(pcity, id) && improvement_types[i].upkeep) {
> really_handle_city_sell(pplayer, pcity, id);
> break;
> }
> @@ -796,9 +799,13 @@
> struct player *pplayer = city_owner(pcity);
>
> for (i = 0; i < game.num_impr_types; i++) {
> + /* selling city walls is really, really dumb -- Syela */
> + /* Selling palace too. Virtually selling of every building with
> + * original upkeep 0. We can't exempt all buildings with real
> + * upkeep 0 because e.g. B_ASMITHS. --pasky */
> if (city_got_building(pcity, i)
> && !is_wonder(i)
> - && i != B_CITY /* selling city walls is really, really dumb -- Syela
> */
> + && improveement_types[i].upkeep
> && (wonder_replacement(pcity, i) ||
> building_unwanted(city_owner(pcity), i))) {
> do_sell_building(pplayer, pcity, i);
> notify_player_ex(pplayer, pcity->x, pcity->y, E_IMP_SOLD,
> > diff -ru freeciv/ai/aiunit.c freeciv+pasky/ai/aiunit.c
> --- freeciv/ai/aiunit.c Sat Nov 24 00:42:27 2001
> +++ freeciv+pasky/ai/aiunit.c Sat Nov 24 21:05:01 2001
> @@ -177,24 +177,23 @@
> }
>
> /**************************************************************************
> -Explores unknown territory, finds huts.
> +Handle eXplore mode of a unit - explores unknown territory, finds huts.
> Returns whether there is any more territory to be explored.
> **************************************************************************/
> -int ai_manage_explorer(struct unit *punit)
> +int ai_manage_exploring(struct unit *punit)
> {
> struct player *pplayer = unit_owner(punit);
> - int x, y; /* is the position of the unit; updated inside the function */
> - int con; /* continent the unit is on */
> - struct city *pcity;
> + int x, y; /* the position of the unit; updated inside the function */
> + int continent; /* continent the unit is on */
> int id = punit->id; /* we can now die because easy AI may accidently
> stumble on huts it fuzzily ignored */
> - int best_x = -1, best_y = -1;
> + int best_x = -1, best_y = -1; /* desired destination */
> int move_rate = unit_move_rate(punit);
> - int range;
> + int range; /* range of unit's vision */
>
> if (unit_profits_of_watchtower(punit)
> && map_get_tile(punit->x, punit->y)->special & S_FORTRESS)
> - range =get_watchtower_vision(punit);
> + range = get_watchtower_vision(punit);
> else
> range = unit_type(punit)->vision_range;
>
> @@ -202,17 +201,19 @@
> handle_unit_activity_request(punit, ACTIVITY_IDLE);
>
> x = punit->x; y = punit->y;
> - if (is_ground_unit(punit)) con = map_get_continent(x, y);
> - else con = 0; /* Thanks, Tony */
> + if (is_ground_unit(punit)) continent = map_get_continent(x, y);
> + else continent = 0; /* ships don't care about continents */
>
> /* CPU-expensive but worth it -- Syela */
> generate_warmap(map_get_city(x, y), punit);
>
> - /* BEGIN PART ONE: Look for huts. Non-Barbarian Ground units ONLY. */
> + /* PART ONE: Look for huts.
> + * Non-Barbarian Ground units ONLY.
> + */
> if (!is_barbarian(pplayer)
> - && is_ground_unit(punit)) { /* boats don't hunt huts */
> + && is_ground_unit(punit)) {
> int maxcost = pplayer->ai.control ? 2 * THRESHOLD : 3;
> - int bestcost = maxcost * SINGLE_MOVE + 1;
> + int bestcost = maxcost * SINGLE_MOVE + 1; /* lower is better */
>
> /* Iterating outward so that with two tiles with the same movecost
> the nearest is used */
> @@ -227,6 +228,7 @@
> bestcost = warmap.cost[best_x][best_y];
> }
> } iterate_outward_end;
> +
> if (bestcost <= maxcost * SINGLE_MOVE) {
> punit->goto_dest_x = best_x;
> punit->goto_dest_y = best_y;
> @@ -235,15 +237,17 @@
> if (!player_find_unit_by_id(pplayer, id))
> return 0; /* died */
>
> + /* We can still move on.. */
> if (punit->moves_left) {
> + /* ..and we got into desired place. */
> if (punit->x == best_x && punit->y == best_y) {
> - return ai_manage_explorer(punit);
> + return ai_manage_exploring(punit);
> } else {
> /* Something went wrong; fall through. This should almost never
> happen.
> */
> if (punit->x != x || punit->y != y)
> generate_warmap(map_get_city(punit->x, punit->y), punit);
> x = punit->x; y = punit->y;
> - /* Fallthough to next fase */
> + /* Fallthough to next phase */
> }
> } else {
> return 1;
> @@ -251,28 +255,34 @@
> }
> }
>
> - /* BEGIN PART TWO: Move into unexplored territory */
> - /* move the unit as long as moving will unveil unknown territory */
> + /* PART TWO: Move into unexplored territory
> + * Move the unit as long as moving will unveil unknown territory
> + */
> while (punit->moves_left) {
> - int most_unknown = 0;
> - int unknown;
> + int most_unknown = 0; /* max. number of unknown tiles */
>
> /* evaluate all adjacent tiles */
> square_iterate(x, y, 1, x1, y1) {
> - unknown = 0;
> + int unknown = 0; /* number of unknown tiles reachable from this tile
> */
> +
> + /* and all tiles in our vision range around them */
> square_iterate(x1, y1, range, x2, y2) {
> if (!map_get_known(x2, y2, pplayer))
> unknown++;
> } square_iterate_end;
>
> + /* We have to be careful with triremes, we won't travel to
> + * another continents, won't travel into cities (unless we
> + * are able to do so - diplomats and caravans can) and we
> + * won't raze huts if we are barbarians.
> + */
> if (unknown > most_unknown && (!unit_flag(punit, F_TRIREME)
> || trireme_loss_pct(pplayer, x1,
> y1) == 0)
> - && map_get_continent(x1, y1) == con
> + && map_get_continent(x1, y1) == continent
> && can_unit_move_to_tile_with_notify(punit, x1, y1, 0)
> - && !((pcity = map_get_city(x1,y1))
> - && (unit_flag(punit, F_DIPLOMAT)
> - || unit_flag(punit, F_CARAVAN)))
> + && !(map_get_city(x1,y1) &&
> + (unit_flag(punit, F_DIPLOMAT) || unit_flag(punit, F_CARAVAN)))
> && !(is_barbarian(pplayer) && map_get_special(x1, y1) & S_HUT)) {
> most_unknown = unknown;
> best_x = x1;
> @@ -280,43 +290,55 @@
> }
> } square_iterate_end;
>
> - if (most_unknown > 0) { /* a tile have unexplored territory adjacent */
> + /* a tile have unexplored territory adjectent, move there */
> + if (most_unknown > 0) {
> int res = handle_unit_move_request(punit, best_x, best_y, FALSE,
> FALSE);
> if (!res) /* This shouldn't happen */
> break;
> +
> if (!player_find_unit_by_id(pplayer, id))
> return 0; /* died */
> x = punit->x; y = punit->y;
> } else {
> - break;
> + break; /* we explored everything */
> }
> }
>
> if (!punit->moves_left) return 1;
>
> - /* BEGIN PART THREE: Go towards unexplored territory */
> - /* no adjacent squares help us to explore - really slow part follows */
> + /* PART THREE: Go towards unexplored territory
> + * No adjacent squares help us to explore - really slow part follows
> + */
> generate_warmap(map_get_city(x, y), punit);
>
> {
> - int unknown, most_unknown = 0;
> - int threshold = THRESHOLD * move_rate;
> + int most_unknown = 0; /* max. number of unknown tiles */
> +
> whole_map_iterate(x1, y1) {
> struct tile *ptile = map_get_tile(x1, y1);
> - unknown = 0;
> - if (ptile->continent == con
> + int threshold = THRESHOLD * move_rate;
> + int unknown = 0; /* number of unknown tiles reachable from this tile
> */
> +
> + /* We won't travel to another continents or into foreign occupied
> squares. */
> + if (ptile->continent == continent
> && !is_non_allied_unit_tile(ptile, pplayer)
> && !is_non_allied_city_tile(ptile, pplayer)
> && tile_is_accessible(punit, x1, y1)) {
> +
> + /* evaluate all tiles in our vision range around this tile */
> square_iterate(x1, y1, range, x2, y2) {
> if (!map_get_known(x2, y2, pplayer))
> unknown++;
> } square_iterate_end;
> +
> if (unknown) {
> + /* also care about how fast we can get there */
> if (is_sailing_unit(punit))
> unknown += 9 * (threshold - warmap.seacost[x1][y1]);
> else
> unknown += 9 * (threshold - warmap.cost[x1][y1]);
> +
> + /* We won't raze huts if we are barbarians. */
> if ((unknown > most_unknown || (unknown == most_unknown && myrand(2)))
> && !(is_barbarian(pplayer) && ptile->special & S_HUT)) {
> best_x = x1;
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1
- [Freeciv-Dev] Re: AI, (continued)
- [Freeciv-Dev] Re: AI, Raimar Falke, 2001/11/25
- [Freeciv-Dev] Re: AI, Raahul Kumar, 2001/11/25
- [Freeciv-Dev] Re: AI, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: AI, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: AI, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: AI, Raahul Kumar, 2001/11/27
- [Freeciv-Dev] Re: AI (THRESHOLD magic), Petr Baudis, 2001/11/27
- [Freeciv-Dev] Re: AI (THRESHOLD magic), Raahul Kumar, 2001/11/28
- [Freeciv-Dev] Re: AI (THRESHOLD magic), Raahul Kumar, 2001/11/28
- [Freeciv-Dev] [PATCH2] Re: AI questions, Petr Baudis, 2001/11/24
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions,
Raahul Kumar <=
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Raimar Falke, 2001/11/26
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Raimar Falke, 2001/11/25
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Raimar Falke, 2001/11/25
- [Freeciv-Dev] Re: [PATCH2] Re: AI questions, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Re: AI questions, Raahul Kumar, 2001/11/24
- [Freeciv-Dev] Re: AI questions, Petr Baudis, 2001/11/24
- [Freeciv-Dev] Re: AI questions, Ross W. Wetmore, 2001/11/25
|
|