I have a 2D grid for a robot to navigate around. I need to locate the shortest path between two points, the startNode and goalNode. The grid is represented by a n x n multidimensional array.
Robots possible actions (transition)
- Up [0,1]
- down [0,-1]
- left [-1,0]
- right [1,0]
where [x,y]
How would I construct a method to return one of the preceding actions if it does not exceed the multidimensional array bounds?
getAction(x,y)
get potential action from transition
if valid action - in array bounds
return action
Thanks,
Check to see if moving in a certain direction would put you out of bounds.
So it would look something like
Of course this would always try to move up first, then down, then right, then left. So you can change this code to match your needs.