neumond / pybrood Goto Github PK
View Code? Open in Web Editor NEWAnother BWAPI Python binding made with pybind11
License: MIT License
Another BWAPI Python binding made with pybind11
License: MIT License
Problem after pip install:
Traceback (most recent call last):
File "example.py", line 2, in <module>
from pybrood import BaseAI, run, game, Color
File "F:\Projects\Starcraft AI\workspace\pybrood test\bot\pybro\lib\site-packages\pybrood\__init__
.py", line 1, in <module>
from .inner import *
ImportError: DLL load failed: The specified procedure could not be found.
Looks like the error when the compiler is the wrong version. So I'll try to compile from source.
It looks like bwapi/include/BWAPI/SetContainer.h:54 is one line too far - it should be line 53.
I have bwapi tag=v4.1.2 checked out.
Should say "Setup paths in generator/config.py"
To build, requires pip install jinja2 pyaml
pybind path in config doesn't do anything, as the comment indicates
need to put pybind in right place, ..\pybind11-2.0.0\include\pybind11
had to change line 58 of inner.vcxproj to:
<AdditionalIncludeDirectories>C:\Python35\include;..\..\pybind11-2.0.0\include;..\..\bwapi\bwapi\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Now the example works, I'm wondering what the difference is in the precompiled version?
I'm using Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
the AIModule of BWAPI has onNukeDetect/onUnitDiscover/onUnitEvade/onUnitCreate/onUnitDestroy. Is pybrood going to supprot these APIs?
code below report an error: pybrood.inner.UnitType: No constructor defined!
unit_type = UnitType(UnitTypes.Terran_Marine)
The example code works fine, but PyCharm gives the warning Unresolved reference 'game'
Furthermore if I want to "compile" the code using cython, I get
Error compiling Cython file:
------------------------------------------------------------
...
units = game.getAllUnits()
for u in units:
print('Unit', u.getID(), u.getType().getName(), u.getPosition(),
u.getTilePosition())
game.print('Hello world!')
^
------------------------------------------------------------
example.py:17:13: Expected an identifier
Removing the line lets cython compile the file correctly.
Not sure if this is intended (might be an implementation thing), but I just put this information here as an issue as it might be useful.
For now I just don't use cython and ignore PyCharm. Thank you for pybrood!
So far only 32-bit builds are available on pip
. It would be good if there are 64-bit builds as well.
I'm trying to understand the decision to convert all Positions into integer arrays. You lose type safety and methods like getDistance().
Is unit::getLastCommand() wrapping in pybrood? It seems that I cant find this in pybrood document. Thanks.
It appears there are declaration order problems in the generated code. It could be related to the version of pybind11 I used (2.2.0) or compiler version (msvc2015). But these errors can be fixed with a few simple changes.
There were 3 lines which gave an error while importing the python module: ImportError: arg(): could not convert default argument into a Python object (type not registered yet?). Compile in debug mode for more information.
.def("isVisible", &BulletInterface::isVisible, py::arg("player") = (Player) nullptr)
It is referring to Player
in the default paramter but it has not been registered yet. This one I fixed by naming the PlayerInterface wrapper definition and moving up above the BulletInterface:
py::class_<BWAPI::PlayerInterface, std::unique_ptr<BWAPI::PlayerInterface, py::nodelete>> player(m, "Player");
py::class_<BWAPI::BulletInterface, std::unique_ptr<BWAPI::BulletInterface, py::nodelete>>(m, "Bullet")
...
.def("isVisible", &BulletInterface::isVisible, py::arg("player") = (Player) nullptr)
...
player
.def("getID", &PlayerInterface::getID)
The next 2 problems are in the UnitInterface wrapper. The default parameters cast nullptr
to Unit
, but Unit
has not been registered yet.
.def("useTech", (bool (UnitInterface::*)(TechType, Unit)) &UnitInterface::useTech, py::arg("tech"), py::arg("target") = (Unit) nullptr)
.def("canUseTech", (bool (UnitInterface::*)(TechType, Unit, bool, bool, bool, bool) const) &UnitInterface::canUseTech, py::arg("tech"), py::arg("target") = (Unit) nullptr, py::arg("checkCanTargetUnit") = true, py::arg("checkTargetsType") = true, py::arg("checkCanIssueCommandType") = true, py::arg("checkCommandibility") = true)
These I fixed by naming the class again, changing the first 2 lines to:
py::class_<BWAPI::UnitInterface, std::unique_ptr<BWAPI::UnitInterface, py::nodelete>> unit(m, "Unit");
unit
.def("getID", &UnitInterface::getID)
After making these changes, I was able to import the python module without errors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.