星际争霸 II API 提供对游戏内状态观察和单位控制的访问。该 API 是通过 websocket 连接围绕 protobuf 定义的协议的包装器。
虽然可以直接写入协议,但此库提供了 C++ 和基于类的抽象。您可以在下面看到一个简单的示例。
[hidecontent type="logged" desc="隐藏内容:登录后可查看"]
#include <sc2api/sc2_api.h> #include <iostream>
using namespace sc2;
class Bot : public Agent {
public:
virtual void OnGameStart() final {
std::cout << "Hello, World!" << std::endl;
}
virtual void OnStep() final {
std::cout << Observation()->GetGameLoop() << std::endl;
}
};
int main(int argc, char* argv[]) {
Coordinator coordinator;
coordinator.LoadSettings(argc, argv);
Bot bot;
coordinator.SetParticipants({
CreateParticipant(Race::Terran, &bot),
CreateComputer(Race::Zerg)
});
coordinator.LaunchStarcraft();
coordinator.StartGame(sc2::kMapBelShirVestigeLE);
while (coordinator.Update()) {
}
return 0;
}
您可以在 docs/tutorial1.md 中找到有关此代码功能的详细教程。
您可以在我们的github 页面网站上的文档中找到 API 。文档是使用Doxygen从代码自动生成的
自己编辑和生成文档。
该库使用CMake生成项目文件。它在 Windows 上使用Visual Studio构建,在其他平台上使用 Makefiles 构建。它依赖于以下贡献包。
按照docs/building.md中的子模块和构建说明进行操作。
除了我们使用四个空格制表符而不是两个空格制表符外,我们尽最大努力遵守 Google C++ 风格指南。
该存储库仅附带一些用于测试的地图。
可以在此处找到其他地图和重播。
如果您使用的是 Visual Studio 2017 并且只需要预编译的库文件,您可以下载以下包:
可以在此处找到其他社区构建的 AI 库。
如果您是编程新手,CommandCenter框架可能是一个很好的起点。
[/hidecontent]
[/rihide]