Skip to content
Snippets Groups Projects
Commit b1ddcadd authored by David Bergström's avatar David Bergström
Browse files

Implement run function in Python

parent 989d10f9
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ link_directories(${PROJECT_BINARY_DIR}/s2client-api/bin)
add_definitions(-DSC2API)
# Create the executable.
pybind11_add_module(library library.cpp ${BOT_SOURCES})
pybind11_add_module(library library.cpp library.h ${BOT_SOURCES})
target_link_libraries(library PRIVATE
sc2api sc2lib sc2utils sc2protocol libprotobuf
)
#include <pybind11/pybind11.h>
#include <sc2api/sc2_api.h>
#include "src/IDABot.h"
#include <iostream>
#include "library.h"
namespace py = pybind11;
void run()
{
char *argv[] = { "executable", NULL};
int argc = sizeof(argv) / sizeof(char*) - 1;
sc2::Coordinator coordinator;
coordinator.LoadSettings(argc, argv);
Coordinator coordinator;
IDABot bot;
coordinator.SetParticipants({
......@@ -23,14 +19,46 @@ void run()
}
}
int add(int i, int j)
{
return i + j + 1;
}
PYBIND11_MODULE(library, m)
{
m.doc() = "pybind11 example plugin";
m.def("add", &add, "A function which adds two numbers");
py::class_<Coordinator>(m, "Coordinator")
.def(py::init())
.def("SetParticipants", &sc2::Coordinator::SetParticipants)
.def("LaunchStarcraft", &sc2::Coordinator::LaunchStarcraft)
.def("StartGame", &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);
py::class_<sc2::Agent>(m, "Agent")
.def(py::init());
// IDABot is a specialization of Agent
py::class_<IDABot, sc2::Agent>(m, "IDABot")
.def(py::init());
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("CreateParticipant", &sc2::CreateParticipant, "Create participant from agent");
m.def("CreateComputer", &sc2::CreateComputer, "Create participant from built-in Starcraft computer");
m.def("run", &run, "Start Starcraft 2");
}
#pragma once
#include <pybind11/pybind11.h>
#include <sc2api/sc2_api.h>
#include "src/IDABot.h"
#include <iostream>
#include <pybind11/stl.h> /* Automatic conversion from std::vector to Python lists */
class Coordinator : public sc2::Coordinator
{
public:
// TODO: We might not always want default value when we run on Linux
Coordinator() : sc2::Coordinator()
{
char *argv[] = { "executable", NULL};
int argc = sizeof(argv) / sizeof(char*) - 1;
LoadSettings(argc, argv);
}
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment