Ejemplo n.º 1
0
void GenerateTopology (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j, k;

	int iCount = pCmdLine->GetAttributeIntegerBounded(COUNT_SWITCH, 1, -1, 1);

	STopologyStats Stats;

	for (k = 0; k < iCount; k++)
		{
		if (iCount > 1)
			printf("sample %d", k+1);

		TSortMap<CString, SNodeInfo> NodeData;
		TSortMap<CString, int> AttribCount;

		//	Initialize the topology

		CString sError;
		Universe.GetFirstTopologyNode();

		//	Loop over all nodes

		for (i = 0; i < Universe.GetTopologyNodeCount(); i++)
			{
			CTopologyNode *pNode = Universe.GetTopologyNode(i);

			SNodeInfo *pNewNode = NodeData.Insert(pNode->GetID());
			pNewNode->sID = pNode->GetID();
			pNewNode->sName = pNode->GetSystemName();
			pNewNode->dwSystemUNID = pNode->GetSystemDescUNID();
			pNewNode->sAttribs = pNode->GetAttributes();

			//	Add the attributes in this node to the list of 
			//	attributes for this try.

			TArray<CString> Attribs;
			ParseAttributes(pNewNode->sAttribs, &Attribs);
			for (j = 0; j < Attribs.GetCount(); j++)
				{
				int *pCount = AttribCount.GetAt(Attribs[j]);
				if (pCount == NULL)
					{
					pCount = AttribCount.Insert(Attribs[j]);
					*pCount = 0;
					}

				*pCount = (*pCount) + 1;
				}
			}

		//	Compute topology stats
		//	Add the node count for this try

		Stats.NodeCount.Insert(NodeData.GetCount());

		//	Loop over all attributes that we know about. If one doesn't
		//	exist in this try, then we set its min to 0

		if (k > 0)
			{
			for (i = 0; i < Stats.Attribs.GetCount(); i++)
				{
				if (AttribCount.GetAt(Stats.Attribs.GetKey(i)) == NULL)
					Stats.Attribs[i].SetMin(0);
				}
			}

		//	Loop over all attributes in this try and add them to the stats

		SStat *pAttribStat;
		for (i = 0; i < AttribCount.GetCount(); i++)
			{
			//	If we have some attributes that no other try had, then
			//	that means that the minimum value is 0.

			if (pAttribStat = Stats.Attribs.GetAt(AttribCount.GetKey(i)))
				pAttribStat->Insert(AttribCount[i]);
			else
				{
				pAttribStat = Stats.Attribs.Insert(AttribCount.GetKey(i));
				pAttribStat->Insert(AttribCount[i]);
				if (k > 0)
					pAttribStat->SetMin(0);
				}
			}

		//	Output all the nodes

		if (iCount == 1)
			{
			printf("Node\tSystemType\tName\tStargates\tAttributes\n");
			for (i = 0; i < NodeData.GetCount(); i++)
				{
				SNodeInfo *pNode = &NodeData.GetValue(i);
				printf("%s\t%08x\t%s\t%d\t%s\n",
						pNode->sID.GetASCIIZPointer(),
						pNode->dwSystemUNID,
						pNode->sName.GetASCIIZPointer(),
						pNode->Stargates.GetCount(),
						pNode->sAttribs.GetASCIIZPointer());
				}
			}
		else
			{
			Universe.Reinit();
			printf("\n");
			}
		}

	//	Output stats

	if (iCount > 0)
		{
		printf("\n");
		printf("STATS\n\n");
		Stats.NodeCount.Print(CONSTLIT("Nodes"), iCount, Stats.NodeCount.GetAverage(iCount));
		printf("\n");

		printf("ATTRIBS\n\n");
		for (i = 0; i < Stats.Attribs.GetCount(); i++)
			Stats.Attribs[i].Print(Stats.Attribs.GetKey(i), iCount, Stats.NodeCount.GetAverage(iCount));
		printf("\n");
		}
	}
Ejemplo n.º 2
0
void GenerateSystemLabelCount (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	ALERROR error;
	int i, j;
	CString sError;

	enum STypes
		{
		typeSystemLabels,
		typeNodeAttributes,
		typeNodeDebug,
		};

	//	Figure out what kind of output we want

	STypes iType;
	if (pCmdLine->GetAttributeBool(CONSTLIT("nodes")))
		iType = typeNodeAttributes;
	else if (pCmdLine->GetAttributeBool(CONSTLIT("nodeDebug")))
		iType = typeNodeDebug;
	else
		iType = typeSystemLabels;

	//	Samples

	int iSystemSample = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("count"), 1, -1, 1);

	//	Options

	bool bPermutations = pCmdLine->GetAttributeBool(CONSTLIT("permutations"));

	//	Generate systems for multiple games

	CSystemCreateStats Stats;
	Stats.AddPermuteAttrib(CONSTLIT("asteroids"));
	Stats.AddPermuteAttrib(CONSTLIT("planetary"));
	Stats.AddPermuteAttrib(CONSTLIT("void"));
	Stats.AddPermuteAttrib(CONSTLIT("innerSystem"));
	Stats.AddPermuteAttrib(CONSTLIT("lifeZone"));
	Stats.AddPermuteAttrib(CONSTLIT("outerSystem"));
	Stats.AddPermuteAttrib(CONSTLIT("envAir"));
	Stats.AddPermuteAttrib(CONSTLIT("envEarth"));
	Stats.AddPermuteAttrib(CONSTLIT("envFire"));
	Stats.AddPermuteAttrib(CONSTLIT("envWater"));
	bPermutations = true;

	for (i = 0; i < iSystemSample; i++)
		{
		printf("pass %d...\n", i+1);

		//	Initialize the universe

		if (error = Universe.InitGame(0, &sError))
			{
			printf("ERROR: %s", sError.GetASCIIZPointer());
			return;
			}

		//	Loop over all topology nodes

		for (j = 0; j < Universe.GetTopologyNodeCount(); j++)
			{
			CTopologyNode *pNode = Universe.GetTopologyNode(j);
			if (pNode->IsEndGame())
				continue;

			//	Different stats depending on type

			switch (iType)
				{
				case typeSystemLabels:
					{
					//	Create the system and generate stats

					CSystem *pSystem;
					if (error = Universe.CreateStarSystem(pNode, &pSystem, NULL, &Stats))
						{
						printf("ERROR: Unable to create star system.\n");
						return;
						}

					//	Done

					Universe.DestroySystem(pSystem);
					break;
					}

				case typeNodeAttributes:
					{
					CString sAttribs = pNode->GetAttributes();

					if (!sAttribs.IsBlank())
						Stats.AddLabel(sAttribs);
					else
						Stats.AddLabel(CONSTLIT("[no attributes]"));

					break;
					}

				case typeNodeDebug:
					{
					CString sAttribs = pNode->GetAttributes();
					printf("%s: %s\n", 
							pNode->GetID().GetASCIIZPointer(), 
							pNode->GetAttributes().GetASCIIZPointer());
					break;
					}
				}
			}
		}

	//	Titles

	int iTotalLabels100 = Stats.GetTotalLabelCount() * 100 / iSystemSample;
	int iTotalLabels = iTotalLabels100 / 100;
	int iTotalLabelsDecimal = iTotalLabels100 % 100;

	switch (iType)
		{
		case typeSystemLabels:
			printf("LABEL STATISTICS\n\n");
			printf("Average no. of labels per universe: %d.%02d\n\n", iTotalLabels, iTotalLabelsDecimal);
			break;

		case typeNodeAttributes:
			printf("NODE ATTRIBUTES\n\n");
			printf("Average no. of nodes per universe: %d.%02d\n\n", iTotalLabels, iTotalLabelsDecimal);
			break;
		}

	//	Nodes

	if (iType != typeNodeDebug)
		{
		for (i = 0; i < Stats.GetLabelAttributesCount(); i++)
			{
			CString sAttribs;
			int iCount;

			Stats.GetLabelAttributes(i, &sAttribs, &iCount);

			if (bPermutations || strFind(sAttribs, CONSTLIT(",")) == -1)
				{
				int iCount100 = iCount * 100 / iSystemSample;
				int iPercent100 = iCount * 10000 / Stats.GetTotalLabelCount();

				printf("%s: %d.%02d (%d.%02d%%)\n", 
						sAttribs.GetASCIIZPointer(), 
						iCount100 / 100,
						iCount100 % 100,
						iPercent100 / 100,
						iPercent100 % 100);
				}
			}
		}
	}