1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Report Questionable Behavior

Discussion in 'Civ4 - Better AI' started by Iustus, Jan 25, 2007.

  1. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    Jdog, I've caught a minor bug in your function in "int CvPlot::calculateImprovementYieldChange(ImprovementTypes eImprovement, YieldTypes eYield, PlayerTypes ePlayer, bool bOptimal, bool bBestRoute) const".

    It calculates the yield that the improvement will change on this plot. What it doesn't account for is that the minimum yield on a plot is 0. If I have a plot producing no hammers, and my improvement subtracts a hammer, your function returns -1 (causing the AI to avoid it, when it doesn't actually matter), when in reality, the improvement doesn't affect production. I suggest you return this instead:

    Code:
    	int iCurrYield = calculateNatureYield(eYield, ePlayer == NO_PLAYER ? NO_TEAM : GET_PLAYER(ePlayer).getTeam(), bOptimal);
    	if (iCurrYield + iYield <= 0)
    	{
    		return -iCurrYield;
    	}
    
    	return iYield;
    
    Which would return 0 instead of -1.
     
  2. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    There is a simple assumption made here: if a buildable improvement has a negative effect, it actually has negative effect. A workshop is only allowed on flatlands which produce at least 1 food so the negative effect always matters.
    Spoiler :
    Allowing improvements with negative effects on plots where that effect doesn't come into play is a bit absurd, why bother adding that negative effect in the first place, so that it would only be viable on grassland? That terrain type is strong enough as it is, I think you should consider removing that negative effect from your farms.
     
  3. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    It has the effect of -1 production, and it can be built on grass (Where it has no effect), but removes the hammer from plains. Or did you forget plains was flatlands too. :p
     
  4. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    Actually no, the opposite. I saw it will remove production from plains but leave grassland alone. The farms thus have no negative effect when built on grassland, which makes them even stronger there than they would have been anyways. If that's on purpose, as I assume it is, it's still questionable at best because one improvement has different actual effects on different terrain.
    short version: plains farms are underpowered.
     
  5. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    The farm thing was simply an example... I don't actually have farms that have a negative yield. I do have a mine that has negative food though.

    Whether it's practical, or balanced is irrelevant to the main point. The function's name (and intended purpose) is "calculateImprovementYieldChange", so it Calculates the change in yield the improvement will bring. Since the total yield can never go negative, this function should reflect that. I fail to see the issue with making it work correctly.
     
  6. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    Simple enough to fix and won't affect the normal game, thanks Afforess.
     
  7. mwyeoh

    mwyeoh Chieftain

    Joined:
    Jun 5, 2009
    Messages:
    36
    I found a bug, which wasnt in the game prior to v1.00

    When you have heaps of siege units in a stack, more than the enemy has troops in their stack, all of them can attack even though the last few arent doing any damage or collateral to enemy troops.

    Previously, once your siege units could no longer do damage, they could no longer attack an enemy stack
     
  8. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    I tried recreating this with a stack of catapults but couldn't, it seems to work correctly for me and after the enemy gets below a certain health level the rest of the catapults cannot attack. Stack attack also worked fine.

    Can you post a save?
     
  9. mwyeoh

    mwyeoh Chieftain

    Joined:
    Jun 5, 2009
    Messages:
    36
    Sure, heres a save game. Theres a large stack of cannon next to Chaco Canyon ready to attack Sitting Bull

    Also, all the cannon that attack, despite not actually doing any damage receive experience

    For me I seem to be able to reproduce it no matter what siege unit Im using
     

    Attached Files:

  10. Still_Asleep

    Still_Asleep Warlord

    Joined:
    Apr 5, 2006
    Messages:
    152
    Location:
    Vienna, Austria
    I found the city-raze logic a bit questionable in my last game.

    It was early game, Ragnar was my direct neighbour and attacked me. Captureds St.Petersburg within 2 turns, and razed it.

    However, St.Petersburg was directly adjacent to Ragnars empire, in a good spot with ressources Ragnar needed, not surrounded by foreign culture, easy to defend for Ragnar (I played bad and had no army...), and Ragnar had a very small empire and no chance to expand peacefully anymore.


    Basically, he attacked the right target at the right time and then refused to accept his reward :eek:

    The save is from my next turn, you can see the Viking stack on the right side of Moscow, standing on top of city ruins. That was size 5 St.Petersburg.
     

    Attached Files:

  11. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    BBAI.log or the save from the turn before would actually shed a bit of light on the situation. The save from afterwards, probably not so much.
     
  12. Yxklyx

    Yxklyx King

    Joined:
    May 7, 2008
    Messages:
    869
    I've never seen the AI build like this before; I attacked France early on (Prince) with Chariots and encountered an army of about 30 Warriors. France didn't get Archery until much later and he didn't have Copper or Iron.
     
  13. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    Thanks mwyeoh, I've got the bug happening now. What appears to cause the bug is the presence of a ship in the city. Some change (I think from Lead from Behind, cause it changes a lot of these functions) appears to have made the code consider the ship a possible target, at least enough so that it lets you launch an attack (but the actual attack code blocks that properly).

    Will looking in to it.
     
  14. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    Just want to make sure you don't miss my post:


     
  15. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    mwyeoh:

    Thank you for reporting that bug, I have fixed it for the next version. I also posted in the Lead from Behind thread, hopefully the fix will be included there as well.

    Afforess:

    Thanks, I'm not surprised that a non-vanilla feature had terrible logic underneath. Will take a look at your code an incorporate.
     
  16. mwyeoh

    mwyeoh Chieftain

    Joined:
    Jun 5, 2009
    Messages:
    36
    No problem
    :)
     
  17. Axios

    Axios Warlord

    Joined:
    Oct 19, 2009
    Messages:
    126
    Location:
    Italy
    Hi everyone,
    I playing a hemisperes, Warlord level, Normal speed game. I'm Korea. In 1960 AD I declare war to Darius (Persian) on my same continent. Immediately I send a transport with 4 tanks for destroy his unique oil well and than park the tanks over the oil tile. Than I attack his cities.
    Darius in 15 turns don't try to regain oil except when he send a single anti tank intantry unit which is wiped out by one of the 4 tanks:eek::eek:.
    Without oil Darius cannot combat well against my attack force: tanks, artillery, infantry, figthers, destroyer and battleship. He go in "survival mode" -> no counter attack and wait in his cities my attack troops.

    I think that in modern wars AI must protect better Oil (and also Aluminum and Uranium). For example: if an AI pillage my unique Oil well with 4 tanks I will send minimum 6 anti tank infantry and also suicides troops in order to regain Oil...

    Infact no Oil no modern units.....

    Also AI should apply the same schema when attacking another player: cutting off enemy's strategic resources.

    I post 2 zip files:
    1) auto save from 1960 AD to 1967 AD
    2) BBAI 1.00 + BUG 4.4 (absolutely I made no changes at the mods)

    I know that programming AI is not easy but I hope that people like Jdog, Afforess, Fuyu, LunarMongoose can solve this problem.

    Thanks in advance for replies. If is necessary to post other autosave tell me.

    PS: BBAI is great!!!!!! :goodjob::goodjob:
     

    Attached Files:

  18. LunarMongoose

    LunarMongoose King

    Joined:
    Jan 29, 2006
    Messages:
    731
    Gender:
    Male
    Location:
    Boston, MA, USA
    Saves aren't necessary for this I would think, since the behavior you describe is obvious and not a rare bug or something.

    I realize oil is the single most important one of them all, but iron and horses and anything else can have the same tide-turning effect in many cases. Assuming there is already code present to make AIs defend their resources in any way shape or form, it should be pretty easy to increase the priority for unique strategics.

    Making AIs target key enemy strategics as part of a war strategy is an entirely different animal (probably a llama) however. I seem to vaguely recall JDog mentioning this in his text files at one point a while back, and it may already be in the code for all I know, but if it's not this is a non-trivial thing to add.

    But there was a bug just reported in the version 1.0 thread about AIs being unwilling to capture empty cities which I'm going to have to fix if JDog doesn't get back again soon, so I guess I can take a look at the strategic resource stuff too.
     
  19. Axios

    Axios Warlord

    Joined:
    Oct 19, 2009
    Messages:
    126
    Location:
    Italy
    Thanks for the reply. Waiting Jdog for more info.
    I think that will be wondeful if next BBAI will manage a strategy for pillage strategic resources.
     
  20. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    A good point Axios ... the AI definitely doesn't understand and act on the importance of oil and other strategic resources well enough, defensively or offensively.

    To improve this we'd need a three staged approach:

    1. Resource defense: The AI should defend its important strategic resources very heavily. I remember noting that it treated most resources the same, but I may have fixed that a while ago. This is the easiest part to improve as it just requires tweaking existing logic.

    2. Recapture pillaged resource tiles: I don't believe the AI ever worries about this explicitly ... right now it's a tactic only a human player uses, and the AI has no counter strategy. The AI will build defensive stacks that will counter attack enemy stacks in its territory, but they don't consider resources when making decisions.

    3. Resource offense: The AI will take out resources which are unguarded, but it doesn't yet consider attacking guarded resources as far as I remember, and certainly doesn't then stick around to deprive their opponent longer. This behavior would be possible to add to attack city stacks who are not strong enough to take a city alone, could probably also get some attempt at denial also by splitting off a few units who can defend.

    I'll keep thinking about the right way to implement this ... any other ideas or comments?
     

Share This Page