I'm trying to figure out how to jump to the beginning of an array after i reached the end.
Basically my code has multiple holes filled with stones and if you select a hole all stones from that hole will be taken away and distributed in the following holes 1 at each time.
Now if the last hole is reached it should start at the beginning of the array and put the remaining stones in the holes at the beginning.
Unfortunately right now all i get is an error message stating
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
My code in this specific code so far is:
for (int i = chosenHoleInt; i <= stonesOnChosenField + chosenHoleInt; i++)
{
board.holes[chosenHoleInt].Stones--;
board.holes[i].Stones++;
if (chosenHoleInt > board.holes.Length)
{
chosenHoleInt = 0;
}
}
I thought that i could solve the problem by implementing the board.holes.length part but apparently that didn't work at all. Any help would be appreciated since i'm still learning and quite stuck right now. :)