• Разработка

Час добрый Повелители двоичной системы! Вопрос от чайника: - " А может ли кто-нибудь взглянуть на код и сказать будет ли у него будущее? Код написан ИИ Deep Seek по моей задаче. Очень хочется одно приложение иметь под рукой, а таких не вижу...

			#include <iostream>
#include <unordered_map>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>

class Team {
public:
    std::string name;
    int wins = 0;
    int losses = 0;
    int draws = 0;
    int home_wins = 0;
    int home_losses = 0;
    int home_draws = 0;
    int away_wins = 0;
    int away_losses = 0;
    int away_draws = 0;
    std::deque<std::string> recent_form;  // Хранит результаты последних 5 матчей

    Team(const std::string& name) : name(name) {}

    void addResult(const std::string& result, bool is_home) {
        if (result == "win") {
            wins++;
            if (is_home) home_wins++; else away_wins++;
        } else if (result == "loss") {
            losses++;
            if (is_home) home_losses++; else away_losses++;
        } else if (result == "draw") {
            draws++;
            if (is_home) home_draws++; else away_draws++;
        }
        recent_form.push_back(result);
        if (recent_form.size() > 5) recent_form.pop_front();
    }

    double getWinProbability() const {
        int total_games = wins + losses + draws;
        if (total_games == 0) return 0.0;
        return static_cast<double>(wins) / total_games;
    }

    double getHomeWinProbability() const {
        int total_home_games = home_wins + home_losses + home_draws;
        if (total_home_games == 0) return 0.0;
        return static_cast<double>(home_wins) / total_home_games;
    }

    double getAwayWinProbability() const {
        int total_away_games = away_wins + away_losses + away_draws;
        if (total_away_games == 0) return 0.0;
        return static_cast<double>(away_wins) / total_away_games;
    }

    double getRecentFormScore() const {
        if (recent_form.empty()) return 0.0;
        double form_score = 0.0;
        for (const auto& result : recent_form) {
            if (result == "win") form_score += 1.0;
            else if (result == "draw") form_score += 0.5;
            else if (result == "loss") form_score -= 0.5;
        }
        return form_score / recent_form.size();
    }
};

class Match {
public:
    Team* team1;
    Team* team2;
    int score1;
    int score2;
    bool is_team1_home;

    Match(Team* team1, Team* team2, int score1, int score2, bool is_team1_home)
        : team1(team1), team2(team2), score1(score1), score2(score2), is_team1_home(is_team1_home) {}

    std::pair<std::pair<Team*, std::string>, std::pair<Team*, std::string>> getResult() const {
        if (score1 > score2) {
            return {{team1, "win"}, {team2, "loss"}};
        } else if (score1 < score2) {
            return {{team1, "loss"}, {team2, "win"}};
        } else {
            return {{team1, "draw"}, {team2, "draw"}};
        }
    }
};

class FootballStats {
private:
    std::unordered_map<std::string, Team*> teams;
    std::vector<Match*> matches;

public:
    ~FootballStats() {
        for (auto& pair : teams) delete pair.second;
        for (auto& match : matches) delete match;
    }

    void addMatch(const std::string& team1_name, const std::string& team2_name, int score1, int score2, bool is_team1_home = true) {
        if (teams.find(team1_name) == teams.end()) {
            teams[team1_name] = new Team(team1_name);
        }
        if (teams.find(team2_name) == teams.end()) {
            teams[team2_name] = new Team(team2_name);
        }

        Team* team1 = teams[team1_name];
        Team* team2 = teams[team2_name];

        Match* match = new Match(team1, team2, score1, score2, is_team1_home);
        matches.push_back(match);

        auto result = match->getResult();
        team1->addResult(result.first.second, is_team1_home);
        team2->addResult(result.second.second, !is_team1_home);
    }

    double getWinProbability(const std::string& team1_name, const std::string& team2_name, bool is_team1_home = true) {
        Team* team1 = teams[team1_name];
        Team* team2 = teams[team2_name];

        if (team1 == nullptr || team2 == nullptr) return 0.5;  // Если команды не найдены

        if (team1->wins + team1->losses + team1->draws == 0 || team2->wins + team2->losses + team2->draws == 0) {
            return 0.5;  // Если нет данных, вероятность 50%
        }

        // Базовые вероятности
        double team1_prob = team1->getWinProbability();
        double team2_prob = team2->getWinProbability();

        // Учитываем домашние/гостевые матчи
        if (is_team1_home) {
            team1_prob += team1->getHomeWinProbability() * 0.2;
            team2_prob += team2->getAwayWinProbability() * 0.1;
        } else {
            team1_prob += team1->getAwayWinProbability() * 0.1;
            team2_prob += team2->getHomeWinProbability() * 0.2;
        }

        // Учитываем текущую форму
        team1_prob += team1->getRecentFormScore() * 0.1;
        team2_prob += team2->getRecentFormScore() * 0.1;

        // Учитываем пересекающиеся матчи
        for (const auto& match : matches) {
            if ((match->team1->name == team1_name && match->team2->name == team2_name) ||
                (match->team1->name == team2_name && match->team2->name == team1_name)) {
                auto result = match->getResult();
                if (result.first.second == "win") {
                    team1_prob += 0.1;
                } else if (result.first.second == "loss") {
                    team1_prob -= 0.1;
                } else if (result.first.second == "draw") {
                    team1_prob += 0.05;
                }
            }
        }

        // Нормализация вероятности
        double total_prob = team1_prob + team2_prob;
        if (total_prob == 0) return 0.5;
        return team1_prob / total_prob;
    }
};

int main() {
    FootballStats stats;

    // Добавляем матчи
    stats.addMatch("Team1", "Team2", 0, 2, true);
    stats.addMatch("Team2", "Team3", 4, 2, true);
    stats.addMatch("Team1", "Team3", 1, 1, false);

    // Получаем вероятность победы
    double probability = stats.getWinProbability("Team1", "Team3", true);
    std::cout << "Вероятность победы Team1: " << probability * 100 << "%" << std::endl;

    return 0;
}







g++ -o football_stats football_stats.cpp
./football_stats
		
0 комментариев Здесь каждый может высказать своё мнение. Сохраняйте уважение, потому что это взаимно.