void __stdcall onTick(double &time)
{
int ax,ay;
int nbrCount;
pState *nbr;
pState a = anyAgent(NULL,ax,ay,nbr,nbrCount);
// pick a neighbour
int nbrIndex = random(aNbrCount); // 0..aNbrCount-1
// get second neighbour
int bx = getNbrX(ax,ay,nbrIndex);
int by = getNbrY(ax,ay,nbrIndex);
pState b = xyAgent(bx,by,nbr,nbrCount);
// now nbr[0..nbrCount-1] are second neighbours of a.
// process second neighbours...
}