I would suggest a data-driven approach:
// We set up some data which represents the possible ways to win. Then later we// can set up a loop, instead of explicitly testing each case in a separate// statement.char possible_wins[8][3] = { {0, 1, 2}, (3, 4, 5}, {6, 7, 8}, // rows {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, // columns {0, 4, 8}, {2, 4, 6} }; // diagonals// We'll use a bitmask to indicate the states we want to test for.const int X = 1;const int O = 2;const int EMPTY = 4;int linesContaining(int types) { int count = 0; // symbolAt() should return X, O, or EMPTY according to what's in that space // Depending on how things are represented in the rest of the game, you may // not need it ;) int myboard[9]; for (int i = 0; i < 9; i++) { myboard = symbolAt(i); } for (int i = 0; i < 8; i++) { if ((myBoard[possible_wins[0]] & types) && (myBoard[possible_wins[1]] & types) && (myBoard[possible_wins[2]] & types)) { count++; } } return count;}// For example, "linesContaining(X)" will be non-zero if X has won, similarly O.// The extra flexibility is built in to make it more useful for AI routines.