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

AI trade valuation quest

Discussion in 'Civ4 - Strategy & Tips' started by Ghpstage, Dec 20, 2013.

  1. Ghpstage

    Ghpstage Deity

    Joined:
    Jan 15, 2009
    Messages:
    2,944
    Location:
    Bristol, England
    Yes I remember him ranting about it, but did he know just how ridiculous the mechanic was?
    While it would never have actually been the case in civ, there could, hypothetically have been something to lower strategic resource trade value as some kind of measure to either prevent a civ getting wiped out by a third party, or to help fight against a rival.
    He will probably go on an even bigger rant due to its random nature :lol:
    I probably am confusing myself. It still seems awful low, i'll just have to track the numbers through a game at some point to rectify this!
    On the diplo points I agree, but it also would affect the grant value for either GPT or resource begs, which may very well be annoying.
    Self pillage, end turn :p
    There *may* be some kind of termination hit somewhere, but I very much doubt it.
    I came across it previously, and hunted down a thread you explained it in for someone who asked about it in the newbie questions thread earlier.
     
  2. Ghpstage

    Ghpstage Deity

    Joined:
    Jan 15, 2009
    Messages:
    2,944
    Location:
    Bristol, England
    Looking at what Tachy posted on resources, and at and around this specific line in CvPlayerAI.cpp
    Code:
    iTempValue += kLoopBuilding.getBonusProductionModifier(eBonus) / 10;
    On this, being as we cant build it right now it comes out nice and simple, just an extra 10% on top of a standard :)/:health: resource as SP is the only thing it has an impact on. If we could build it now it would be 20%.
    After SP is built gold loses its extra value, becoming equal to the other :)/:health: resources.
    So heres some worked example from a save stolen (and WBd) from NC 131!

    First a picture of the trade screen
    Spoiler :
    Here if we count up the named cities we find we have 10 and the French have 11, but the capitals don't show up on the trade screen so we need to add 1 to both so we have 11 and Louis has 12.

    Now using the formula gained earlier in the thread
    ((Lowest out of buyers citycount vs sellers citycount) + 3) * 30
    We get (11 + 3) * 30 = 420 for a standard resource.
    Calculating GPT from this. 420 / 20 = 21
    Spoiler :
    Which we can see above is correct (I don't see any necessity in showing screens of the AI refusing values just below, you'll just have to trust i tested it :p.

    The claim for gold is that the equation will be (11 + 3) * 1.1 * 30
    This gives us 462. This will round down to 460 on the trade table so the GPT cost will be 460 / 20 = 23
    Spoiler :


    Looking at this its pretty obvious that the AI tries to seriously rip off the player when we ask what the AI wants for gold, its request will be two standard :)/:health: resoruces or a resource of higher value where available, wheras it would only want 1 st resource + a small amount of GPT! Just 1-2GPT more in the overwhelming majority of games.

    The rest of basebonusval is still proving difficult to find a satisfactory way of dealing with in a useable way (though it may be unreasonable in general) and testing as the values for strategic resources change often through the game.
    Maybe i'll crack ivory tomorrow.
     
  3. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    GPhstage, muster all your ultraballs/masterball. There's a wild pokieman around here at level 72. It's downright rare appearance.
     
  4. Ghpstage

    Ghpstage Deity

    Joined:
    Jan 15, 2009
    Messages:
    2,944
    Location:
    Bristol, England
    :confused:

    Ok so Ivory, its at least relatively simple compared to the full strategic resources so will be useful for understanding how some of the unit related factors are taken into account.

    Case 1
    Classical era, before we have the techs to allow Wellies, SoZ isn't built

    We already know that the happiness has an initial value of + 100 and the previous testing explained why SoZ will give us + 10.
    As there will be multiplications of later values during this its best to say that the 100 value from hapiness is an initial ivalue, while the +10 from SoZ is part of a rolling tempvalue that needs to be kept seperate for now.

    After modifying the NC 131 test game some more I played around with trades to find that in this case, the minimum Louis would take is 29 :gold:.
    Spoiler :

    Spoiler :
    Code:
    					if (kLoopUnit.getPrereqAndTech() != NO_TECH)
    						{
    							iDiff = abs(GC.getTechInfo((TechTypes)(kLoopBuilding.getPrereqAndTech())).getEra() - getCurrentEra());
    
    							if (iDiff == 0)
    							{
    								iTempValue *= 3;
    								iTempValue /= 2;
    							}
    							else
    							{
    								iTempValue /= iDiff;
    							}
    						}
    As its the same era we multiply our 60 by 3 / 2 giving us 90.
    Right now the rest is irrelevant so adding this temp value to the initial ivalue gives 190.

    Thrown back into the bonustradeval function we can simplify by dividing this by 100 to get
    1.9 * (lowest city count + 3) * 30 = 570
    Turn to gold per turn by dividing by 20 = 28.5 which due to AIs wanting equal or more value in a trade, rounds up to 29GPT

    Case 2
    Same era, don't have techs for Wellies, SoZ built
    ((1 + (50 * 3 / 2) / 100) * (lowest city count +3) * 30 = 525 due to trade values rounding down to nearest 10 so 520.
    Then to GPT by dividng by 20 gives 26

    Case 3
    Same era, SoZ not built (but have Aesthetics), we do have techs for Wellies. Looking at Tachys list
    Spoiler :

    Starts same as case 1 to get ivalue = 100, and tempvalue of 60. but now we need to double it on top of the * 3 / 2 factor we have already used.
    60 * 2 * 3 / 2 = 180
    (180 + 100) / 100 = 2.8
    2.8 * 10 * 30 = 840
    As GPT 840 / 20 = 42.
    Spoiler :

    So far so good. Will add the cases of medieval cost, and obsoletion at Cuirassiers later.

    But I have had an issue, where the cost was only 39GPT when we could build Wellies, and I didn't have Aesthetics while SoZ hadn't been built. This is a problem as if we remove the +10 from SoZ (by building it) the predicted value drops to 38 as shown below, and if we remove that 10 we mess up the pre-SP value of the gold resource too. EDIT - There are further problems I have seen while messing around in WB.
    Spoiler :
    :confused:

    I think with the shear number of resource dependant units, and building/wonder/project speeding impacts of the proper strategic resources it'll be too comlicated to follow. As such if you want to calculate it'll be best to follow Tachy's steps as they have been given quite a good trial, though for now I have no clue how the Cathedrals will react due to the religious requirement.

    As a small thing to take away from this, it means that its cheaper to trade for Ivory before you get HBR and Construction.
    A similar thing should happen with other strat resources (e.g. Horse cost reducing when getting Knights due to both Chariots and HA obsoleting!), but it will be very hard to track and test without a spreadsheet.

    I have started a spreadsheet to cover all the resources, and am getting some success under some conditions. I'm going to just carry on with that rather than try to get my head around the rest of it as it will be much faster to test under varying conditions and will actually be useable in the end, despite the mass of equations it'll probably be quicker to debug too. And once thats conquered, then corps.
     
  5. Ghpstage

    Ghpstage Deity

    Joined:
    Jan 15, 2009
    Messages:
    2,944
    Location:
    Bristol, England
    So far the spreadsheet for calculating basebonusval is actually going quite well. Its managed to produce the values in the above posts (even the wierd ones) and covers standard :)/:health: resources, Gold and Ivory and should even take into account the era and obsoletion.

    I have hit an obstacle I need to get around before going forward, that is the shear number of imputs from each resource (Ivory needed a 3 line formula....). For marble theres 14 things to evaluate (15 if Creative Constructions HQ is counted as i suspect), to Ivories 3, just repeating the same functions over and over again will make it ridiculously time consuming and easy to make mistakes.

    As a result i'm now trying to find a way to repeat a function group for certain cells to a range of other cells (they are right next to each other) without adding up the intenal. Maybe someone here will have an idea

    e.g. If I had
    (Max($C12,S5)-Min($C12,S5)+IF(R5=blah,1,0)*IF(Q= blah,2,1))
    Is there a function that would allow me to repeat the evaluation for say, the next X cells downward without having to repeat the whole function in the original formula X times while changing the S, R and Q values.

    EDIT - Horse values are damn close right now, seems like there may be a rounding error somewhere, either that or the excel auto fix screwed something up.....
     
  6. Kaitzilla

    Kaitzilla Lord Croissant

    Joined:
    Jun 21, 2008
    Messages:
    8,704
    Gender:
    Male
    Location:
    America!
    There seems to be a revival in people interested in game mechanics, so I'm gonna bump Ghpstage's baby back to the front.

    :bump:

    Thanks for teaching me exactly how much :gold: the AI is willing to trade on any given turn.
     
    Last edited: Feb 24, 2020
    krikav, Harv and sampsa like this.

Share This Page