O'Reilly logo

Java Deep Learning Projects by Md. Rezaul Karim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculating agent and goal positions

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required