You are right, there is such technique.
Each winning pattern starts at the upper edge or at the left edge, and continues for three steps. In each of these steps, one of the following happens:
- Row number gets incremented, and column stays the same
- Column number gets incremented, and row stays the same
- Both row and column number gets incremented (first diagonal)
- Row number gets incremented, and column number gets decremented (the other diagonal)
So now you can write a function like this:
bool CheckWin(char[3][3] board, char playerCh, int r, int c, int dr, int dc) {
for (int i = 0 ; i != 3 ; i++) {
if (board[r+i*dr][c+i*dc] != playerCh) {
return false;
}
}
return true;
}
Using this function, you can check if a player has three in a row starting at (r,c), with the step dr rows and dc columns:
bool won = false;
for (int i = 0 ; !won && i != 3 ; i++) {
won |= CheckWin(board, 'X', i, 0, 0, 1)
|| CheckWin(board, 'X', 0, i, 1, 0);
}
won |= CheckWin(board, 'X', 0, 0, 1, 1);
won |= CheckWin(board, 'X', 2, 0, -1, 1);