Espionage AI

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
One of the areas the AI tends to be weakest is espionage. Espionage is the sort of gameplay mechanic a decentralized AI is poorest at. Espionage requires large amounts of pre-planning, a large amount of coordination between units and cities, and long timespans. The Civilization AI is largely decentralized, which means that each turn, units and cities make decisions mostly independent of each other, deciding the best particular action each turn (or a few turns a head of time). The AI doesn't think 50 or 100 turns in advance.

Espionage with the AI appears schizophrenic because the AI doesn't really have a plan. It's pretty easy to exploit the AI's weak espionage defenses, and the AI's espionage attacks feel very artificial (destroying the same exact resource/building over and over).

I'm working on a new Espionage Plan system, which will let the AI focus on a specific espionage plan and cities will build appropriate numbers of spies, and spies will focus on particular roles (defensive / offensive).

Espionage AI Plans:

  • None (No Espionage / Has Met No Players)
  • Defensive (1 spy per 6 pop+ city (or capital), don't engage other players in missions)
  • Disruptive (Peacetime, attacks your growth via poison/unhappiness/revolts/research)
  • Offensive (Wartime, attacks military resources, military buildings, crucial military production cities)
  • Offensive Preparation (Warplanning, plants nukes or bribes cities as a way of hurting you right before a war declaration)
  • Financial (Steals your gold to cover financial troubles)

I also included a plan for stealing techs, but a espionage tech strategy is a bit too complicated for the AI, at least right now.

I'm hoping to get the AI to shore up defenses initially. I want them to stick spies in their own cities and reliably guard their cities and give their defensive spies counter-espionage promotions.

Once I have that working, I will try and implement the more offensive AI plans.
 
Sheesh. That lot sounds scary!
 
:devil: Go for it!

Hopefully, that'll give you practical experience to increase centralization of AI relating other important aspects of the game.
Hopefully.
 
It seems a great advance to the AI. I liked it.


BTW, once I've read a tip saying that the AI will be fiercer using espionage if the human uses against it first, as to not enrage players who almost never use spies for anything. Are you going to keep this true or remove this completely? IMO I think it should be kept (if you're not aware of espionage, it can be a big load of frustration, especially with a flip city mission).
 
I'm hoping to get the AI to shore up defenses initially. I want them to stick spies in their own cities and reliably guard their cities and give their defensive spies counter-espionage promotions.

I always had this question:can you use spies as counter-espionage?I play Civ4 for 7 years and I haven't still confirmed if it works.:confused:
 
I always had this question:can you use spies as counter-espionage?I play Civ4 for 7 years and I haven't still confirmed if it works.:confused:

Absolutely. If you keep a spy stationed in one of the cities you own, it increases the chance of detecting any enemy spy action in the city. The exact amount it helps is in the GlobalDefines.XML, "ESPIONAGE_INTERCEPT_COUNTERSPY". It increases the chances of catching an enemy spy by 15%. That is a lot (considering mission successes usually are between 40-80 percent, decreasing those odds by 15% makes them much more likely to fail). Counter-espionage promotions can increase the chances of catching an enemy spy even further.

BTW, once I've read a tip saying that the AI will be fiercer using espionage if the human uses against it first, as to not enrage players who almost never use spies for anything. Are you going to keep this true or remove this completely? IMO I think it should be kept (if you're not aware of espionage, it can be a big load of frustration, especially with a flip city mission).

I see no reason the AI should not engage in spying, even if the human player is not. If a human player doesn't want spying, they can turn off the game option. The AI should use every tactic to their best ability.
 
If they don't start using their incredible numbers against you in a way that makes the game impossible to play, then I'm ok with it. But I liked that insight from vanilla BtS. Anyway, it's useless to me as I use espionage a lot on my games, so carry on.
 
If they don't start using their incredible numbers against you in a way that makes the game impossible to play, then I'm ok with it. But I liked that insight from vanilla BtS. Anyway, it's useless to me as I use espionage a lot on my games, so carry on.

Here's the code the AI Player will use to determine it's espionage plan"

Spoiler :
Code:
void CvPlayerAI::AI_updateEspionagePlan()
{
	if (GC.getGameINLINE().isOption(GAMEOPTION_NO_ESPIONAGE))
	{
		return;
	}

	bool bMetAnyone = false;
	for (int iI = 0; iI < MAX_TEAMS; iI++)
	{
		if (iI != getTeam() && GET_TEAM(getTeam()).isHasMet((TeamTypes)iI))
		{
			bMetAnyone = true;
			break;
		}
	}
	if (!bMetAnyone)
	{
		m_eEspionagePlan = NO_ESPIONAGE_PLAN;
		return;
	}

	if (AI_isFinancialTrouble())
	{
		for (int iI = 0; iI < MAX_PLAYERS; iI++)
		{
			if (iI != getID() && GET_PLAYER((PlayerTypes)iI).isAlive() && GET_TEAM(getTeam()).isHasMet(GET_PLAYER((PlayerTypes)iI).getTeam()))
			{
				if (GET_PLAYER((PlayerTypes)iI).getGold() > (250 + (100 * GET_PLAYER((PlayerTypes)iI).getNumCities())))
				{
					m_eEspionagePlan = ESPIONAGE_FINANCIAL;
					return;
				}
			}
		}
		m_eEspionagePlan = ESPIONAGE_DEFENSIVE;
		return;
	}

	bool bAtWarWithAny = false;
	for (int iI = 0; iI < MAX_TEAMS; iI++)
	{
		if (iI != getTeam() && GET_TEAM(getTeam()).isAtWar((TeamTypes)iI))
		{
			bAtWarWithAny = true;

			int iTheirSuccess = std::max(10, GET_TEAM((TeamTypes)iI).AI_getWarSuccess(getTeam()));
			int iOurSuccess = std::max(10, GET_TEAM(getTeam()).AI_getWarSuccess((TeamTypes)iI));
			if (iTheirSuccess * 2 < iOurSuccess * 3)
			{
				m_eEspionagePlan = ESPIONAGE_OFFENSIVE;
				return;
			}
		}
	}
	if (bAtWarWithAny)
	{
		m_eEspionagePlan = ESPIONAGE_DEFENSIVE;
		return;
	}

	for (int iI = 0; iI < MAX_TEAMS; iI++)
	{
		if (iI != getTeam() && GET_TEAM(getTeam()).AI_getWarPlan((TeamTypes)iI) != NO_WARPLAN)
		{
			m_eEspionagePlan = ESPIONAGE_PREPARE_OFFENSIVE;
			return;
		}
	}

	if (GC.getLeaderHeadInfo(getLeaderType()).getWarmongerRespect() >= 2 || GC.getGameINLINE().isOption(GAMEOPTION_RUTHLESS_AI))
	{
		m_eEspionagePlan = ESPIONAGE_DISRUPTIVE;
	}
	else
	{
		m_eEspionagePlan = ESPIONAGE_DEFENSIVE;
	}
}

If you can't read C++, I'll break it down right here.

  1. If the AI has not met any players, or espionage is disabled as a game option, logic stops.
  2. If the AI is in financial trouble and has met a player that has more than 250 gold + 100 gold per city in their treasury (so a 6 city player would need to have 850 gold), switch to the financial espionage plan. This plan causes the AI to steal money. The reason for the variable amount of gold is that the amount of money you steal from a city treasury decreases based on the total empire size, so you can steal more money from larger cities and smaller empires.
  3. If the AI is at war with anyone and its winning the war, use an offensive espionage plan.
  4. If the AI is at war with anyone, and not winning the war, use a defensive espionage plan.
  5. If the AI is planning a war, use the offensive preparation plan.
  6. If the AI is a warmonger (think montezuma) or ruthless AI is enabled, use the disruptive espionage plan.
  7. Use the defensive espionage plan.

This is a branching pattern here, so the first condition that is true stops the logic. If none of the conditions are true, it uses a defensive plan.

So players should expect to be harrassed: If they are at war, if the AI is planning war, or they use ruthless AI, or the AI is a warmongerer. It's a pretty reasonable stratagem for the AI. Otherwise the AI will just use espionage in a purely defensive manner.
 
What about the war winning logic??

what I mean is, if the AI gets a 'cheap kill' it suddenly thinks "hey, I'm winning this war", but in fact, it is out gunned 2/1 or more and has no offensive capabilities.

Or is this just a fix and see how it goes, as the war winning logic maybe too much to recode??
 
What about the war winning logic??

what I mean is, if the AI gets a 'cheap kill' it suddenly thinks "hey, I'm winning this war", but in fact, it is out gunned 2/1 or more and has no offensive capabilities.

Or is this just a fix and see how it goes, as the war winning logic maybe too much to recode??

It's the same logic used pretty much elsewhere by the AI. When it kills a unit or captures a city, it adds 4 or 10 points to the "war success" variable for that player. When it loses a unit or loses a city, it adds that much to the "war success" for the enemy player. So you compare the "war success" of each player, and see which is higher.

So yes, if the AI gets a couple early kills, and loses no units, it thinks it is winning. But as soon as it starts to lose units, it will change its mind.

Good question BTW. If you don't understand anything else about the AI, do ask.
 
One of the areas the AI tends to be weakest is espionage. Espionage is the sort of gameplay mechanic a decentralized AI is poorest at. Espionage requires large amounts of pre-planning, a large amount of coordination between units and cities, and long timespans. The Civilization AI is largely decentralized, which means that each turn, units and cities make decisions mostly independent of each other, deciding the best particular action each turn (or a few turns a head of time). The AI doesn't think 50 or 100 turns in advance.

Espionage with the AI appears schizophrenic because the AI doesn't really have a plan. It's pretty easy to exploit the AI's weak espionage defenses, and the AI's espionage attacks feel very artificial (destroying the same exact resource/building over and over).

I'm working on a new Espionage Plan system, which will let the AI focus on a specific espionage plan and cities will build appropriate numbers of spies, and spies will focus on particular roles (defensive / offensive).

Espionage AI Plans:

  • None (No Espionage / Has Met No Players)
  • Defensive (1 spy per 6 pop+ city (or capital), don't engage other players in missions)
  • Disruptive (Peacetime, attacks your growth via poison/unhappiness/revolts/research)
  • Offensive (Wartime, attacks military resources, military buildings, crucial military production cities)
  • Offensive Preparation (Warplanning, plants nukes or bribes cities as a way of hurting you right before a war declaration)
  • Financial (Steals your gold to cover financial troubles)

I also included a plan for stealing techs, but a espionage tech strategy is a bit too complicated for the AI, at least right now.

I'm hoping to get the AI to shore up defenses initially. I want them to stick spies in their own cities and reliably guard their cities and give their defensive spies counter-espionage promotions.

Once I have that working, I will try and implement the more offensive AI plans.

Sounds awesome!
 
Top Bottom