For example, when choosing beliefs, the AI weighs all available beliefs and scores them based on hundreds of variables (yields, synergies, grandstrategy links, policies, relationships, angry neighbors, etc. etc.). Once totaled, the AI ranks them based on weight and chooses from them. At Deity, they always choose the highest-weighted entity. At lower difficulties, they'll choose randomly from the top x (2, 3, 4).
For the record, this has been a huge task on my part. Formerly these were all decided by flavors. If the AI was FLAVOR_NAVAL 10, they would choose all naval things they could regardless of whatever they were doing/needed/stuck in. Land-locked v. Shaka and behind in science? Let me continue to obsess with naval techs and naval-related policies. Stupid AI. Not anymore. Flavors are about 10% of AI logic now (used to be 100%).
They do this for techs, policies, beliefs, buildings, units, wonders, opinions, war desirability, and ideologies.
G