Rik's Treehouse > Babbling in Binary > My Software > Orphanware > R2DToo > R2DToo Help > For the Programmer > forEachNbrVar

forEachNbrVar

Declaration
Parameters
Remarks
Revisions
Example
See Also

Declaration

void __stdcall forEachNbrVar(
	int x,                                       // x-coordinate of agent
	int y,                                       // y-coordinate of agent
	bool (*func)(pState,int,int,pState*,         // name of function
	             int,int,double*,int),      
	double* var,                                 // workspace
	int varCount                                 // size of workspace
);
Top of page

Parameters

x
X-coordinate of agent whose neighbours are to be processed (zero based).
y
Y-coordinate of agent whose neighbours are to be processed (zero based).
func
The name of a function to apply to each agent in turn.
var
Allocated array of storage space for extra parameters.
varCount
Size of array, var[0..varCount-1].
Top of page

Remarks

This function is available through the API. It provides an efficient way to process every neighbour to the agent at (x,y) in turn. The details of this function are the same as that for
forEachAgentVar except that the iteration is only over the neighbours of a single agent. Top of page

Revisions

API v1.5
  • no longer passes param to func
Top of page

Example

bool getBestScore(pState state, int x, int y, pState *nbr, int nbrCount, int feaMode, double *var, int varCount) // score[0..width-1][0..height-1] is a matrix of doubles { switch (feaMode) { case feaBegin: var[0]=-1; var[1]=-1; break; case feaContinue: var[state[0]] = max(var[state[0]],score[x][y]); } return true; } void __stdcall onTick(double &time) { int x,y; int nbrCount; pState *nbr; pState state = anyAgent(NULL,x,y,nbr,nbrCount); double bestScore[2]; forEachNbrVar(x,y,getBestScore,bestScore,2); // now do something about it... } Top of page

See Also

forEachAgentVar, forEachNbr.
Top of page
[Rik's Office Hours] [Contact Rik]
Last updated: Fri Apr 30 2004, 1:37pm