[SOLVED] - Bloody incremented the wrong variable.
My code is spitting out and IndexOutOfRange Error, yet it manages to print each element to the console perfectly fine.
I can’t for the life of me work out where my bug is.
Please help, I’m questioning life choices at this point.
Error:
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
The line of code I get the error:
for (x = 0; x < BOARDLENGTH && Board[x, y] != otherPlayer; y++)
The code block:
for (int y = 0; y < BOARDLENGTH; y++)
{
count = 0;
nextSpace = new int[] { -1, -1 };
int x = 0;
Console.Error.WriteLine(x < BOARDLENGTH && Board[x, y] != otherPlayer);
for (x = 0; x < BOARDLENGTH && Board[x, y] != otherPlayer; y++)
{
if (Board[x, y] == playerToCheck)
count++;
else
nextSpace = new int[] { x, y };
}
if (count >= 2)
return nextSpace;
}
Output Stream:
True