Skip to content

Commit 6d8deb0

Browse files
committed
add point methods & implement some Game methods
1 parent e650b06 commit 6d8deb0

File tree

11 files changed

+592
-223
lines changed

11 files changed

+592
-223
lines changed

src/main/java/bwapi/Game.java

Lines changed: 498 additions & 175 deletions
Large diffs are not rendered by default.

src/main/java/bwapi/Player.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public boolean isAlly(final Player player) {
5454
}
5555

5656
public boolean isEnemy(final Player player) {
57-
return !isNeutral() && !isAlly(player);
57+
return !(player.isObserver() || player.isNeutral() || isAlly(player));
5858
}
5959

6060
public boolean isNeutral() {

src/main/java/bwapi/Unit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ public int getDistance(final Position target) {
127127
/////// Compute distance
128128

129129
// retrieve left/top/right/bottom values for calculations
130-
int left = target.getX() - 1;
131-
int top = target.getY() - 1;
132-
int right = target.getX() + 1;
133-
int bottom = target.getY() + 1;
130+
int left = target.x - 1;
131+
int top = target.y - 1;
132+
int right = target.x + 1;
133+
int bottom = target.y + 1;
134134

135135
// compute x distance
136136
int xDist = getLeft() - right;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package bwapi.filter;
2+
3+
//STUB filter class for now
4+
public class UnitFilter {
5+
public UnitFilter(String filterstring){}
6+
}

src/main/java/bwapi/point/Point.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package bwapi.point;
22

3-
public abstract class Point {
3+
import bwapi.Game;
4+
5+
abstract class Point {
46
static final int TILE_WALK_FACTOR = 4; // 32 / 4
57

6-
protected int x, y;
8+
public final int x;
9+
public final int y;
710
private int scalar;
811

912
Point(int x, int y, int type) {
@@ -16,14 +19,6 @@ public double getLength() {
1619
return Math.sqrt(x * x + y * y);
1720
}
1821

19-
public int getX() {
20-
return x;
21-
}
22-
23-
public int getY() {
24-
return y;
25-
}
26-
2722
public String toString() {
2823
return "[" + x + ", " + y + "]";
2924
}
@@ -34,6 +29,15 @@ public boolean equals(Object o) {
3429
return scalar == point.scalar && x == point.x && y == point.y;
3530
}
3631

32+
/**
33+
* Check if the current point is a valid point for the current game
34+
*/
35+
public boolean isValid(final Game game) {
36+
return x >= 0 && y >= 0 &&
37+
scalar * x < game.mapWidth() * TilePosition.SIZE_IN_PIXELS &&
38+
scalar * y < game.mapHeight() * TilePosition.SIZE_IN_PIXELS;
39+
}
40+
3741
public int hashCode() {
3842
//alternatively return Objects.hash(x, y); ?
3943
return (x << 16) + y;

src/main/java/bwapi/point/Position.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Position extends Point{
99

1010
public static final int SIZE_IN_PIXELS = 1;
1111

12-
public Position(int x, int y) {
12+
public Position(final int x, final int y) {
1313
super(x, y, SIZE_IN_PIXELS);
1414
}
1515

@@ -25,8 +25,24 @@ public WalkPosition toWalkPosition() {
2525
return new WalkPosition(x / WalkPosition.SIZE_IN_PIXELS, y / WalkPosition.SIZE_IN_PIXELS);
2626
}
2727

28-
public static Position Invalid = new Position(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
29-
public static Position None = new Position(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
30-
public static Position Unknown = new Position(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
31-
public static Position Origin = new Position(0, 0);
28+
public Position subtract(final Position other) {
29+
return new Position(x - other.x, y - other.y);
30+
}
31+
32+
public Position add(final Position other) {
33+
return new Position(x + other.x, y + other.y);
34+
}
35+
36+
public Position divide(final int divisor) {
37+
return new Position(x / divisor, y / divisor);
38+
}
39+
40+
public Position multiply(final int multiplier) {
41+
return new Position(x * multiplier, y * multiplier);
42+
}
43+
44+
public static final Position Invalid = new Position(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
45+
public static final Position None = new Position(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
46+
public static final Position Unknown = new Position(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
47+
public static final Position Origin = new Position(0, 0);
3248
}

src/main/java/bwapi/point/TilePosition.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class TilePosition extends Point{
44

55
public static final int SIZE_IN_PIXELS = 32;
66

7-
public TilePosition(int x, int y) {
7+
public TilePosition(final int x, final int y) {
88
super(x, y, SIZE_IN_PIXELS);
99
}
1010

@@ -16,8 +16,24 @@ public WalkPosition toWalkPosition() {
1616
return new WalkPosition(x * TILE_WALK_FACTOR, y * TILE_WALK_FACTOR);
1717
}
1818

19-
public static TilePosition Invalid = new TilePosition(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
20-
public static TilePosition None = new TilePosition(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
21-
public static TilePosition Unknown = new TilePosition(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
22-
public static TilePosition Origin = new TilePosition(0, 0);
19+
public TilePosition subtract(final TilePosition other) {
20+
return new TilePosition(x - other.x, y - other.y);
21+
}
22+
23+
public TilePosition add(final TilePosition other) {
24+
return new TilePosition(x + other.x, y + other.y);
25+
}
26+
27+
public TilePosition divide(final int divisor) {
28+
return new TilePosition(x / divisor, y / divisor);
29+
}
30+
31+
public TilePosition multiply(final int multiplier) {
32+
return new TilePosition(x * multiplier, y * multiplier);
33+
}
34+
35+
public static final TilePosition Invalid = new TilePosition(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
36+
public static final TilePosition None = new TilePosition(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
37+
public static final TilePosition Unknown = new TilePosition(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
38+
public static final TilePosition Origin = new TilePosition(0, 0);
2339
}

src/main/java/bwapi/point/WalkPosition.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class WalkPosition extends Point{
44

55
public static final int SIZE_IN_PIXELS = 8;
66

7-
public WalkPosition(int x, int y) {
7+
public WalkPosition(final int x, final int y) {
88
super(x, y, SIZE_IN_PIXELS);
99
}
1010

@@ -16,8 +16,24 @@ public TilePosition toTilePosition() {
1616
return new TilePosition(x / TILE_WALK_FACTOR, y / TILE_WALK_FACTOR);
1717
}
1818

19-
public static WalkPosition Invalid = new WalkPosition(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
20-
public static WalkPosition None = new WalkPosition(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
21-
public static WalkPosition Unknown = new WalkPosition(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
22-
public static WalkPosition Origin = new WalkPosition(0,0);
19+
public WalkPosition subtract(final WalkPosition other) {
20+
return new WalkPosition(x - other.x, y - other.y);
21+
}
22+
23+
public WalkPosition add(final WalkPosition other) {
24+
return new WalkPosition(x + other.x, y + other.y);
25+
}
26+
27+
public WalkPosition divide(final int divisor) {
28+
return new WalkPosition(x / divisor, y / divisor);
29+
}
30+
31+
public WalkPosition multiply(final int multiplier) {
32+
return new WalkPosition(x * multiplier, y * multiplier);
33+
}
34+
35+
public static final WalkPosition Invalid = new WalkPosition(32000 / SIZE_IN_PIXELS, 32000 / SIZE_IN_PIXELS);
36+
public static final WalkPosition None = new WalkPosition(32000 / SIZE_IN_PIXELS, 32032 / SIZE_IN_PIXELS);
37+
public static final WalkPosition Unknown = new WalkPosition(32000 / SIZE_IN_PIXELS, 32064 / SIZE_IN_PIXELS);
38+
public static final WalkPosition Origin = new WalkPosition(0,0);
2339
}

src/main/java/bwapi/values/Flag.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ public enum Flag {
44
CompleteMapInformation(0),
55
UserInput(1);
66

7-
private int value;
7+
public final int value;
88

9-
public int getValue(){
10-
return value;
11-
}
12-
13-
Flag(int value){
9+
Flag(final int value){
1410
this.value = value;
1511
}
1612
}

src/main/java/bwapi/values/Key.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,9 @@ public enum Key {
230230
K_PA1(253),
231231
K_OEM_CLEAR(254);
232232

233-
private int value;
233+
public final int value;
234234

235-
public int getValue(){
236-
return value;
237-
}
238-
239-
Key(int value){
235+
Key(final int value){
240236
this.value = value;
241237
}
242238
}

0 commit comments

Comments
 (0)