From 989d10f9af5c224f8c4be4534c28399d8a3f0251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Mon, 25 Jun 2018 13:40:39 +0200 Subject: [PATCH] Run the existing baseline behaviour from a Python function --- CMakeLists.txt | 23 ++++++++++++++++++++++- library.cpp | 36 ++++++++++++++++++++++++++++++++++++ library.cxx | 12 ------------ tutorial.cxx | 15 --------------- 4 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 library.cpp delete mode 100644 library.cxx delete mode 100644 tutorial.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 191b40b..d6fa9ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,25 @@ set_target_properties(sc2protocol PROPERTIES COMPILE_FLAGS "/W0") set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CommandCenter) -pybind11_add_module(library library.cxx) +# TODO: Move everything below this line to a separate directory + +include_directories(SYSTEM + ${PROJECT_SOURCE_DIR}/lib/s2client-api/include + ${PROJECT_SOURCE_DIR}/lib/s2client-api/contrib/protobuf/src + ${PROJECT_BINARY_DIR}/lib/s2client-api/generated +) + +# All the source files for the bot. +file(GLOB BOT_SOURCES "src/*.cpp" "src/*.h" "src/*.hpp") + +link_directories(${PROJECT_BINARY_DIR}/s2client-api/bin) + +# Enable compilation of the SC2 version of the bot code +# TODO: Remove all remaining BW code +add_definitions(-DSC2API) + +# Create the executable. +pybind11_add_module(library library.cpp ${BOT_SOURCES}) +target_link_libraries(library PRIVATE + sc2api sc2lib sc2utils sc2protocol libprotobuf +) diff --git a/library.cpp b/library.cpp new file mode 100644 index 0000000..bd86eb6 --- /dev/null +++ b/library.cpp @@ -0,0 +1,36 @@ +#include <pybind11/pybind11.h> +#include <sc2api/sc2_api.h> +#include "src/IDABot.h" +#include <iostream> + +void run() +{ + char *argv[] = { "executable", NULL}; + int argc = sizeof(argv) / sizeof(char*) - 1; + sc2::Coordinator coordinator; + coordinator.LoadSettings(argc, argv); + + IDABot bot; + coordinator.SetParticipants({ + CreateParticipant(sc2::Race::Terran, &bot), + sc2::CreateComputer(sc2::Race::Zerg) + }); + + coordinator.LaunchStarcraft(); + coordinator.StartGame("InterloperTest.SC2Map"); + + while (coordinator.Update()) { + } +} + +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"); + m.def("run", &run, "Start Starcraft 2"); +} diff --git a/library.cxx b/library.cxx deleted file mode 100644 index ac183e5..0000000 --- a/library.cxx +++ /dev/null @@ -1,12 +0,0 @@ -#include <pybind11/pybind11.h> - -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"); -} diff --git a/tutorial.cxx b/tutorial.cxx deleted file mode 100644 index b7e2b86..0000000 --- a/tutorial.cxx +++ /dev/null @@ -1,15 +0,0 @@ -#include <iostream> -#include <pybind11/pybind11.h> - -int add(int i, int j) -{ - return i + j; -} - -int main (int argc, char *argv[]) -{ - while (true) - { - std::cout << "Hello World!" << std::endl; - } -} -- GitLab