Hi,
I am making a connect 5 program with a 15x15 array. I have have the check vertical and horizontal parts working but the diagonally is giving me a problem. Here is half the method, is suppose to check up and to the left for the same color chip but everytime it only loops once. Example, chips at 0,0 1,1 2,2 and when a 3,3 chip is dropped it only counts the 3,3 chip and loops once to count the 2,2 chip. Heres the code thanks!
Code:
void checkDiagonal(char a[][15], int prow, int pcol, char playerStone)
{
int numInline = 1;
int i, j;
for(i= prow-1; i >= 0; i--) //Check diagonal up left
for(j= pcol-1; j >= 0; j--)
{
if(numInline < 5)
if(a[i][j] == playerStone)
{
numInline++;
printf("%s %d %d %d", "Up Left: ", numInline, i, j);
break; //To get back to outer for loop
}
else
break;
else
{
if(playerStone == 'O')
{
printBoard(a, 15, boardAxis);
printf("%s", "Player 1 wins diagonally up left!!!!\n");
}
else
{
printBoard(a, 15, boardAxis);
printf("%s", "Player 2 wins diagonally up up left!!!!\n");
}
exit(0);
}
}
}