June 2018
Intermediate to advanced
436 pages
10h 33m
English
Now the search space for the agent is ready. So let's calculate the initial position of the agent and the goal. First, we compute the initial position of the agent in the grid, as follows:
// Calculate the position of agentint calcAgentPos(float[][] Map) { int x = -1; for(int i = 0; i < size * size; i++) { if(Map[i / size][i % size] == 1) return i; } return x; }
Then we calculate the position of the goal, as follows:
// Calculate the position of goal. The method takes the grid space as inputint calcGoalPos(float[][] Map) { int x = -1;// start from the initial position // Then we loop over the grid size say 4x4 times for(int i = 0; i < size * size; i++) { // If the mapped position is the initial position, ...Read now
Unlock full access