Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
Language: Cpp
BasedOnStyle: Google
BreakBeforeBraces: Linux
ColumnLimit: 120
IndentWidth: 4
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false
IndentCaseLabels: false
InsertNewlineAtEOF: true
LineEnding: LF
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
Standard: Latest
---
Language: Proto
DisableFormat: true
---
Language: Json
BasedOnStyle: Google
ColumnLimit: 120
IndentWidth: 2
45 changes: 45 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
Checks: "*,
-abseil-*,
-altera-*,
-android-*,
-boost-*,
-cert-*,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-fuchsia-*,
-google-*,
-hicpp-*,
-linuxkernel-*,
-llvm-*,
-llvmlibc-*,
-mpi-*,
-objc-*,
-openmp-*,
-portability-avoid-pragma-once,
-readability-identifier-length,
-zircon-*,
cert-dcl50-cpp,
cert-dcl58-cpp,
cert-env33-c,
cert-err33-c,
cert-err34-c,
cert-err52-cpp,
cert-err58-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-mem57-cpp,
cert-msc50-cpp,
cert-msc51-cpp,
cert-oop57-cpp,
cert-oop58-cpp,
google-build-namespaces,
google-readability-casting,
llvm-namespace-comment
"
CheckOptions:
misc-include-cleaner.IgnoreHeaders: 'sc2api/sc2_typeenums.h;sc2api/typeids/.*'
readability-function-cognitive-complexity.DescribeBasicIncrements: false
ExcludeHeaderFilterRegex: '.*/_deps/.*'
FormatStyle: none
HeaderFilterRegex: '.*/src/.*'
WarningsAsErrors: '*'
22 changes: 15 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,40 @@ env:

jobs:
basic_build:
name: basic_build (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
include:
- os: windows-latest
cores_cmd: echo $NUMBER_OF_PROCESSORS
- os: macos-latest
cores_cmd: sysctl -n hw.logicalcpu
- os: ubuntu-latest
cores_cmd: nproc

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v7.0.1
with:
submodules: recursive

- name: Configure
run: cmake -B ${{env.BUILD_DIR}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -B "${{env.BUILD_DIR}}" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}} --parallel 2
shell: bash
run: cmake --build "${{env.BUILD_DIR}}" --config ${{env.BUILD_TYPE}} --parallel $(${{ matrix.cores_cmd }})

ladder_build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v7.0.1
with:
submodules: recursive

- name: Configure
run: cmake -B ${{env.BUILD_DIR}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_FOR_LADDER=ON -DSC2_VERSION=4.10.0
run: cmake -B "${{env.BUILD_DIR}}" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_FOR_LADDER=ON -DSC2_VERSION=4.10.0

- name: Build
run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}} --parallel 2
run: cmake --build "${{env.BUILD_DIR}}" --config ${{env.BUILD_TYPE}} --parallel $(nproc)
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
# Copyright (c) 2021-2024 Alexander Kurbatov
# Copyright (c) 2021-2026 Alexander Kurbatov

cmake_minimum_required(VERSION 3.15)

Expand All @@ -24,8 +24,8 @@ set(FETCHCONTENT_QUIET FALSE)

option(BUILD_FOR_LADDER "Create build for the AIArena ladder" OFF)

# Build with c++17 support, required by sc2api
set(CMAKE_CXX_STANDARD 17)
# Build with c++20 support, required by sc2api
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Specify output directories
Expand All @@ -39,7 +39,7 @@ if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
endif ()

list(APPEND CMAKE_MODULE_PATH thirdparty/cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/cmake")

# cpp-sc2 dependency
include(cpp_sc2)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2024 Alexander Kurbatov
Copyright (c) 2021-2026 Alexander Kurbatov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ Starter bot for StarCraft II with integrated cpp-sc2.

## Support

Feel free to post questions on the unofficial StarCraft II AI Discord server. [Invite Link](https://discordapp.com/invite/Emm5Ztz)
If you have any questions, feel free to send a message over the
[#cpp](https://discord.com/channels/350289306763657218/350289506068463618)
channel of the [AI Arena](https://discord.gg/YurYAgHRSw) Discord server.

## Build instructions

> :construction: This project requires a compiler with C++17 support.
> :construction: This project requires a compiler with C++20 support.

1. Before proceeding further download the [actual map pack](https://aiarena.net/wiki/maps/).

1. Put the downloaded maps into the `Maps` folder (create it if the folder doesn't exist):
* Windows: `C:\Program Files\StarCraft II\Maps`
* OS X: `/Applications/StarCraft II/Maps`
* macOS: `/Applications/StarCraft II/Maps`
* Linux: anywhere.

### Windows
Expand All @@ -46,7 +48,7 @@ For building for Windows under WSL2, see [WSL2 Support](#wsl2-support).

1. Install [CMake](https://cmake.org/download/).

1. Download and install Visual Studio ([2017](https://www.visualstudio.com/downloads/) or newer).
1. Download and install Visual Studio ([2022](https://www.visualstudio.com/downloads/) or newer).

1. Get the project.

Expand Down Expand Up @@ -102,20 +104,20 @@ For building for Windows under WSL2, see [WSL2 Support](#wsl2-support).
1. Build the project.

```bash
cmake --build build --parallel $(nproc)
cmake --build build --parallel $(sysctl -n hw.logicalcpu)
```

1. Launch the bot with the specified absolute path to a SC2 map, e.g.:

```bash
./build/bin/BlankBot "/home/alkurbatov/Ladder2019Season3/AcropolisLE.SC2Map"
./build/bin/BlankBot "/Users/alkurbatov/Ladder2019Season3/AcropolisLE.SC2Map"
```

### Linux

1. Install [CMake](https://cmake.org/download/).

1. Install `gcc-c++`.
1. Install a C++ compiler (`g++` on Debian/Ubuntu, `gcc-c++` on Fedora/RHEL).

1. Install the `make` utility.

Expand Down Expand Up @@ -152,8 +154,8 @@ Cross compiling for Windows under WSL2 is supported through `cpp-sc2`. See the `
### Game client version
By default, the API assumes the latest version of the game client. The assumed version can be found in cmake's output, e.g.:
```bash
$ cmake -B build grep 'SC2 version'
Target SC2 version: 5.0.5
$ cmake -B build | grep "SC2 version"
Target SC2 version: 5.0.14
...
```

Expand Down Expand Up @@ -197,13 +199,13 @@ remove the `build` folder or the `CMakeCache.txt` file, or explicitly re-specify

### Build freezes (Linux or macOS)

If project compilation freezes, decrease nproc to 1 or more, e.g.:
If project compilation freezes, decrease the number of parallel jobs, e.g.:

``` bash
cmake --build build --parallel $(nproc --ignore=1)
cmake --build build --parallel 2
```

## License
Copyright (c) 2021-2024 Alexander Kurbatov
Copyright (c) 2021-2026 Alexander Kurbatov

Licensed under the [MIT license](LICENSE).
57 changes: 28 additions & 29 deletions src/Bot.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
// The MIT License (MIT)
//
// Copyright (c) 2021-2024 Alexander Kurbatov
// Copyright (c) 2021-2026 Alexander Kurbatov

#include "Bot.h"

#include <sc2api/sc2_common.h>
#include <sc2api/sc2_client.h>
#include <sc2api/sc2_typeenums.h>
#include <sc2api/sc2_unit.h>

#include <iostream>
#include <string>
#include <vector>

void Bot::OnGameStart()
auto Bot::OnGameStart() -> void
{
std::cout << "New game started!" << std::endl;
std::cout << "New game started!\n";
}

void Bot::OnGameEnd()
auto Bot::OnGameEnd() -> void
{
std::cout << "Game over!" << std::endl;
std::cout << "Game over!\n";
}

void Bot::OnBuildingConstructionComplete(const sc2::Unit* building_)
auto Bot::OnBuildingConstructionComplete(const sc2::Unit* building) -> void
{
std::cout << sc2::UnitTypeToName(building_->unit_type) <<
"(" << building_->tag << ") constructed" << std::endl;
std::cout << sc2::UnitTypeToName(building->unit_type) << " (" << building->tag << ") constructed\n";
}

void Bot::OnStep()
auto Bot::OnStep() -> void
{
std::cout << "OnStep" << std::endl;
std::cout << "OnStep\n";
}

void Bot::OnUnitCreated(const sc2::Unit* unit_)
auto Bot::OnUnitCreated(const sc2::Unit* unit) -> void
{
std::cout << sc2::UnitTypeToName(unit_->unit_type) <<
"(" << unit_->tag << ") was created" << std::endl;
std::cout << sc2::UnitTypeToName(unit->unit_type) << " (" << unit->tag << ") was created\n";
}

void Bot::OnUnitIdle(const sc2::Unit* unit_)
auto Bot::OnUnitIdle(const sc2::Unit* unit) -> void
{
std::cout << sc2::UnitTypeToName(unit_->unit_type) <<
"(" << unit_->tag << ") is idle" << std::endl;
std::cout << sc2::UnitTypeToName(unit->unit_type) << " (" << unit->tag << ") is idle\n";
}

void Bot::OnUnitDestroyed(const sc2::Unit* unit_)
auto Bot::OnUnitDestroyed(const sc2::Unit* unit) -> void
{
std::cout << sc2::UnitTypeToName(unit_->unit_type) <<
"(" << unit_->tag << ") was destroyed" << std::endl;
std::cout << sc2::UnitTypeToName(unit->unit_type) << " (" << unit->tag << ") was destroyed\n";
}

void Bot::OnUpgradeCompleted(sc2::UpgradeID id_)
auto Bot::OnUpgradeCompleted(sc2::UpgradeID id) -> void
{
std::cout << sc2::UpgradeIDToName(id_) << " completed" << std::endl;
std::cout << sc2::UpgradeIDToName(id) << " completed\n";
}

void Bot::OnError(const std::vector<sc2::ClientError>& client_errors,
const std::vector<std::string>& protocol_errors)
auto Bot::OnError(const std::vector<sc2::ClientError>& client_errors, const std::vector<std::string>& protocol_errors)
-> void
{
for (const auto i : client_errors) {
std::cerr << "Encountered client error: " <<
static_cast<int>(i) << std::endl;
for (const auto& err : client_errors) {
std::cerr << "Encountered client error: " << static_cast<int>(err) << '\n';
}

for (const auto& i : protocol_errors)
std::cerr << "Encountered protocol error: " << i << std::endl;
for (const auto& i : protocol_errors) {
std::cerr << "Encountered protocol error: " << i << '\n';
}
}
30 changes: 16 additions & 14 deletions src/Bot.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
// The MIT License (MIT)
//
// Copyright (c) 2021-2024 Alexander Kurbatov
// Copyright (c) 2021-2026 Alexander Kurbatov

#pragma once

#include <sc2api/sc2_agent.h>
#include <sc2api/sc2_client.h>

#include <string>
#include <vector>

// The main bot class.
struct Bot: sc2::Agent
{
struct Bot final : sc2::Agent {
Bot() = default;

private:
void OnGameStart() final;
auto OnGameStart() -> void final;

void OnGameEnd() final;
auto OnGameEnd() -> void final;

void OnStep() final;
auto OnStep() -> void final;

void OnBuildingConstructionComplete(const sc2::Unit* building_) final;
auto OnBuildingConstructionComplete(const sc2::Unit* building) -> void final;

void OnUnitCreated(const sc2::Unit* unit_) final;
auto OnUnitCreated(const sc2::Unit* unit) -> void final;

void OnUnitIdle(const sc2::Unit* unit_) final;
auto OnUnitIdle(const sc2::Unit* unit) -> void final;

void OnUnitDestroyed(const sc2::Unit* unit_) final;
auto OnUnitDestroyed(const sc2::Unit* unit) -> void final;

void OnUpgradeCompleted(sc2::UpgradeID id_) final;
auto OnUpgradeCompleted(sc2::UpgradeID id) -> void final;

void OnError(const std::vector<sc2::ClientError>& client_errors,
const std::vector<std::string>& protocol_errors = {}) final;
auto OnError(const std::vector<sc2::ClientError>& client_errors,
const std::vector<std::string>& protocol_errors = {}) -> void final;
};
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
# Copyright (c) 2021-2024 Alexander Kurbatov
# Copyright (c) 2021-2026 Alexander Kurbatov

set(bot_sources
main.cpp
Expand Down
Loading