views:

139

answers:

0

Hi,

I have a game I am making, it is giving me this message...

"An unhandled exception of type 'System.StackOverflowException' occurred in game.exe"

To explain...I have a 2D array with 9 different opening moves and I am getting a random number to use as the array reference to retrieve the details needed for a move...

  • you may get the same move again - but that's illegal.
  • the move may be illegal for other reasons too

So to try and fix this, I am calling the function again from within the function.

The error occurs very randomly

Is this bad practise to call a function from within itself?

What would be a better way to randomly row from a 2D array, AND if it isn't accept to get another one....

Or better still, how can I retrieve a random LEGAL move?