Suppose you have a specific starting point (x, y), and you are curious if there are three equal numbers in a line at that point. Consider only the case when you look in the horizontal direction. Then one way to do this (ignoring border checking) would be as follows:
bool IsHorizontalMatch(int x, int y) {
const int startValue = board[x][y];
for (int i = 1; i < 3; ++i)
if (board[x + i][y] != startValue)
return false;
return true;
}
Similarly, you can write a function to check vertically:
bool IsVerticalMatch(int x, int y) {
const int startValue = board[x][y];
for (int i = 1; i < 3; ++i)
if (board[x][y + i] != startValue)
return false;
return true;
}
And finally, one for the diagonals:
bool IsDiagonalDownMatch(int x, int y) {
const int startValue = board[x][y];
for (int i = 1; i < 3; ++i)
if (board[x + i][y + i] != startValue)
return false;
return true;
}
bool IsDiagonalUpMatch(int x, int y) {
const int startValue = board[x][y];
for (int i = 1; i < 3; ++i)
if (board[x + i][y - i] != startValue)
return false;
return true;
}
, ; ! , . : , , " ", , . (+1, +0), it (+0, +1), (+1, +1) (+1, -1). , , , :
bool IsLinearMatch(int x, int y, int stepX, int stepY) {
const int startValue = board[x][y];
for (int i = 1; i < 3; ++i)
if (board[x + i * stepX][y + i * stepY] != startValue)
return false;
return true;
}
bool IsLineStartingAt(int x, int y) {
return (IsLinearMatch(x, y, 1, 0) ||
IsLinearMatch(x, y, 0, 1) ||
IsLinearMatch(x, y, 1, 1) ||
IsLinearMatch(x, y, 1, -1));
}
, , .
, !
EDIT: .: -)