Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stalemate detection #96

Open
Archiatrus opened this issue Dec 21, 2018 · 1 comment
Open

Stalemate detection #96

Archiatrus opened this issue Dec 21, 2018 · 1 comment

Comments

@Archiatrus
Copy link
Contributor

Should be possible to detect if there are only flying buildings. From that moment start a timer of X minutes until draw.

@Archiatrus
Copy link
Contributor Author

My solution:

for (auto i(0); i< response->game_info().player_info_size(); ++i)
{
    const auto& playerID = ActualObservation.player_common().player_id();
    const auto& playerInfo = response->game_info().player_info(i);
    if(playerInfo.player_id() == playerID && playerInfo.race_actual()==SC2APIProtocol::Race::Terran)
    {
        size_t totalHealth = 0U;
        for (auto ii(0); ii< ActualObservation.raw_data().units_size(); ++ii)
        {
            const auto unit = ActualObservation.raw_data().units(ii);
            if (unit.alliance() != SC2APIProtocol::Alliance::Self)
            {
                continue;
            }
            // This can be abused. Hide a worker somewhere.
            // But the solution is proper seek and destroy code of the attacker.
            // And it would gain nothing because a tie is a tie.
            if (!unit.is_flying())
            {
                lastGameLoopWithNonFlyer = currentGameLoop;
                break;
            }
            else
            {
                totalHealth+=unit.health();
            }
        }
        // If the flying building(s) gets attacked it is not a stalemate
        if (totalHealth_old != totalHealth)
        {
            totalHealth_old = totalHealth;
            lastGameLoopWithNonFlyer = currentGameLoop;
        }
    }
}
if (currentGameLoop - lastGameLoopWithNonFlyer > maxLoopsWithoutNonFlyer)
{
    std::cout << "DETECTED STALEMATE!!!!" << std::endl;
    CurrentExitCase = ExitCase::Stalemate;
}

Did I miss an obvious or not so obvious corner case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant