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

Slave Economy - A Pitiful Method to Abuse Your Neighbours

Discussion in 'Civ4 Strategy Articles' started by Manco Capac, Jul 23, 2012.

  1. Revent

    Revent Will SIP

    Joined:
    May 5, 2012
    Messages:
    1,914
    Location:
    London
    Yes indeed, moving the warrior traps him due to the worker not being able to access the shortest 1 turn route to the city anymore which is blocked by the scout :)
     
  2. Sun Tzu Wu

    Sun Tzu Wu Chieftain Supporter

    Joined:
    Mar 26, 2007
    Messages:
    7,920
    Player Civs that start with Hunting, start with a Scout. This means no early Worker steals, until a Warrior is trained.

    I was wondering whether it might make sense to research Archery at t0, and build a Worker stealing Archer when done.

    I realize that this is dubious strategem, but it would offer much better survival odds when the AI counterattacks.

    Sun Tzu Wu
     
  3. Zx Zero Zx

    Zx Zero Zx Chieftain

    Joined:
    Apr 23, 2009
    Messages:
    2,145
    Location:
    Minnesota
    It's to bad that archers can't get the forest promotion. Otherwise this would make them very solid. But this might be pretty good bellow Deity.
     
  4. UnforcedError

    UnforcedError Settler

    Joined:
    May 1, 2012
    Messages:
    3,298
    Gender:
    Female
    Location:
    Budapest, Hungary
    I think it depends on the map and your other starting tech. It may be viable e.g. with a deer / fur start, but archers are still more costly then warriors.
     
  5. Sun Tzu Wu

    Sun Tzu Wu Chieftain Supporter

    Joined:
    Mar 26, 2007
    Messages:
    7,920
    Agreed. However, Archers can get Guerrilla promotions which would be great on hilly Maps. The pseudo 2 movement of Guerrilla II units via hills is very effective and fun.

    Sun Tzu Wu
     
  6. Zx Zero Zx

    Zx Zero Zx Chieftain

    Joined:
    Apr 23, 2009
    Messages:
    2,145
    Location:
    Minnesota
    True, but Guerrilla III is just not as good as Woodsman III. I <3 Woodsman III Medic III super medics.
     
  7. Revent

    Revent Will SIP

    Joined:
    May 5, 2012
    Messages:
    1,914
    Location:
    London
    Guerilla can actually be very effective as well because capitals always have x number of hills so very well possible to easy steal workers. Also a lot more likely for the archer to survive. I've seen Longbows on a hill survive attacks from 10 units with hills 3 (followed by eventual drill). Short term more expensive, but long term, saves hammers as you steal a worker and most likely won't lose the archer.
    Plus, if an AI has high attack courage, chances are, he will not do as well attacking an archer so if you kill during defence, it's a lot more likely to get peace.
     
  8. LowtherCastle

    LowtherCastle Chieftain

    Joined:
    May 18, 2005
    Messages:
    21,764
    1. I've noticed that 2 mvmt units can catch workers with their pants down by being next to a road that was two tiles from the worker. Evidently, the code does work across off-road-to-road movements.
    2. Tachy, I'm thinking a big step forward would be if you completed your analysis of AI worker actions, so that the slave master could predict where the workers will go for capture. Plus, when do they work in pairs or triplets?
     
  9. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    ^
    Yes, the article isn't finished.

    1. That is one of the trick I listed, but seems I stopped there.
    2. AI workers are rather difficult to unravel. I recall I tried and stopped at AI_bonusVal(), which evaluates the value of a bonus, so the most valued are improved, then I went to CvCityAI.cpp for the code about worker improving BFC and that was monstrous...so many conditions.
     
  10. vanillasine

    vanillasine Chieftain

    Joined:
    Dec 26, 2007
    Messages:
    270
    I have just completed IU 90: Hammurabi: and I was looking at sources to learn more about worker-stealing and choking in general.

    This IU might be a good example in your sample games of (slightly risky) high level (IMM+), permanent-war situation where there is a resource (copper) inside capital BFC owned by agressive AI (Shaka).

    I have a question about AI behavior:

    My initial worker steal was from around his 2nd city north of his capital. he had an archer guarding his town, and another archer diagonally away from the worker. I nabbed the worker but the AI did not retaliate with his city archer.

    my question is this: Is the reason that the AI did not attack random or coded? Was it that the AI will not attack from a city, that only has 1 unit garrison even if there is a high probability of winning? (worker was on FP on same side of the river). If so, that could be a good tactic - stand on a hill overseeing a city, and based on how many units are in the city, go for the worker. But what is confusing here is that the 2nd archer could have moved into the city, forming a garrison of 2. Why did shaka not attack?
     
  11. Sun Tzu Wu

    Sun Tzu Wu Chieftain Supporter

    Joined:
    Mar 26, 2007
    Messages:
    7,920
    I do believe that the lone defender of a city will ever never be used to retaliate. This might be script dependent.

    If the AI moves the other Archer into the city first, then that might release the garrison Archer to retaliate. Not sure though, as this is also script dependent.

    Very interesting question. I look forward to see tachywaxon well considered response.

    Sun Tzu Wu
     
  12. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    @vanillasine

    First, see T67-68 of this small writeup. It is a showcase of an AI neglecting the presence of an attacking unit.

    What I discovered through the many cases of worker stealing is when you kill a friendly unit with a single unit, that single unit sometimes get (for some reason I haven't found in the code yet) immunity...or better said invisibility. As if the friendly unit (the former worker) disappearance is not digested by the AI for a whole turn. I called this "bug" the sheep's clothes tactic. The small writeup showed the most extreme situation where it led to a successive worker tile near another tile and at last, that axe ended up next to the AI capital. Normally, strong units next to cities (in BTS exclusively) trigger urgent unit whippings. It didn't happened because the AI hadn't digested the second worker disappearance.

    In a similar way, it is very possible when you captured that worker from Shaka, the sheep's clothes trick happened.

    STILL, it occured to me to have a retaliation nonetheless in several occasions.
    And now I bring the concept of AI unit scripting. You see, AI units are more rigid in their behaviour than you may ever think. And archers are the most versatiles units being the host of the biggest collection of possible AI unit scripts. On default script, an Archer receives UNITAI_CITY_DEFENSE, which is I personally call the coward script. Those archers attack rarely and tend to stick in cities. IIRC, when I put those outside cities, they rush to cities ignoring enemy units (weak or not). UNITAI_ATTACK archers are the dangerous side of archers. Those ones are the retaliators. How to differentiate? Sadly, no mean except extreme experience. And still I can't differentiate them. But, I know on IMM, the three free archers the AI receive at the beginning of the game are UNITAI_CITY_DEFENSE all the time and will not change script over the game. While founding the next city, if the AI goes fast (without a second escort archer), the second city is guarded by a defensive archer full of cowardice. If the settler party comes by a pair of archer, the second is really really often a UNITAI_ATTACK archer built before the settler (btw, the IMM AI starts with a free worker).
    Anyways, unit scripting defines behaviour of the unit and priority of actions. Our coward archer will run for cities and retaliate only against weak units. Our strong attack archer will roam around the empire doing plenty of missions like escorting settlers, workers, massing for a barb city, replace killed scouts somehow, etc. It also defines the tolerance odd of attacking, which is why sometimes the archer attacks freely or is more on reserve.

    If you give me some save around that time, I may dig further.
     
  13. vanillasine

    vanillasine Chieftain

    Joined:
    Dec 26, 2007
    Messages:
    270
    I was able to recreate the exact moment that I stole the worker. From the save: Move the middle warrior onto the hill overlooking Shaka's second city to the east, and you will see the city has one archer, and the 'wandering' archer directly north of it. I move to take the worker and the wandering archer moves into the city, but the original garrisoned archer does nothing.

    Although what you say about the sheep's clothing makes sense, I'm not sure it applies here, because the AI clearly reacted to the threat by moving its archer (with UNITAI_ATTACK) towards me. (of course, maybe it was for entirely different reasons, but lets assume that it was b/c of the worker steal.

    Its looking more than likely that this is the explanation. that an archer with UNITAI_CITY_DEFENSE script either has a very high threshold on attacking from a city, or simply will never attack from a city no matter what, even if there is another archer there.

    edit:* what could also be in the script is the % of fortification of the garrisoned troop. Here, he is at full 25% fortification bonus. If it were lower, perhaps he wouldn't hesitate to attack.
     

    Attached Files:

  14. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    Ok, I'm on the case. New material to me since I didn't prolong my "voyage" into AI unit too far (it's hardcore material). I have a path of explanation of what is really happening.

    I can assure Sheeps' clothing bug is still in effect. That behaviour from that UNITAI_ATTACK archer to move back and forth is typical and I'll explain it in a minute. Need to assemble stuff...

    Also, has nothing to do with fortification.
     
  15. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    Wow, it's friggin' hard. Now, I understand why I gave up about CvUnitAI.cpp.
    It's getting late. I'll see tomorrow. I have hints, but the global AI scheme is still pretty blurred.


    RESOLVED.
     
  16. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    Ok, I was tired yesterday. Took me much less time to unravel some parts of AI coding. And myself I've learnt new stuff...very interesting stuff that can be used in practice...:devil:

    Once again, I recall that unit fortification bonuses has nothing to do with it and again, that bug I called sheep's clothing is prolly behing the AI missing an easy retaliation.

    If I DoW and land next to the city without capturing/killing any unit, then I get what is expected: a retaliation. Not from the UNITAI_ATTACK archer, but from the UNITAI_CITY_DEFENSE archer. IIRC, Sirian, one of the dev behind CIV, said that CIV AI compared to CivIII AI is less prone to let human pillage everything. Along his colleagues, AI units defending cities are implemented in such way they react to weak pillagings units, but remain behind the city walls when strong forces like stacks come along. For attacking weak unit, looking at the precise script for UNITAI_CITY_DEFENSE, leaving a city for getting rid of a weak pest is high in defense archer priorities (see the bolded function):

    Spoiler :
    Code:
    void CvUnitAI::AI_cityDefenseMove()
    {
    	PROFILE_FUNC();
    	
    	bool bDanger = (GET_PLAYER(getOwnerINLINE()).AI_getPlotDanger(plot(), 3) > 0);
    	
    	if (bDanger)
    	{
    		if ([B][U]AI_leaveAttack[/U][/B](1, 70, 175))
    		{
    			return;
    		}
    
    		if (AI_chokeDefend())
    		{
    			return;
    		}
    	}
    
    [More actions not listed here]
    


    Adding to that, Shaka has his units to be pretty courageous (unit courage; yes, it is a real parameter), thus indulging less favorable battles compared to typical AI's like Freddy, Ramesses, Hatshe, etc. My article lists unit courage btw.

    BTW, AI units actions, in the code POW, is simply a list of conditional structure read from top to bottom and according to the situation, the first corresponding to the circumstance accepted by the unit is taken and proceeded during this turns (or many turns if it happens to be a mission).

    Now, why that UNITAI_ATTACK archer moves to and fro around the city; well, I haven't found the exact explanation yet, but it seems MISSIONAI_EXPLORE (to be an explorer mission) is attributed to the archer, when given the city is needing 2 defenders, thus the attacking archer is called back.

    Indeed, the units logistics work in term of need.
    Exploration units, workers and defenders for instance, are listed in terms of needed/have. If the city needs some worker/defenders/exploration units, the city either builds them or call a nearby existing unit to do the job.

    What attracted my attention while looking at the AI shuffling its units is at some point, that UNITAI_ATTACK archer quits the city for exploration. My first instinct: the city no longer needs two minimal defenders.

    And thus comes the concept of minimum defenses in a city. In the code, the function dealing with this is CvCityAI::AI_neededDefenders() and I got interesting insights about it:

    • Minimum of base is indeed 1 defender.
    • Min # of defenders is also era dependant. Ancient AI needs only 1 defenfer in its cities and one more each era. This an AI gunning IW will move the next era faster and get its cities more defended. And by min defenses, we mean defenses that won't move out.
    • Coastal cities are a bit more defended.
    • A capital has one more defender by default.
    • Cities with an active WW will have one more defender.
    • Cities, for the first 9 turns, will have a needed min defense of the default+era#+one more to defend recent cities.
    • More conditions I won't lay down unless asked.

    What I saw, after 10 turns, that UNITAI_ATTACK was free to explore because he was no longer bound to the city needed 2 defenders since the 9 turns counter has expired.

    The capital still needed 2 min defenders for being a capital.

    So basically, that UNITAI_ATTACK archer did not return to the city because of the recent invasion of yours, but because he was bound to the city until the counter of 9 turns finished.

    I let a bunch of images to show some imagery.

    N=Needed defenders.
    The city needed two defenders to protect a recent city.

    Spoiler :


    That attack archer returns given the city needs. A: attack. D: defense.

    Spoiler :


    The 9 turns counter has expired (now 10 turns since the city foundation), thus that UNITAI_ATTACK archer is free. See, the city no longer needs 2 defenders, but only one now.

    Spoiler :



    I show you Shaka explorations. By some internal calculi, the AI deems exploration is insufficient (btw, the AI settles its cities thanks to explorations, it doesn't know the map as it has some omniscience; thus exploration is important for an impotent AI) and thus that leads that UNITAI_ATTACK archer to exploration that fog of war near us.

    Spoiler :


    The capital is nonetheless founded for over 9 turns. Why it still needs two defenders? Well, it's a capital.

    Spoiler :


    EDIT: I'll come with the pictures later. An error occured.
     
  17. vanillasine

    vanillasine Chieftain

    Joined:
    Dec 26, 2007
    Messages:
    270
    I ran a couple replays myself to see if I understood what you said correctly (please excuse if I did not):

    Shaka
    I entered world builder and essentially copied your experiments to confirm. Shaka founded his city on turn 22, and the potential worker steal happens on turn 30. on turn 32 (after 9 turns expires) he is free to do what he wants as the city, as you say, no longer needs 2 min defenders. On turn 32 he emerges from his march around the city and onto the hill my middle warrior is at and goes into explore mode.

    Shaka's archer #2 has an Attack script, and thus, while fulfilling the 'need' of the city to have 2 minimum defender, he is free to wander around (presumably 1 space away from city only -- i'll make another test where there is an attacking unit script in a cultural civ where the border would pop quicker than the 10 turns expire)


    so this 'presumably' led me to peek at other civs in this game: and there were some discrepancies (which i attempt to understand and pose a theory without looking at the code). and I naturally there are more questions than answers

    I peeked at gilgamesh and catherine specifically and found some interesting results regarding the 10 turn limit. both of them have 2 DEFENDER archers, when they found their cities with them. I wanted to know what would happen if instead they had 1 defender and one attack script archer (like shaka).

    1) catherine
    After I changed her 2nd archer to an attack script, promptly went out of the city on the 2nd turn of city's founding. to what i understood from shaka's archer, I thought catherine's archer would then go right back into the city and go back and forth until 10 turns were up. Of course the archer didn't do that -- instead it went further west onto the hill, and eventually a few turns later, it went out through moscow and began (presumably) exploring out into the SE.

    the possible explanation I have is that the city was on a peninsula, guarded by moscow, and thus did not need a second one.

    2) Gilgamesh
    this was more routine in that his 2nd archer (after i switched scripts), did what shaka's would do. until the 8th turn, when, a worker had built a road from the capital to the 2nd city, and the archer went onto the iron resource (or copper - w/e). thus also 'leaving' the 2nd city with 1 defender, but the difference being that the archer could still make it back to the city in one turn via the road.

    possible explanation is that the AI attack script has some sort of resource defending that is higher on its list than helping out with city defense. or that, fulfilling its obligation to the city defense (via the road), the resource guarding was the next one on the list (before exploration).

    what are your thoughts on this? (especially catherine)

    observations and questions:

    1) I did a test just now in world builder where I did a worker steal with a warrior in front of a city with 2 archers with defender scripts - and they didn't attack. the sheep's clothing is proven.

    I need to finish quickly now, but I wanted to pose this quick question: Do cultural civs always go with 2 defender archers to their 2nd city? what do deity archers start out as? there are many questions still, but time is short.


    Thanks for looking into this, I'm certainly learning alot about the AI. keep up the good work
     
  18. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    Feel free to ask as much questions as you desire. What I like the most are corrections, suggestions and questions. Praises come last. :)

    First, I looked the AI development in its natural form and everything went as expected.
    Some AI went settler first, escort it with 2/3 UNITAI_CITY_DEFENSE archers and once the counter of 9 turns has expired, the second archer returned to the capital because a capital is always needing 2 defenders min and the second city no longer needs a second archer for being already "enough old".

    Then, I retested with a user interaction which is forcing a script over a unit. Indeed, I noted the same behavior as you described. That archer went scout, targeted as a mission some tile in the fog and beeline there without thinking anything else or revoking the mission. I wonder if this is not the problem; the user involvement pushed an mission regardless of the cities needs. As I said, I still haven't found why those UNITAI_ATTACK arches move to and fro with missions oscillating between MISSIONAI_EXPLORE and MISSIONAI_GUARD_CITY. Nevertheless, if you don't impose/overwrite over an AI unit initial script, you'll have the regular behaviour without flaw. Possibly you broke some hidden links not shown in the debugger with the overwrite action.

    Sadly, you are conferring some intelligent logistics to the AI; in fact, they have none. What you have said is too advanced for an AI as CIV one and needs consideration of the map and such.
    Still, it is in the code that coastal cities are supposed to be defended more than inland cities but I think the modified min defender # is affected starting some era later. I'm pretty that was some implementation to circumvent a bit amphibious attacks.

    Was there a worker working the iron plot? If so, then the UNITAI_ATTACK archer went in AI_defend() mode, which is escorting worker. Still, that task is really really low in the list. I think again by overwriting, you broke some hidden links that archer had with something I can't yet ponder. I'm sure such behaviour won't be seen in a normal AI development.

    IIRC, the the function for defending resources is matter of the UNITAI_CITY_DEFENSE, not the UNITAI_ATTACK script. And those units will guard forts, not bonuses.

    Spoiler :
    Code:
    if ((AI_getBirthmark() % 4) == 0)
    	{
    		if (AI_guardFort())
    		{
    			return;
    		}
    	}


    That thing about birthmark is simply a randomly given number associated to certain units and those units once having no other priority will be tasked to guard forts. Units without birthmark will never do this job.
    Then, why defending forts in a city defense script: forts are viewed as mini-cities by the game.

    Traits have nothing to do with such AI behaviours. As explained in the first test of normal AI developments, the AI will escort their first settler (mainly seen when the AI starts with a settler since T0) with 2 out of 3 archers. After 9 turns, then next turn, the archer will rejoin the cap since the cap needs 2 defenders.

    Deity player over there? :) 4 UNITAI_CITY_DEFENSE archers.
    2 will remain in the capital and the two others follow the second settler (as in the settler is the commanding unit and the archers just follow; that's why those archers never attack; they behave just like lemmings).
     
  19. Manco Capac

    Manco Capac Friday,13 June,I Collapse

    Joined:
    Mar 1, 2010
    Messages:
    8,051
    General comment and observation of mine:

    Sheep's clothing is a trick a named upon finding working stealing often leads to no retaliation.
    But games after games, I was starting to think there is no such real trick. Recently, I came upon realization that the lack of retaliation must comes from the fact UNITAI_CITY_DEFENSE archers somehow for one turn considers the attacking enslaver (could be a warrior of ours) is a worker and a universal rule about UNITAI_CITY_DEFENSE script is to ignore workers altogether. Always. Scouts too.

    Then I changed to a UNITAI_ATTACK archer in a capital and now two archers: no retaliation. I scratched my head.
    Then I added a second UNITAI_CITY_DEFENSE archer and the UNITAI_ATTACK archer decided to attack. Now I realize it must have to do with minimum defender script where a capital always needs two defenders and when there were three, the UNITAI_ATTACK archer was free to attack. That explains those random weird retaliations I've seen in the past.

    Same for new founded cities needed 2 min defenders. A count of 10 turns before the new city returns to min 1. I guess at that point, UNITAI_ATTACK archer would attack.

    So, there isn't such real sheep's clothing trick except for UNITAI_CITY_DEFENSE archers.

    In fact, globally, it's a combination of two circumstances: unit script and "min defenders" function in a city (which indeed is circumstancial).
    Also, beware of those roaming archers around capital square as those tend to go in retaliation mode after snatching workers. Worker stealing has indeed its deal of risk.
     
  20. cseanny

    cseanny Chieftain

    Joined:
    Apr 3, 2008
    Messages:
    1,191
    @ Tachy

    Just a general comment or question rather. I've been trying to learn a bit more about rules and XML in general but tbh, it's all pretty damn confusing to me lol. Code, math, etc, are just not my cup of tea. It's why I play so damn slow....and I still have bad math/results.

    Can you direct me to a link or something that allows a person to learn about these things? Another useful tool would be how does one look into the code/XML actions already taken place (from a random save point in a game), I.E., anything to do with how much gold we have turn by turn, or unit actions, such as building improvements, etc etc. That should make it easier to identify or rather, locate specific points in a game and meddle with what you (or I in this case) were looking for....whatever that may be lol.
     

Share This Page