Blizzard / s2client-api

StarCraft II Client - C++ library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
1.66k stars 282 forks source link

race_actual always defaults to sc2::Race::Protoss #294

Open pedronahum opened 5 years ago

pedronahum commented 5 years ago

Hi, Maybe someone can point me in the right direction. I am currently trying to analyze replays (3.16.1 Pack 1) using the Linux package 3.16.1 and regardless of the UnitTypeData (eg, CommandCenter), player_info always returns "sc2::Race::Protoss".

void OnGameStart() final {
        const sc2::ObservationInterface* obs = Observation();
        assert(obs->GetUnitTypeData().size() > 0);
        count_units_built_.resize(obs->GetUnitTypeData().size());
        std::fill(count_units_built_.begin(), count_units_built_.end(), 0);

        std::cout << "Map name: " << obs->GetGameInfo().map_name << std::endl;

        // Get the race of the players
        sc2::GameInfo game_info = obs->GetGameInfo();
        std::vector<sc2::PlayerInfo> player_information = game_info.player_info;

        for (uint32_t i = 0; i < player_information.size(); ++i){
            sc2::PlayerInfo player = player_information[i];
            sc2::Race race = player.race_actual;
            if(race == sc2::Race::Protoss) {
                std::cout << "Player ID: " << player.player_id << "; Player's Race : " << "Protoss" << std::endl;
            } else if(race == sc2::Race::Terran){
                std::cout << "Player ID: " << player.player_id << "; Player's Race : " <<"Terran" << std::endl;
            } else if(race == sc2::Race::Zerg){
                std::cout << "Player ID: " << player.player_id << "; Player's Race : " << "Zerg" << std::endl;
            } else {
                std::cout << "Player ID: " << player.player_id << "; Player's Race : " << "Random" << std::endl;
            }
        }
    }

I am seeing a similar issue with the map_name, but maybe I am very lucky that all my replay tests have been done in the map "Odyssey LE".

Any pointer is greatly appreciated.

Thanks,

pedronahum commented 5 years ago

Hi, I see that there was an attempt to address this issue (at least for maps) in #259 via force_refresh, yet the most recent version of GetGameInfo (in ObservationInterface) do not expose force_refresh. Could the cache be creating a similar issue for the player's race? https://github.com/Blizzard/s2client-api/blob/d9ba0a33d6ce9d233c2a4ee988360c188fbe9dbf/include/sc2api/sc2_interfaces.h#L140

pedronahum commented 5 years ago

Hi, ReplayControl() would output the correct race, yet GetGameInfo() would not.

sc2::ReplayInfo replay_info = ReplayControl()->GetReplayInfo();
std::cout << "player_1_race: " << replay_info.players[0].race << std::endl;
std::cout << "player_2_race: " << replay_info.players[1].race << std::endl;

I replicated #259, and I can confirm that obs->GetGameInfo(true) would address the issue. But not sure if that is the design you want to follow. I just think that is not good if two different approaches to obtain the race of a player provide different information.

Thanks,