Can I find AI decision making in BTS?

HawkEyes

Chieftain
Joined
Sep 29, 2016
Messages
8
Hey, I'm not very technical with technology, I started playing Civ 4 beyond the sword (all expansions, no mods) a couple of weeks ago after not playing it for a long time, and I like to play on the hardest difficulty setting.

I would really like to know how the AI make their decisions because on Deity, I like to start a game, save it, then play, then load from save point and use world map maker to see how the AI would control the nation I was playing as and I'm all ways in awe about how they choose better than me.

I feel like if I could see this decision module for my self I too would be a lot better at Civilasation4. The closest I've got is looking around in vein in XML files and non readable better AI mod.


Also I came across something called black board AI looking on the internet but that didn't help me in the long run.

EDIT: I spawn in Great Spies as the other nation to spy on original nation
 
If the AI does a better job at managing your empire than you then you have a problem ;)

On Deity, the AI does well because it gets huge bonuses to production and research. But its decision making is for the biggest part done randomly. It chooses randomly what to research and what to build, it chooses randomly how to vote on an AP resolution or when to go to war (within a certain framework of course, but still). An AI will never choose to chop out the Pyramids because it has a capital with a lot of food. It is very bad at choosing good improvements for terrain, it doesn't nearly whip or chop enough.

If you really want to learn how to manage your empire better, I would rather learn from a few select player on this forum ;)
 
GJ is right. The AI decision making is based on coding and randomness. The good human player will always be better. I would not look to the AI for advice on how to play. That can be found in the Strateg & Tips forum, research, Let's play's, and practice, ofc.

However, it does pay to understand how the AIs make certain decisions. Doing so will improve your play and enable you to make informed decisions and strategies.

Some time ago, a member put together a spreadsheet that extrapolated the coding behind the AI. However, more recently this data was translated into a more easily understood strategy article which can be found here:

Know thy enemy

As for why "AI's choose better" than you currently, I simply chalk that up to inexperience. The AI otherwise make a lot of bad decisions. As GJ mentioned, on higher levels they get larger bonuses to the human which is where much of the difficulty comes from.

The AI generally makes a lot of rather consistent decisions about things like teching and worker management/tile improvements. Understanding things like this help you to make better decisions. Like the AI almost always prioritizes certain techs like religious, Iron Working, Maths, Feudalism, Machinery, Engineering, etc.
 
^^^^^
And you can always automate your workers and use Governors to get a flavor for how the AI does things. (hint: you won't be impressed)
 
The AI values :
1 :food: = 2 :hammers: = 3 :commerce:

(I believe ?) That's probably the best thing to take from their decision process.

There's never one right conversion ratio and if there were, it would be situation & objective dependent...
... but that equation has got the hierarchy right enough to make it a rule of thumb.
 
Code:
#pragma once

#ifndef AI_DEFINES_H
#define AI_DEFINES_H

#define DEFAULT_PLAYER_CLOSENESS 6
#define AI_DAGGER_THRESHOLD            100  //higher is a lower chance

#define AI_DEFAULT_STRATEGY             (1 << 0)
#define AI_STRATEGY_DAGGER              (1 << 1)
#define AI_STRATEGY_SLEDGEHAMMER        (1 << 2)
#define AI_STRATEGY_CASTLE              (1 << 3)
#define AI_STRATEGY_FASTMOVERS          (1 << 4)
#define AI_STRATEGY_SLOWMOVERS          (1 << 5)
#define AI_STRATEGY_CULTURE1            (1 << 6)  //religions and wonders
#define AI_STRATEGY_CULTURE2            (1 << 7)  //mass culture buildings
#define AI_STRATEGY_CULTURE3            (1 << 8)  //culture slider
#define AI_STRATEGY_CULTURE4            (1 << 9)
#define AI_STRATEGY_MISSIONARY          (1 << 10)
#define AI_STRATEGY_CRUSH                (1 << 11)  //convert units to City Attack
#define AI_STRATEGY_PRODUCTION          (1 << 12)
#define AI_STRATEGY_PEACE                (1 << 13)  //lucky... neglect defenses.
#define AI_STRATEGY_GET_BETTER_UNITS    (1 << 14)
#define AI_STRATEGY_LAND_BLITZ            (1 << 15)
#define AI_STRATEGY_AIR_BLITZ            (1 << 16)
#define AI_STRATEGY_LAST_STAND            (1 << 17)
#define AI_STRATEGY_FINAL_WAR            (1 << 18)
#define AI_STRATEGY_OWABWNW                (1 << 19)
#define AI_STRATEGY_BIG_ESPIONAGE        (1 << 20)


#define AI_CITY_ROLE_VALID              (1 <<  1)    //zero is bad
#define AI_CITY_ROLE_BIG_CULTURE        (1 <<  2)    //culture victory, probably
#define AI_CITY_ROLE_BIG_PRODUCTION     (1 <<  3)    //don't build girly NW's
#define AI_CITY_ROLE_BIG_MILITARY       (1 <<  4)    //stick with military stuff
#define AI_CITY_ROLE_SCIENCE            (1 <<  5)    //
#define AI_CITY_ROLE_GOLD               (1 <<  6)    //
#define AI_CITY_ROLE_PRODUCTION         (1 <<  7)    //
#define AI_CITY_ROLE_SPECIALIST         (1 <<  8)    //
#define AI_CITY_ROLE_FISHING            (1 <<  9)   //
#define AI_CITY_ROLE_STAGING            (1 << 10)    //send troops here
#define AI_CITY_ROLE_LICHPIN            (1 << 11)    //this city must not fall

#endif // AI_DEFINES_H


I found this in C:\Program Files (x86)\2K Games\Firaxis Games\Sid Meier's Civilization 4 Complete\Beyond the Sword\CvGameCoreDLL

Edit: Also in my latest game of Civ4 with the AI set to Deity, Babylonia had the Destroyer Navy Battle Ship with strength 30 in 1540AD!
 
^ I do not know what you would make of that.

The AI doesn't get excellent results on Deity diff because of its intelligence but because it gets massive bonuses/discounts in each and every field.
The AI acts based on flavour and RNG. No planning, no real will to win, very limited understanding of the map --> no strategy. One shouldn't aim to replicate their build & tech orders.
Deity AIs are like aimless wanderers on steroids : dumb & dangerous.

Their evaluation of food, hammers & commerce, however, can help a player choose how to improve and work the land. This is not a question of strategy but rather of management.
(Parenthesis : If Civ4 is such a good game, it is in a large part because the balance between food, hammers and commerce is very sound. The game is very much about converting these 3 basic resources into each other and it is very well balanced at that.
It's the sound basis that ulterior Civ games would lack.)
Their workers road way over the top and keep swapping cottage for farm for cottage for workshop for cottage for farm for cottage for whatever is not cottage for, etc. but looking at the spread of workers can, maybe, give an idea of what should be.

Overall, though... better look at guides for humans, how to set up an early base and so on.


If you really want to see how the AI plays, compared with a human, you need to set the game's difficulty to Noble.
That way, the AI is neither advantaged, nor does it receive a handicap. They play with the same rules as you do.
If you can beat Noble, you're already better than they are. If you can't beat Noble, well, surely you can improve...
 
Last edited:
Code:
#define BUILDINGFOCUS_FOOD                    (1 << 1)
#define BUILDINGFOCUS_PRODUCTION            (1 << 2)
#define BUILDINGFOCUS_GOLD                    (1 << 3)
#define BUILDINGFOCUS_RESEARCH                (1 << 4)
#define BUILDINGFOCUS_CULTURE                (1 << 5)
#define BUILDINGFOCUS_DEFENSE                (1 << 6)
#define BUILDINGFOCUS_HAPPY                    (1 << 7)
#define BUILDINGFOCUS_HEALTHY                (1 << 8)
#define BUILDINGFOCUS_EXPERIENCE            (1 << 9)
#define BUILDINGFOCUS_MAINTENANCE            (1 << 10)
#define BUILDINGFOCUS_SPECIALIST            (1 << 11)
#define BUILDINGFOCUS_ESPIONAGE                (1 << 12)
#define BUILDINGFOCUS_BIGCULTURE            (1 << 13)
#define BUILDINGFOCUS_WORLDWONDER            (1 << 14)
#define BUILDINGFOCUS_DOMAINSEA                (1 << 15)
#define BUILDINGFOCUS_WONDEROK                (1 << 16)
#define BUILDINGFOCUS_CAPITAL                (1 << 17)

Found this in CvCityAI, I would like to know where technology choices are held, just played another Civ4 AI Deity game, ha ha ha one of them won the Space Race in 1820AD

I am aware they have bonuses and am now aware thanks to your posts that they have flavours and RNG behind their decision making, but I really want to see the code that makes them make these choices.

Forget the strategies, all I want is just the AI's, what to build and what to research code. You are right it's probably better learning from other players but after all I'm just doing this for fun.
 
Tech choices are in CvPlayerAI. I'm sure the build choices are in there too. It appears the part of the code that is used to determine best tech is too long to paste into one post at these forums.
 
:D Thank you, this is the jackpot. Like I said in my first post, I'm digitally naïve. Going on Control find and typing // is finding me lots of interesting things.
 
Me saying I'm "in awe of AIs decision making" (which I still am in comparison to my decision making) probably didn't help clear things up. But you did help, I was aware of AI bonuses but I hadn't heard of discounts before amongst other things.
 
Top Bottom