[1.61 & Warlords] Small AI cheat in SDK

The Great Apple

Big Cheese
Joined
Mar 24, 2002
Messages
3,361
Location
Oxford, England
CvPlayerAI::AI_getPlotDanger(...) scans plots to check for danger. As far as I can tell it does not check to see if the plot is visible to the AI or not. I've ran a few tests manually setting the scan range to 50 and it seems to pick up on barb units which are well out of sight distance.

The net result of this is that the AI will be able to tell that a plot is dangerous despite not being able to see the plot

Suggested fix:
Spoiler Altered code :

Code:
int CvPlayerAI::AI_getPlotDanger(CvPlot* pPlot, int iRange, bool bTestMoves)
{
	PROFILE_FUNC();

	CLLNode<IDInfo>* pUnitNode;
	CvUnit* pLoopUnit;
	CvPlot* pLoopPlot;
	int iCount;
	int iDX, iDY;

	iCount = 0;

	if (iRange == -1)
	{
		iRange = DANGER_RANGE;
	}

	for (iDX = -(iRange); iDX <= iRange; iDX++)
	{
		for (iDY = -(iRange); iDY <= iRange; iDY++)
		{
			pLoopPlot	= plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iDX, iDY);

			if (pLoopPlot != NULL)
			{
[b]// START - TGA | Fixing AI cheat | 2 September 2006
				if (pLoopPlot->isVisible(getTeam(), false))
				{	
// END - TGA | Fixing AI cheat | 2 September 2006[/B]
					if (pLoopPlot->area() == pPlot->area())
					{
						pUnitNode = pLoopPlot->headUnitNode();

						while (pUnitNode != NULL)
						{
							pLoopUnit = ::getUnit(pUnitNode->m_data);
							pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);

							if (atWar(pLoopUnit->getTeam(), getTeam()))
							{
								if (pLoopUnit->canAttack())
								{
									if (!(pLoopUnit->isInvisible(getTeam(), false)))
									{
										if (!bTestMoves || pLoopPlot->isValidRoute(pLoopUnit) || ((pLoopUnit->baseMoves() + ((!(pLoopUnit->isAnimal())) ? getAIVar(105) : 0) + ((pLoopUnit->isHuman()) ? 1 : 0)) >= stepDistance(pPlot->getX_INLINE(), pPlot->getY_INLINE(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()))) // TGA | AutoGenFunction | v0.02 | 24 August 2006
	 									{
											iCount++;
										}
									}
								}
							}
						}
					}
[B]// START - TGA | Fixing AI cheat | 2 September 2006
				}
// END - TGA | Fixing AI cheat | 2 September 2006[/B]
			}
		}
	}
	
	return iCount;
}
 
A human player is able to see a plot which is fogged out and know that an enemy unit might be there.

If this 'bug' is fixed, it would cause the AIs to play stupider, being more susceptible to attacking out of the fog.

The purist may not like that the AI cheats here, but for gameplay, it seems like it is better for the AI to cheat a bit than to play stupid.

-Iustus
 
True. Alternatively the algorithm could be improved to account for unknown plots in some way.

I personally think that the AI should not cheat at all. The handicaps are alright, but the AI should have to work on exactly the same information that the player does during the game. It was one of my main problems with Civ 3 - one of the more obvious cheats in Civ 3 was that the AI would found cities near resources that were yet to become revealed... which is just silly.
 
Back
Top Bottom