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
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
[![Build Status](https://travis-ci.org/JavaBWAPI/JBWAPI.svg?branch=develop)](https://travis-ci.org/JavaBWAPI/JBWAPI)[![Total alerts](https://img.shields.io/lgtm/alerts/g/JavaBWAPI/JBWAPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JavaBWAPI/JBWAPI/alerts/)[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/JavaBWAPI/JBWAPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JavaBWAPI/JBWAPI/context:java)
# JBWAPI

Pure Java [bwapi](https://github.com/bwapi/bwapi) 4.4.0 client implementation backed by [N00byEdge](https://github.com/N00byEdge)'s [JavaBWAPIBackend](https://github.com/N00byEdge/JavaBWAPIBackend) idea and automated by [Bytekeeper](https://github.com/Bytekeeper).

Also contains a modified version of the pure Java BWEM implementation from [BWAPI4J](https://github.com/OpenBW/BWAPI4J).

## goals
## Goals

- Have a similar (Java) interface to BWMirror to make porting BWMirror bots easy without all the DLL and JNI hassle and overhead.
- Stay as updated as possible with the BWAPI releases
- Stay as updated as possible with the BWAPI releases.

## Advantages

## advantages
- no dependency on external DLL's
- 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
- No dependency on external DLL's.
- 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.

## warnings
- JBWAPI by default has Lateny Compensation disabled (and at the moment has no LatCom at all).
- A fake BWTA is provided for easier porting, but it translates BWTA calls to their respective BWEM calls, so specific Regions/Chokepoints etc. may differ.
## 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.

## usage
**maven**
## Usage

Add JitPack as a repository
**Maven**

Add JitPack as a repository:
```
<repositories>
<repository>
Expand All @@ -30,7 +33,7 @@ Add JitPack as a repository
</repository>
</repositories>
```
Add JBWAPI as a dependecy
Add JBWAPI as a dependency:
```
<dependency>
<groupId>com.github.JavaBWAPI</groupId>
Expand All @@ -39,9 +42,9 @@ Add JBWAPI as a dependecy
</dependency>
```

**gradle**
**Gradle**

Add JitPack as a repository
Add JitPack as a repository:
```
allprojects {
repositories {
Expand All @@ -50,31 +53,31 @@ allprojects {
}
}
```
Add JBWAPI as a dependency
Add JBWAPI as a dependency:
```
dependencies {
implementation 'com.github.JavaBWAPI:JBWAPI:0.8'
}
```

**jar**
**Jar**

Alternatively add the latest .jar from the [releases](https://github.com/JavaBWAPI/JBWAPI/releases) page to your project.

## compilation
## Compilation

`mvnw.cmd package`

or if you already have maven installed

`mvn package`

## documentation
## Documentation

The API documentation can be found [here](https://javabwapi.github.io/JBWAPI/).

You can also ask any further questions on the [SSCAIT Discord](https://discord.gg/DqvHsq9)

## tutorial
## 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)!

38 changes: 38 additions & 0 deletions src/main/java/bwapi/Cache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package bwapi;


class Cache<T> {
private int frame = -1;
private T obj;

void set(T obj, int frame) {
this.frame = frame;
this.obj = obj;
}

boolean valid(int currentFrame) {
return frame == currentFrame;
}

T get() {
return obj;
}
}

class IntegerCache extends Cache<Integer> {

void setOrAdd(int obj, int frame) {
if (valid(frame)) {
set(get() + obj, frame);
}
else {
set(obj, frame);
}
}
}

class BooleanCache extends Cache<Boolean>{}
class OrderCache extends Cache<Order>{}
class UnitTypeCache extends Cache<UnitType>{}
class UpgradeTypeCache extends Cache<UpgradeType>{}
class TechTypeCache extends Cache<TechType>{}
Loading