Skip to content

Commit

Permalink
Merge pull request #73 from JavaBWAPI/linux-support
Browse files Browse the repository at this point in the history
Linux support
  • Loading branch information
JasperGeurtz authored Apr 13, 2022
2 parents 36754c2 + 58cf01e commit 44858ae
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 144 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/e2e-linux.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test Linux

on:
- pull_request

jobs:
e2e:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Setup and launch openbw
run: |
sudo apt-get update
sudo apt-get install cmake libsdl2-dev libsdl2-mixer-dev

git clone https://github.com/basil-ladder/openbw
git clone -b linux-client-support https://github.com/basil-ladder/bwapi
cd bwapi
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENBW_DIR=../../openbw -DOPENBW_ENABLE_UI=1
make -j4

curl http://www.cs.mun.ca/~dchurchill/starcraftaicomp/files/Starcraft_1161.zip -o starcraft.zip
unzip starcraft.zip patch_rt.mpq BROODAT.MPQ STARDAT.MPQ
mv patch_rt.mpq Patch_rt.mpq && mv BROODAT.MPQ BrooDat.mpq && mv STARDAT.MPQ StarDat.mpq
unzip starcraft.zip "maps/BroodWar/ICCup/ICCup Destination 1.1.scx"

BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP="maps/BroodWar/ICCup/ICCup Destination 1.1.scx" ./bin/BWAPILauncher&
BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP="maps/BroodWar/ICCup/ICCup Destination 1.1.scx" ./bin/BWAPILauncher&

- name: Build & Run test bots
run: |
mvn install -DskipTests
mvn -f it/bots/pom.xml package

java -jar it/bots/SittingDuck/target/SittingDuck-*-jar-with-dependencies.jar &
sleep 3
java -jar it/bots/jbwapibot/target/MarineHell-*-jar-with-dependencies.jar | grep "Hello from JBWAPI!" || exit 1
50 changes: 50 additions & 0 deletions .github/workflows/e2e-wine.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test Wine

on:
- pull_request

jobs:
e2e:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: '3.6'

- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Show versions
run: |
uname -a
python3 --version
java -version
- name: Setup e2e-windows environment
run: |
git clone https://github.com/Bytekeeper/sc-docker.git
cp it/sc-docker-support/*.dockerfile sc-docker/docker/dockerfiles
pushd sc-docker
pip3 install numpy==1.16.6 wheel
python3 setup.py bdist_wheel
pip3 install dist/scbw*.whl
cd docker
./build_images.sh
popd
cp sc-docker/scbw/local_docker/starcraft.zip /tmp/sc-docker/starcraft.zip
scbw.play --install

- name: Test the e2e-windows environment
run: |
sh mvnw clean install
sh mvnw -f it/bots/pom.xml package
for bot in $(ls -d it/bots/*/); do BOTNAME=$(basename $bot); echo "Setting up $BOTNAME"; mkdir -p "$HOME/.scbw/bots/$BOTNAME/AI" "$HOME/.scbw/bots/$BOTNAME/read" "$HOME/.scbw/bots/$BOTNAME/write"; cp it/sc-docker-support/BWAPI.dll "$HOME/.scbw/bots/$BOTNAME"; cp "$bot/target/"*-with-dependencies.jar "$HOME/.scbw/bots/$BOTNAME/AI"; cp "$bot/bot.json" "$HOME/.scbw/bots/$BOTNAME"; done
scbw.play --headless --bots jbwapibot SittingDuck --timeout 180 --docker_image starcraft:game 2>&1 | grep 'Winner is BotPlayer:jbwapibot:T' || (cat $HOME/.scbw/games/*/logs_0/* && false)
28 changes: 28 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java:
- '8'
- '11'
#- '17'
name: Java ${{ matrix.Java }} sample
steps:
- uses: actions/checkout@v2
- name: Setup java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Build with Maven
run: mvn -B package --file pom.xml
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Also contains a modified version of the pure Java BWEM implementation from [BWAP
- At least [5x](https://github.com/JavaBWAPI/JBWAPI/issues/17) faster compared to BWMirror for primitives as it directly reads the memory mapped client file. Even faster for BWAPI objects as it also avoids type marshalling
- Supports both 32 and 64 bit Java (e.g. [deeplearning4j](https://deeplearning4j.org/) requires 64 bit Java which bwmirror doesn't support).
- BWEM instead of BWTA as map analyser.
- Supports Linux "natively" using [openbw](https://github.com/JavaBWAPI/JBWAPI/pull/73), made possible by by [ByteKeeper](https://github.com/Bytekeeper)
- `Async` support for realtime tournament constraints, made possible by [dgant](https://github.com/dgant)

## Warnings
- A fake BWTA is provided for easier porting from BWMirror, but it translates BWTA calls to their respective BWEM calls, so specific Regions/Chokepoints etc. may differ.
Expand Down Expand Up @@ -105,3 +107,17 @@ You can also ask any further questions on the [SSCAIT Discord](https://discord.g
## Tutorial

If you are a just starting out with bot development, it might be helpful to follow the [tutorial](https://github.com/JavaBWAPI/Java-BWAPI-Tutorial/wiki)!


## Bots

Some bots using [JBWAPI](https://github.com/JavaBWAPI/JBWAPI) (feel free to make add a `Pull Request` to add yours!)

- https://github.com/dgant/PurpleWave
- https://github.com/Ravaelles/Atlantis
- https://github.com/impie66/Kangaroo-Bot

## Linux

If you use Linux you can choose to develop normally and run the `jar` and `starcraft` using [wine](https://www.winehq.org/)`
or try to use `openbw` by following the following [instructions](./build_with_openbw.md)
36 changes: 36 additions & 0 deletions build_with_openbw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Based on: #64

Compiling and running openbw on linux with client support:

```bash
# Download build deps
sudo apt install cmake libsdl2-dev libsdl2-mixer-dev #for ubuntu

# Build openbw with client support
git clone https://github.com/basil-ladder/openbw
git clone -b linux-client-support https://github.com/basil-ladder/bwapi
cd bwapi
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENBW_DIR=../../openbw -DOPENBW_ENABLE_UI=1
make -j4

# Download runtime deps
curl http://www.cs.mun.ca/~dchurchill/starcraftaicomp/files/Starcraft_1161.zip -o starcraft.zip
unzip starcraft.zip patch_rt.mpq BROODAT.MPQ STARDAT.MPQ
mv patch_rt.mpq Patch_rt.mpq && mv BROODAT.MPQ BrooDat.mpq && mv STARDAT.MPQ StarDat.mpq

# Run openbw using the map: Destination 1.1.scx
unzip starcraft.zip "maps/BroodWar/ICCup/ICCup Destination 1.1.scx"

BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP="maps/BroodWar/ICCup/ICCup Destination 1.1.scx" ./bin/BWAPILauncher
```

Compiling and running openbw on macos with client support (not working):

```bash
brew install cmake sdl2 sdl2_mixer gcc

cmake .. -D CMAKE_C_COMPILER=gcc-11 -D CMAKE_CXX_COMPILER=g++-11 -DCMAKE_BUILD_TYPE=Release -DOPENBW_DIR=../../openbw -DOPENBW_ENABLE_UI=1
make -j4
```
4 changes: 4 additions & 0 deletions it/bots/SittingDuck/src/main/java/SittingDuck.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import bwapi.BWClient;
import bwapi.DefaultBWListener;

public class SittingDuck extends DefaultBWListener {
public static void main(String[] args) {
new BWClient(new SittingDuck()).startGame();
}
}
17 changes: 0 additions & 17 deletions it/sc-docker-support/java.dockerfile

This file was deleted.

27 changes: 19 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmh.version>1.26</jmh.version>
<jmh.version>1.33</jmh.version>
</properties>

<build>
Expand Down Expand Up @@ -54,7 +54,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -98,7 +98,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
<configuration>
<additionalOptions>-Xdoclint:none</additionalOptions>
<additionalJOption>-Xdoclint:none</additionalJOption>
Expand All @@ -108,41 +108,52 @@
</reporting>

<dependencies>
<dependency>
<groupId>no.fiken.oss.junixsocket</groupId>
<artifactId>junixsocket-common</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>no.fiken.oss.junixsocket</groupId>
<artifactId>junixsocket-native-common</artifactId>
<version>1.0.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
<version>5.10.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.6.0</version>
<version>5.10.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.5.15</version>
<version>3.12.4</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.17.2</version>
<version>3.21.0</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/bwapi/BWClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package bwapi;

import com.sun.jna.platform.win32.Kernel32;

import java.util.Objects;

/**
Expand Down
Loading

0 comments on commit 44858ae

Please sign in to comment.