Hello, everyone

I know this may have been posted in the wrong section ,but I thought it is a rookie thing ,so Starting With Gamestudio was my choice for posting ...

In the AUM 109 workshop (named "AI Part 4"), I figured out every part except when it comes to the find_path() function which I didn't understand at all frown
The problem is that the writer of the workshop didn't clarify it in detail and depended on merely writing comments in the code which still didn't help, so I would appreciate it if anyone has helped me understand how this function works and what it does precisely in plain English laugh Also, a brief description of this workshop as a whole would be appreciated ...

Here's the function:

Code:
function find_path(l, j)

{

       i = 0;

       while (i < max_nodes) // search from this node for the rest of the nodes (up to 299 more nodes)

       {

               if ((i != j) && (visited[i + max_nodes * j] == 0)) // the current node can "see" these nodes, excepting itself of course (i != j)

               {

                       if (node_to_node[l + max_nodes * j] == node_to_node[l + max_nodes * i] + node_to_node[i + max_nodes * j])

                       // that's a node on the shortest path because the shortest path includes it

                       {

                               k += 1; // move to the next array element

                               path[k] = i; // and store the node number inside the array

                               next_node = i; // store the new node on the shortest path because it will loose its value right away

                               i = max_nodes - 1; // don't test other values - eliminate other paths that have the same length (that could happen in some levels)

                               if (path[k] == l) // end of search, reached the starting point (l = start_node, remember?)

                               {

                                       return; // get out of this function

                               }

                       }

               }

               i += 1; // increase i if the function continues to run

       }

       j = next_node; // set the next node on the path as target

       find_path(l, j); // recursive function, search for the shortest path again (if it searched (2,10) now search (2,9) and so on)

}


Last edited by JackPell; 07/28/16 18:45.