Python RandPlot error

Joined
Sep 15, 2006
Messages
511
I've been using this line of code to generate random plots

Code:
CyMap().syncRandPlot( (1 | 5 | 6), area, 10, 9999)

However its been causing infinite loops. At 10 it nearly inf loops every time, and at 8 it loops occasionally. However there is space fufiling the requirements that I can see using the world builder. Any suggestions on avoiding the inf loop and keeping my units 10 spaces apart without making my own rand plot generator?
 
I've been using this line of code to generate random plots

Code:
CyMap().syncRandPlot( (1 | 5 | 6), area, 10, 9999)

However its been causing infinite loops. At 10 it nearly inf loops every time, and at 8 it loops occasionally. However there is space fufiling the requirements that I can see using the world builder. Any suggestions on avoiding the inf loop and keeping my units 10 spaces apart without making my own rand plot generator?

I havent used that function before, so Im just guessing. But what happens if you decrease the timeout from 9999 to something like 10?
 
Haven't tried that I will later, thanks Kael.

However, in my experiments I've found that every time I raise the iMinUnitDistance to above 6 it changes the turn time length noticeably (5-8 seconds). I'm guessing this function is recursive. That would also explain why I couldn't break out of it using ctrl-alt-del. I set it to 6 and it works how I would like it to..
 
I've just took a look at this function by curiosity . There is no possible infinite loop ... but just a lot of calculation . If you take in count that you're on a big area , and that the process take a random plot , then check if in a good area . I think this is not easy to adjust settings . Especially if there is already a lot of unit on the map . Perhaps rewrite in python , make a list of available plots and choose one should be very quick if you want a big iMinUnitDistance !

Spoiler :
Code:
CvPlot* CvMap::syncRandPlot(int iFlags, int iArea, int iMinUnitDistance, int iTimeout)
{
	CvPlot* pPlot;
	CvPlot* pTestPlot;
	CvPlot* pLoopPlot;
	bool bValid;
	int iCount;
	int iDX, iDY;

	pPlot = NULL;

	iCount = 0;

	while (iCount < iTimeout)
	{
		pTestPlot = plotSorenINLINE(GC.getGameINLINE().getSorenRandNum(getGridWidthINLINE(), "Rand Plot Width"), GC.getGameINLINE().getSorenRandNum(getGridHeightINLINE(), "Rand Plot Height"));

		FAssertMsg(pTestPlot != NULL, "TestPlot is not assigned a valid value");

		if ((iArea == -1) || (pTestPlot->getArea() == iArea))
		{
			bValid = true;

			if (bValid)
			{
				if (iMinUnitDistance != -1)
				{
					for (iDX = -(iMinUnitDistance); iDX <= iMinUnitDistance; iDX++)
					{
						for (iDY = -(iMinUnitDistance); iDY <= iMinUnitDistance; iDY++)
						{
							pLoopPlot	= plotXY(pTestPlot->getX_INLINE(), pTestPlot->getY_INLINE(), iDX, iDY);

							if (pLoopPlot != NULL)
							{
								if (pLoopPlot->isUnit())
								{
									bValid = false;
								}
							}
						}
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_LAND)
				{
					if (pTestPlot->isWater())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_UNOWNED)
				{
					if (pTestPlot->isOwned())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_ADJACENT_UNOWNED)
				{
					if (pTestPlot->isAdjacentOwned())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_ADJACENT_LAND)
				{
					if (!(pTestPlot->isAdjacentToLand()))
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_PASSIBLE)
				{
					if (pTestPlot->isImpassable())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_NOT_VISIBLE_TO_CIV)
				{
					if (pTestPlot->isVisibleToCivTeam())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				if (iFlags & RANDPLOT_NOT_CITY)
				{
					if (pTestPlot->isCity())
					{
						bValid = false;
					}
				}
			}

			if (bValid)
			{
				pPlot = pTestPlot;
				break;
			}
		}

		iCount++;
	}

	return pPlot;
}

Hope this help you to adjust settings .

Tcho !
 
lol if iMinUnitDistance = 10 thats 21^2 loops per tile.

Anyways just a thought wouldn't it make sense to first check to see if the plot is valid before going through all those loops?

I'll have to edit that and recompile looks like it could make a big difference in the game starting speed.
 
Back
Top Bottom