int check_diags(int row, int col) { int count = 0; count += check_diag(row, col, -1, -1); count += check_diag(row, col, -1, +1); count += check_diag(row, col, +1, +1); count += check_diag(row, col, +1, -1); return count; }
int check_diag(int row, int col, int x, int y) { int count = 0; row = row + x; col = col + y; if (VALID_ROW(row) && VALID_COL(col)) { if (board[row][col] == QUEEN) count++; count += check_diag(row, col, x, y); } return count; }
void CApp::verify_winner(int id) { if (check_pos(id, next_pos(id, 0, 1), 0, 1) || check_pos(id, next_pos(id, 1, 0), 1, 0) || (check_anti_diag(id) && check_pos(id, next_pos(id, 1, -1), 1, -1)) || (check_diag(id) && check_pos(id, next_pos(id, 1, 1), 1, 1))) { if (grid[id] == GRID_TYPE_X) result = FINAL_X_WON; else result = FINAL_O_WON; finish = true; } if (grid_used == MATRIX_SIZE * MATRIX_SIZE) { result = FINAL_DRAW; finish = true; } }