bwmirror 2.2
This commit is contained in:
parent
2a3bb21681
commit
877663c34f
Binary file not shown.
BIN
bwmirror_v2_2.jar
Normal file
BIN
bwmirror_v2_2.jar
Normal file
Binary file not shown.
|
@ -10,7 +10,8 @@ namespace BWTA
|
|||
void readMap();
|
||||
void analyze();
|
||||
void computeDistanceTransform();
|
||||
void balanceAnalysis();
|
||||
void balanceAnalysis();
|
||||
void cleanMemory();
|
||||
|
||||
int getMaxDistanceTransform();
|
||||
RectangleArray<int>* getDistanceTransformMap();
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
#include <BWAPI.h>
|
||||
namespace BWTA
|
||||
{
|
||||
class Region;
|
||||
class BaseLocation
|
||||
{
|
||||
public:
|
||||
virtual BWAPI::Position getPosition() const=0;
|
||||
virtual BWAPI::TilePosition getTilePosition() const=0;
|
||||
class Region;
|
||||
class BaseLocation
|
||||
{
|
||||
public:
|
||||
virtual ~BaseLocation(){};
|
||||
virtual BWAPI::Position getPosition() const = 0;
|
||||
virtual BWAPI::TilePosition getTilePosition() const = 0;
|
||||
|
||||
virtual Region* getRegion() const=0;
|
||||
virtual Region* getRegion() const = 0;
|
||||
|
||||
virtual int minerals() const=0;
|
||||
virtual int gas() const=0;
|
||||
virtual int minerals() const = 0;
|
||||
virtual int gas() const = 0;
|
||||
|
||||
virtual const BWAPI::Unitset &getMinerals()=0;
|
||||
virtual const BWAPI::Unitset &getStaticMinerals() const=0;
|
||||
virtual const BWAPI::Unitset &getGeysers() const=0;
|
||||
|
||||
virtual double getGroundDistance(BaseLocation* other) const=0;
|
||||
virtual double getAirDistance(BaseLocation* other) const=0;
|
||||
virtual const BWAPI::Unitset &getMinerals() = 0;
|
||||
virtual const BWAPI::Unitset &getStaticMinerals() const = 0;
|
||||
virtual const BWAPI::Unitset &getGeysers() const = 0;
|
||||
|
||||
virtual bool isIsland() const=0;
|
||||
virtual bool isMineralOnly() const=0;
|
||||
virtual bool isStartLocation() const=0;
|
||||
};
|
||||
virtual double getGroundDistance(BaseLocation* other) const = 0;
|
||||
virtual double getAirDistance(BaseLocation* other) const = 0;
|
||||
|
||||
virtual bool isIsland() const = 0;
|
||||
virtual bool isMineralOnly() const = 0;
|
||||
virtual bool isStartLocation() const = 0;
|
||||
};
|
||||
}
|
|
@ -3,13 +3,14 @@
|
|||
#include <BWAPI.h>
|
||||
namespace BWTA
|
||||
{
|
||||
class Region;
|
||||
class Chokepoint
|
||||
{
|
||||
public:
|
||||
virtual const std::pair<Region*,Region*>& getRegions() const=0;
|
||||
virtual const std::pair<BWAPI::Position,BWAPI::Position>& getSides() const=0;
|
||||
virtual BWAPI::Position getCenter() const=0;
|
||||
virtual double getWidth() const=0;
|
||||
};
|
||||
class Region;
|
||||
class Chokepoint
|
||||
{
|
||||
public:
|
||||
virtual ~Chokepoint(){};
|
||||
virtual const std::pair<Region*, Region*>& getRegions() const = 0;
|
||||
virtual const std::pair<BWAPI::Position, BWAPI::Position>& getSides() const = 0;
|
||||
virtual BWAPI::Position getCenter() const = 0;
|
||||
virtual double getWidth() const = 0;
|
||||
};
|
||||
}
|
|
@ -17,7 +17,9 @@ namespace BWTA
|
|||
RectangleArray(unsigned int width = 1, unsigned int height = 1, Type* data = NULL);
|
||||
/** Copy constructor */
|
||||
RectangleArray(const RectangleArray<Type>& rectangleArray);
|
||||
/** Destorys the array and deletes all content of array. */
|
||||
/** Assignment operator */
|
||||
const RectangleArray& operator=(const RectangleArray<Type>& rectangleArray);
|
||||
/** Destroys the array and deletes all content of array. */
|
||||
~RectangleArray(void);
|
||||
/**
|
||||
* Gets the width of the array.
|
||||
|
@ -47,7 +49,6 @@ namespace BWTA
|
|||
*/
|
||||
void setItem(unsigned int x, unsigned int y, Type *item);
|
||||
void resize(unsigned int width, unsigned int height);
|
||||
void printToFile(FILE* f);
|
||||
void saveToFile(const std::string& fileName);
|
||||
/** Sets all fields of the array to the specified value */
|
||||
void setTo(const Type& value);
|
||||
|
@ -109,7 +110,7 @@ namespace BWTA
|
|||
for (unsigned int position = 0;i < width; i ++,position += height)
|
||||
columns[i] = &this->data[position];
|
||||
}
|
||||
//---------------------------------------------- CONSTRUCTOR -----------------------------------------------
|
||||
//-------------------------------------------- COPY CONSTRUCTOR --------------------------------------------
|
||||
template <class Type>
|
||||
RectangleArray<Type>::RectangleArray(const RectangleArray<Type>& rectangleArray)
|
||||
:owner(true)
|
||||
|
@ -124,6 +125,22 @@ namespace BWTA
|
|||
columns[i] = &data[position];
|
||||
memcpy(this->data, rectangleArray.data, sizeof(Type)*this->getWidth()*this->getHeight());
|
||||
}
|
||||
//------------------------------------------ ASSIGNMENT OPERATOR -------------------------------------------
|
||||
template <class Type>
|
||||
const RectangleArray<Type>& RectangleArray<Type>::operator=(const RectangleArray<Type>& rectangleArray)
|
||||
{
|
||||
this->setWidth(rectangleArray.getWidth());
|
||||
this->setHeight(rectangleArray.getHeight());
|
||||
this->owner = true;
|
||||
this->data = new Type[this->getWidth()*this->getHeight()];
|
||||
columns = new Type*[this->getWidth()];
|
||||
|
||||
unsigned int i = 0;
|
||||
for (unsigned int position = 0; i < width; i++, position += height)
|
||||
columns[i] = &data[position];
|
||||
memcpy(this->data, rectangleArray.data, sizeof(Type)*this->getWidth()*this->getHeight());
|
||||
return *this;
|
||||
}
|
||||
//----------------------------------------------- DESTRUCTOR -----------------------------------------------
|
||||
template <class Type>
|
||||
RectangleArray<Type>::~RectangleArray(void)
|
||||
|
@ -211,29 +228,21 @@ namespace BWTA
|
|||
for (unsigned int position = 0;i < this->width; i ++,position += this->height)
|
||||
columns[i] = &data[position];
|
||||
}
|
||||
//--------------------------------------------- PRINT TO FILE ----------------------------------------------
|
||||
template <class Type>
|
||||
void RectangleArray<Type>::printToFile(FILE* f)
|
||||
{
|
||||
for (unsigned int y = 0; y < this->getHeight(); y++)
|
||||
{
|
||||
for (unsigned int x = 0; x < this->getWidth(); x++)
|
||||
{
|
||||
char ch = this->getColumn(x)[y];
|
||||
fprintf_s(f, "%c", ch);
|
||||
}
|
||||
fprintf_s(f, "\n");
|
||||
}
|
||||
}
|
||||
//---------------------------------------------- SAVE TO FILE ----------------------------------------------
|
||||
template <class Type>
|
||||
void RectangleArray<Type>::saveToFile(const std::string& fileName)
|
||||
{
|
||||
FILE* f = fopen(fileName.c_str(), "wt");
|
||||
if (!f)
|
||||
exit(1);
|
||||
this->printToFile(f);
|
||||
fclose(f);
|
||||
std::ofstream outputFile(fileName);
|
||||
if (!outputFile)
|
||||
exit(1);
|
||||
|
||||
for (unsigned int y = 0; y < this->getHeight(); ++y) {
|
||||
for (unsigned int x = 0; x < this->getWidth(); ++x) {
|
||||
outputFile << this->getColumn(x)[y];
|
||||
}
|
||||
outputFile << std::endl;
|
||||
}
|
||||
outputFile.close();
|
||||
}
|
||||
//------------------------------------------------- SET TO -------------------------------------------------
|
||||
template <class Type>
|
||||
|
|
|
@ -4,17 +4,18 @@
|
|||
#include <BWTA/Polygon.h>
|
||||
namespace BWTA
|
||||
{
|
||||
class Chokepoint;
|
||||
class BaseLocation;
|
||||
class Region
|
||||
{
|
||||
public:
|
||||
virtual const Polygon& getPolygon() const=0;
|
||||
virtual const BWAPI::Position& getCenter() const=0;
|
||||
virtual const std::set<Chokepoint*>& getChokepoints() const=0;
|
||||
virtual const std::set<BaseLocation*>& getBaseLocations() const=0;
|
||||
virtual bool isReachable(Region* region) const=0;
|
||||
virtual const std::set<Region*>& getReachableRegions() const=0;
|
||||
virtual const int getMaxDistance() const=0;
|
||||
};
|
||||
class Chokepoint;
|
||||
class BaseLocation;
|
||||
class Region
|
||||
{
|
||||
public:
|
||||
virtual ~Region() {};
|
||||
virtual const Polygon& getPolygon() const = 0;
|
||||
virtual const BWAPI::Position& getCenter() const = 0;
|
||||
virtual const std::set<Chokepoint*>& getChokepoints() const = 0;
|
||||
virtual const std::set<BaseLocation*>& getBaseLocations() const = 0;
|
||||
virtual bool isReachable(Region* region) const = 0;
|
||||
virtual const std::set<Region*>& getReachableRegions() const = 0;
|
||||
virtual const int getMaxDistance() const = 0;
|
||||
};
|
||||
}
|
19
c4/impl.cpp
19
c4/impl.cpp
|
@ -5957,8 +5957,8 @@ jclass listCls = FindCachedClass(env, "java/util/ArrayList");
|
|||
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()V");
|
||||
jobject result = env->NewObject(listCls, listConsID);
|
||||
jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z");
|
||||
jclass elemClass = FindCachedClass(env, "bwta/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwta/Unit;");
|
||||
jclass elemClass = FindCachedClass(env, "bwapi/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwapi/Unit;");
|
||||
for(Unitset::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){
|
||||
const Unit elem_ptr = *it;
|
||||
jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ;
|
||||
|
@ -5973,8 +5973,8 @@ jclass listCls = FindCachedClass(env, "java/util/ArrayList");
|
|||
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()V");
|
||||
jobject result = env->NewObject(listCls, listConsID);
|
||||
jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z");
|
||||
jclass elemClass = FindCachedClass(env, "bwta/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwta/Unit;");
|
||||
jclass elemClass = FindCachedClass(env, "bwapi/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwapi/Unit;");
|
||||
for(Unitset::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){
|
||||
const Unit elem_ptr = *it;
|
||||
jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ;
|
||||
|
@ -5989,8 +5989,8 @@ jclass listCls = FindCachedClass(env, "java/util/ArrayList");
|
|||
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()V");
|
||||
jobject result = env->NewObject(listCls, listConsID);
|
||||
jmethodID addMethodID = FindCachedMethod(env, listCls, "add", "(Ljava/lang/Object;)Z");
|
||||
jclass elemClass = FindCachedClass(env, "bwta/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwta/Unit;");
|
||||
jclass elemClass = FindCachedClass(env, "bwapi/Unit");
|
||||
jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, "get", "(J)Lbwapi/Unit;");
|
||||
for(Unitset::const_iterator it = cresult.begin(); it != cresult.end(); it++ ){
|
||||
const Unit elem_ptr = *it;
|
||||
jobject elem = env->CallStaticObjectMethod(elemClass, getMethodID, (long)elem_ptr) ;
|
||||
|
@ -6032,6 +6032,9 @@ BWTA::computeDistanceTransform();
|
|||
JNIEXPORT void JNICALL Java_bwta_BWTA_balanceAnalysis(JNIEnv * env, jclass jclz){
|
||||
BWTA::balanceAnalysis();
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_bwta_BWTA_cleanMemory(JNIEnv * env, jclass jclz){
|
||||
BWTA::cleanMemory();
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_bwta_BWTA_getMaxDistanceTransform(JNIEnv * env, jclass jclz){
|
||||
return BWTA::getMaxDistanceTransform();
|
||||
}
|
||||
|
@ -6224,7 +6227,7 @@ TilePosition cObj((int)env->GetIntField(p_cObj, FindCachedField(env, env->GetObj
|
|||
targets.insert(cObj);
|
||||
}
|
||||
std::pair<TilePosition, double> cresult = BWTA::getNearestTilePosition(start, targets);
|
||||
jclass firstElemClass = FindCachedClass(env, "bwta/TilePosition");
|
||||
jclass firstElemClass = FindCachedClass(env, "bwapi/TilePosition");
|
||||
jmethodID firstElemConsID = FindCachedMethod(env, firstElemClass, "<init>", "(II)V");
|
||||
jclass secondElemClass = FindCachedClass(env, "java/lang/Double");
|
||||
jmethodID secondElemConsID = FindCachedMethod(env, secondElemClass, "<init>", "(D)V");
|
||||
|
@ -6254,7 +6257,7 @@ jclass listCls = FindCachedClass(env, "java/util/HashMap");
|
|||
jmethodID listConsID = FindCachedMethod(env, listCls, "<init>", "()V");
|
||||
jobject result = env->NewObject(listCls, listConsID);
|
||||
jmethodID addMethodID = FindCachedMethod(env, listCls, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
jclass keyElemClass = FindCachedClass(env, "bwta/TilePosition");
|
||||
jclass keyElemClass = FindCachedClass(env, "bwapi/TilePosition");
|
||||
jmethodID keyElemConsID = FindCachedMethod(env, keyElemClass, "<init>", "(II)V");
|
||||
jclass valueElemClass = FindCachedClass(env, "java/lang/Double");
|
||||
jmethodID valueElemConsID = FindCachedMethod(env, valueElemClass, "<init>", "(D)V");
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -9091,6 +9091,14 @@ JNIEXPORT void JNICALL Java_bwta_BWTA_computeDistanceTransform
|
|||
JNIEXPORT void JNICALL Java_bwta_BWTA_balanceAnalysis
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: bwta_BWTA
|
||||
* Method: cleanMemory
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_bwta_BWTA_cleanMemory
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: bwta_BWTA
|
||||
* Method: getMaxDistanceTransform
|
||||
|
|
|
@ -56,7 +56,7 @@ public class Mirror {
|
|||
|
||||
private static final boolean EXTRACT_JAR = true;
|
||||
|
||||
private static final String VERSION = "2_1";
|
||||
private static final String VERSION = "2_2";
|
||||
|
||||
static {
|
||||
String arch = System.getProperty("os.arch");
|
||||
|
|
|
@ -22,6 +22,8 @@ public class BWTA {
|
|||
|
||||
public static native void balanceAnalysis();
|
||||
|
||||
public static native void cleanMemory();
|
||||
|
||||
public static native int getMaxDistanceTransform();
|
||||
|
||||
public static native List<Region> getRegions();
|
||||
|
|
|
@ -39,6 +39,14 @@ JNIEXPORT void JNICALL Java_bwta_BWTA_computeDistanceTransform
|
|||
JNIEXPORT void JNICALL Java_bwta_BWTA_balanceAnalysis
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: bwta_BWTA
|
||||
* Method: cleanMemory
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_bwta_BWTA_cleanMemory
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: bwta_BWTA
|
||||
* Method: getMaxDistanceTransform
|
||||
|
|
|
@ -56,7 +56,7 @@ public class Mirror {
|
|||
|
||||
private static final boolean EXTRACT_JAR = true;
|
||||
|
||||
private static final String VERSION = "2_1";
|
||||
private static final String VERSION = "2_2";
|
||||
|
||||
static {
|
||||
String arch = System.getProperty("os.arch");
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -43,7 +43,7 @@ public class JavaContext {
|
|||
}
|
||||
|
||||
public String getPackageName(String javaRetType) {
|
||||
if (packageName.equals("bwta") && (javaRetType.equals("Position") || javaRetType.equals("TilePosition"))) {
|
||||
if (packageName.equals("bwta") && (javaRetType.equals("Position") || javaRetType.equals("Unit") || javaRetType.equals("TilePosition"))) {
|
||||
return "bwapi";
|
||||
}
|
||||
return packageName;
|
||||
|
|
|
@ -246,7 +246,7 @@ public class CallImplementer {
|
|||
|
||||
|
||||
//Key static part
|
||||
String keyPackageName = javaContext.getPackageName();
|
||||
String keyPackageName = javaContext.getPackageName(javaKeyType);
|
||||
if (javaContext.isPrimitive(javaKeyType)) {
|
||||
keyPackageName = "java/lang";
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ public class CallImplementer {
|
|||
}
|
||||
|
||||
//Value static part
|
||||
String valuePackageName = javaContext.getPackageName();
|
||||
String valuePackageName = javaContext.getPackageName(javaValueType);
|
||||
if (javaContext.isPrimitive(javaValueType)) {
|
||||
valuePackageName = "java/lang";
|
||||
}
|
||||
|
@ -337,9 +337,9 @@ public class CallImplementer {
|
|||
"jobject result = env->NewObject(listCls, listConsID);");
|
||||
|
||||
out.println("jmethodID addMethodID = FindCachedMethod(env, listCls, \"add\", \"(Ljava/lang/Object;)Z\");");
|
||||
out.println("jclass elemClass = FindCachedClass(env, \"" + javaContext.getPackageName() + "/" + classGenericType + "\");");
|
||||
out.println("jclass elemClass = FindCachedClass(env, \"" + javaContext.getPackageName(classGenericType) + "/" + classGenericType + "\");");
|
||||
if (!javaContext.isValueType(genericType)) {
|
||||
out.println("jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, \"get\", \"(J)L" + javaContext.getPackageName() + "/" + classGenericType + ";\");");
|
||||
out.println("jmethodID getMethodID = FindCachedMethodStatic(env, elemClass, \"get\", \"(J)L" + javaContext.getPackageName(classGenericType) + "/" + classGenericType + ";\");");
|
||||
} else {
|
||||
out.println("jmethodID elemConsID = FindCachedMethod(env, elemClass, \"<init>\", \"(" + javaContext.copyConstructor(genericType) + ")V\");");
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ public class CallImplementer {
|
|||
}
|
||||
|
||||
//First static part
|
||||
String firstPackageName = javaContext.getPackageName();
|
||||
String firstPackageName = javaContext.getPackageName(javaFirstType);
|
||||
if (javaContext.isPrimitive(javaFirstType)) {
|
||||
firstPackageName = "java/lang";
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ public class CallImplementer {
|
|||
}
|
||||
|
||||
//Second static part
|
||||
String secondPackageName = javaContext.getPackageName();
|
||||
String secondPackageName = javaContext.getPackageName(javaSecondType);
|
||||
if (javaContext.isPrimitive(javaSecondType)) {
|
||||
secondPackageName = "java/lang";
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package test.api;
|
|||
import bwapi.*;
|
||||
import bwapi.Text.Size.Enum;
|
||||
import bwta.BWTA;
|
||||
import bwta.BaseLocation;
|
||||
import bwta.Chokepoint;
|
||||
import util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -47,6 +49,15 @@ public class TestBot1 {
|
|||
|
||||
StringBuilder units = new StringBuilder("My units:\n");
|
||||
|
||||
for(BaseLocation baseLocation : BWTA.getBaseLocations()){
|
||||
//System.out.println(baseLocation.getPosition());
|
||||
//System.out.println(baseLocation.getTilePosition());
|
||||
}
|
||||
|
||||
for(Chokepoint chokepoint : BWTA.getChokepoints()){
|
||||
//System.out.println(chokepoint.getCenter());
|
||||
}
|
||||
|
||||
for (Player player : game.getPlayers()) {
|
||||
// System.out.println(player.getName());
|
||||
for (Unit enemyUnit : player.getUnits()) {
|
||||
|
|
Reference in a new issue