I am trying to get coordinates for turtles in NetLogo by using the Java API. I have managed to get the workspace loaded and have been using the following code that I made:
public static int getX(HeadlessWorkspace workspace, String playerName, int agentNum)
{
Double doubleX = null;
int xVal = 0;
try
{
xVal = doubleX.valueOf((workspace.report("[xcor] of "+playerName+" "+agentNum).toString()).trim()).intValue();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return xVal;
}
However, there is one small problem. It is extremely slow when there are more than 5 turtles. When I run the Flocking code with 200 turtles, without getting the coordinates, then I get about 300 ticks in 10 seconds. When I run the code with the coordinates, then each tick takes about 3 seconds. Is there a more efficient way of achieving this?
Thanks,
Nadim