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 agentintcalcAgentPos(float[][]Map) {intx = -1;for(inti = 0; i < size * size; i++) {if(Map[i / size][i % size] == 1)returni; }returnx; }

Then we calculate the position of the goal, as follows:

// Calculate the position of goal. The method takes the grid space as inputintcalcGoalPos(float[][]Map) {intx = -1;// start from the initial position // Then we loop over the grid size say 4x4 timesfor(inti = 0; i < size * size; i++) { // If the mapped position is the initial position, ...