#include "library.h" namespace py = pybind11; PYBIND11_MODULE(library, m) { m.doc() = "Python API for playing Starcraft II"; define_typeenums(m); define_unit(m); define_unittype(m); define_util(m); define_point(m); define_base_location(m); py::class_<Coordinator>(m, "Coordinator") .def(py::init()) .def("set_participants", &sc2::Coordinator::SetParticipants) .def("launch_starcraft", &sc2::Coordinator::LaunchStarcraft) .def("start_game", &sc2::Coordinator::StartGame) .def("update", &sc2::Coordinator::Update); py::enum_<sc2::Race>(m, "Race") .value("Terran", sc2::Race::Terran) .value("Zerg", sc2::Race::Zerg) .value("Protoss", sc2::Race::Protoss) .value("Random", sc2::Race::Random); // Stupid anonymous enum, used as int everywhere. Best work-around I could think of. py::module players = m.def_submodule("Players", "Constants for referring to players"); players.attr("Self") = (int) Players::Self; players.attr("Enemy") = (int) Players::Enemy; players.attr("Neutral") = (int) Players::Neutral; players.attr("Ally") = (int) Players::Ally; players.attr("Size") = (int) Players::Size; // These are probably used for players.attr("None") = (int) Players::None; // creating arrays of fixed length?? /* TODO: These also needs to be defined typedef SC2Type<ABILITY_ID> AbilityID; typedef SC2Type<UPGRADE_ID> UpgradeID; typedef SC2Type<BUFF_ID> BuffID; */ py::class_<sc2::UnitTypeID>(m, "UnitTypeID") .def(py::init<sc2::UNIT_TYPEID>()); py::implicitly_convertible<sc2::UNIT_TYPEID, sc2::UnitTypeID>(); py::class_<sc2::Agent>(m, "Agent") .def(py::init()); // IDABot is a specialization of Agent py::class_<IDABot, PyIDABot, sc2::Agent>(m, "IDABot") .def(py::init()) .def("OnGameStart", &IDABot::OnGameStart) .def("OnStep", &IDABot::OnStep) .def("OnStep_UpdateIDABot", &IDABot::OnStep_UpdateIDABot) .def("get_all_units", &IDABot::GetAllUnits) .def("get_my_units", &IDABot::GetMyUnits) .def_property_readonly("base_manager", &IDABot::Bases); py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); py::enum_<sc2::Difficulty>(m, "Difficulty") .value("VeryEasy", sc2::Difficulty::VeryEasy) .value("Easy", sc2::Difficulty::Easy) .value("Medium", sc2::Difficulty::Medium) .value("MediumHard", sc2::Difficulty::MediumHard) .value("Hard", sc2::Difficulty::Hard) .value("HardVeryHard", sc2::Difficulty::HardVeryHard) .value("VeryHard", sc2::Difficulty::VeryHard) .value("CheatVision", sc2::Difficulty::CheatVision) .value("CheatMoney", sc2::Difficulty::CheatMoney) .value("CheatInsane", sc2::Difficulty::CheatInsane); m.def("create_participants", &sc2::CreateParticipant, "Create participant from agent"); m.def("create_computer", &sc2::CreateComputer, "Create participant from built-in Starcraft computer"); }