本文整理匯總了C++中TList::IndexOf方法的典型用法代碼示例。如果您正苦於以下問題:C++ TList::IndexOf方法的具體用法?C++ TList::IndexOf怎麽用?C++ TList::IndexOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TList
的用法示例。
在下文中一共展示了TList::IndexOf方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: FindMainRoads
//---------------------------------------------------------------------------
// Description: Highlights the routes with the heigher pheromone intesity
// starting from the Nest. If the Food source is not reached
// after a given number of tries, stop the search and draw the
// result.
bool __fastcall Civilization::FindMainRoads(int Ntries, TImage *ImageBox, const int RWidth, const float Scale)
{
// Start from the Anthill...
City *CurrentCity = Nest;
TList *MainRoads = new TList();
while(CurrentCity!=FoodSourceCity && Ntries>0)
{
int PheroLevel = -MAXINT;
Route *CurrentRoad = NULL;
City* NextCity;
Route* thisRoad;
// the following loop select the best road acording to the pheromone level
for(int j=0; j<Roads->Count; j++)
{
thisRoad = (Route*)Roads->Items[j];
// if the road has a conection with the current city...
NextCity = thisRoad->GetConection(CurrentCity);
// Test the highest Pheromone level among the possible roads...
// if 'thisRoad' was not used before...
if(NextCity!=NULL && MainRoads->IndexOf(thisRoad)==-1)
{
if(thisRoad->GetPheromone() > PheroLevel)
{
CurrentRoad = thisRoad;
PheroLevel = thisRoad->GetPheromone();
}
}
}
// Go to next city using the selected road...
if(CurrentCity!=NULL && CurrentRoad!=NULL)
{
CurrentCity = CurrentRoad->GetConection(CurrentCity);
MainRoads->Add(CurrentRoad);
}
Ntries--;
}
// Draw the MainRoad
Rebuild(ImageBox,Scale);
// Draw all the roads
for(int i=0; i<MainRoads->Count; i++)
{
ImageBox->Canvas->Pen->Width = RWidth;
((Route*)MainRoads->Items[i])->DrawRoad(ImageBox,clRed,Scale);
ImageBox->Canvas->Pen->Width = 1;
}
return (Ntries>0)?true:false;
}