8 You have 8 directions, and when you get in some direction, you need to “rotate this matrix”
But this is just modulo over a finite field.
Since you only have 100 integers to choose a probability, you can simply drop all the integers in the list and the value from each integer to the index of your direction.
In this direction, you rotate (modulo addition) so that it indicates the movement you must make.
And than you have one array that has a difference that you must apply to your movement.
something like.
40 numbers 14 numbers 8 numbers int[100] probab={0,0,0,0,0,0,....,1,1,1,.......,2,2,2,...};
and then
N NE E SE STOP int[9] next_move={{0,1},{ 1,1},{1,1},{1,-1}...,{0,0}}; //in circle
So you choose
move=probab[randint(100)] if(move != 8)//if 8 you got stop { move=(prevous_move+move)%8; } move_x=next_move[move][0]; move_y=next_move[move][1];