// Alternative players turns
if (iPlayerTurn == 1)
iPlayerTurn = 2;
else
iPlayerTurn = 1;
// increment to keep under 9 turns
iCount++;
}// End Main While Loop
// Halts program at end
cout << "\n\nPress ENTER to quit.";
cin.get();
return 0;
}
// check for end of the game conditions
void checkForWinner(char theBoard, bool &bGameOver, bool &bWinGame)
{
//check the rows
for (int i = 0; i < 3; i++)
{
if (theBoard[i][0] == theBoard[i][1] && theBoard[i][1] == theBoard[i][2])
{
bGameOver = true;
bWinGame = true;
}
return;
}
//check the clmns
for (int i = 0; i < 3; i++)
{
if (theBoard[0][i] == theBoard[1][i] && theBoard[1][i] == theBoard[2][i])
{
bGameOver = true;
bWinGame = true;
}
return;
}
//check the diagonals
if (theBoard[0][0] == theBoard[1][1] && theBoard[1][1] == theBoard[2][2])
{
bGameOver = true;
bWinGame = true;
}
if (theBoard[2][0] == theBoard[1][1] && theBoard[1][1] == theBoard[0][2])
{
bGameOver = true;
bWinGame = true;
}
//need to check the board full. (No-win conditions).
if (theBoard[0][0] != '1' && theBoard[0][1] != '2' && theBoard[0][3] != '3' &&
theBoard[1][0] != '4' && theBoard[1][1] != '5' && theBoard[1][2] != '6' &&
theBoard[2][0] != '7' &&theBoard[2][1] != '8' && theBoard[2][2] != '9' && !bGameOver)
bGameOver = true;
C++ compiler is smart enough to figure out the first dimension I presume using some pointer arithmetic.
Actually, even though the first dimension is not required, it is not because the compiler is smart enough to work it out. It can't. Its because the compiler doesn't care about what it is. The other dimensions are required so that the compiler can do the correct pointer arithmetic to locate an element, but the first dimension is not required for that calculation.
I tend to declare all dimensions if I know that they are fixed. What is even better, if the dimensions are fixed, is to pass the array by reference. This forces you to declare all the dimensions and gives a full dimension check at compile time: