I want to create an entity with artificial intelligence. It should be possible to move either up, down, left or right (on its own) and it should choose the direction, in which it should head next, dynamically depending on the obstacles, which are surrounding it.
Therefore I planned to spacify a “static” number for each direction – up (1), right (2), down (3), left (4) – these numbers are just examples and can be changed. I wanted to create random numbers in this range and decide which way to go. But I wanted to know if there is a way to use this method efficiently if for example the way “up” and “down” is blocked. In this case I would have to create either the number 2 (right) or 4 (left) randomly to decide which direction to go.
Is there an efficient way to do this.
Thanks for your help in advance.