Skip to content

Commit 2e944e4

Browse files
author
Bytekeeper
committed
Reformatting and lint fixes.
1 parent 7e747d2 commit 2e944e4

13 files changed

+106
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can also use the `RetreatBehavior` to make some or all units run away instea
140140
A DBScan based clustering algorithm.
141141
* Stable clustering: Unless a cluster is split up, units will end up in the same cluster as in previous runs
142142
* Iterative: Instead of assigning all units to clusters at once, do it iteratively. Once done,
143-
it the clustering restarts and the previous result can be accessed.
143+
the clustering restarts and the previous result can be accessed.
144144

145145
### UnitFinder
146146
A simple utility class to make queries for units within a radius/square at some position.

src/main/java/org/bk/ass/AttackerBehavior.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public boolean simUnit(
3838
for (int i = enemies.size() - 1; i >= 0; i--) {
3939
Agent enemy = enemies.get(i);
4040
Weapon wpn = agent.weaponVs(enemy);
41-
if (enemy.healthShifted >= 1 && wpn.damageShifted != 0 && enemy.detected && !enemy.isStasised) {
41+
if (enemy.healthShifted >= 1
42+
&& wpn.damageShifted != 0
43+
&& enemy.detected
44+
&& !enemy.isStasised) {
4245
int distanceSquared = distanceSquared(agent, enemy);
4346
if (distanceSquared >= wpn.minRangeSquared && distanceSquared < selectedDistanceSquared) {
4447
selectedDistanceSquared = distanceSquared;

src/main/java/org/bk/ass/Evaluator.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.bk.ass;
22

3-
import static java.lang.Math.max;
4-
53
import java.util.ArrayList;
64
import java.util.Collection;
75
import java.util.List;
86

7+
import static java.lang.Math.max;
8+
99
/**
1010
* Used to get a rough guess for combat outcome. Doesn't provide as much detail as the {@link
1111
* Simulator}. Estimates [0-0.5) =&gt; not so good for force A. Estimates (0.5-1] =&gt; not bad for
@@ -49,18 +49,16 @@ public double evaluate(Collection<Agent> agentsA, Collection<Agent> agentsB) {
4949
}
5050
double evalA =
5151
(double) damageToA
52-
/ (finalAgentsA
53-
.stream()
54-
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
55-
.sum()
56-
+ EPS);
52+
/ (finalAgentsA.stream()
53+
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
54+
.sum()
55+
+ EPS);
5756
double evalB =
5857
(double) damageToB
59-
/ (finalAgentsB
60-
.stream()
61-
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
62-
.sum()
63-
+ EPS);
58+
/ (finalAgentsB.stream()
59+
.mapToDouble(a -> a.getHealth() + a.getShields() * parameters.shieldScale)
60+
.sum()
61+
+ EPS);
6462
// eval is a rough estimate on how many units where lost.
6563
// Directly comparing is bad since one might have lost more agents than he had.
6664
// So we just multiply with the enemy count and compare that instead.
@@ -72,8 +70,7 @@ public double evaluate(Collection<Agent> agentsA, Collection<Agent> agentsB) {
7270
private int regeneration(Collection<Agent> agents) {
7371
// Subtract 1 to prevent counting selfheal
7472
int healables = (int) (agents.stream().filter(it -> it.isOrganic).count() - 1);
75-
return agents
76-
.stream()
73+
return agents.stream()
7774
.mapToInt(
7875
a -> {
7976
int healed = 0;
@@ -246,8 +243,8 @@ public Parameters(double[] source) {
246243

247244
public Parameters() {
248245
this(
249-
new double[]{
250-
2.812625, 0.504625, 0.053, 1.2545, 2.27975, 1.86025, 976.7565, 513.109625, 586.87675
246+
new double[]{
247+
2.812625, 0.504625, 0.053, 1.2545, 2.27975, 1.86025, 976.7565, 513.109625, 586.87675
251248
});
252249
}
253250
}

src/main/java/org/bk/ass/PositionOutOfBoundsException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
public class PositionOutOfBoundsException extends RuntimeException {
77

88
PositionOutOfBoundsException(String message) {
9-
super(message);
10-
}
9+
super(message);
10+
}
1111
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.bk.ass;
22

33
public enum SplashType {
4-
RADIAL_SPLASH, RADIAL_ENEMY_SPLASH, LINE_SPLASH, BOUNCE, IRRELEVANT;
4+
RADIAL_SPLASH,
5+
RADIAL_ENEMY_SPLASH,
6+
LINE_SPLASH,
7+
BOUNCE,
8+
IRRELEVANT
59
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.bk.ass;
22

33
public enum UnitSize {
4-
SMALL, MEDIUM, LARGE, IRRELEVANT;
4+
SMALL,
5+
MEDIUM,
6+
LARGE,
7+
IRRELEVANT
58
}

src/main/java/org/bk/ass/cluster/StableDBScanner.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public StableDBScanner<U> scan(int maxMarkedElements) {
129129

130130
private void updateElementClusters() {
131131
elementToCluster =
132-
elementToWrapper
133-
.entrySet()
134-
.stream()
132+
elementToWrapper.entrySet().stream()
135133
.collect(
136134
Collectors.toMap(
137135
Entry::getKey,
@@ -186,9 +184,7 @@ private void reset() {
186184
}
187185

188186
private List<WrappedElement<U>> elementsWithinRadius(WrappedElement<U> q) {
189-
return inRadiusFinder
190-
.apply(q.element)
191-
.stream()
187+
return inRadiusFinder.apply(q.element).stream()
192188
.map(u -> elementToWrapper.get(u))
193189
.filter(Objects::nonNull) // Yet unknown elements might be returned, ignore them
194190
.collect(Collectors.toList());

src/main/java/org/bk/ass/info/BWAPI4JUnitInfo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.bk.ass.info;
22

3-
43
import org.openbw.bwapi4j.type.UnitType;
54

65
public class BWAPI4JUnitInfo {
6+
private BWAPI4JUnitInfo() {
7+
// Utility class
8+
}
79

810
public static int stopFrames(UnitType unitType) {
911
switch (unitType) {
@@ -38,5 +40,4 @@ public static int stopFrames(UnitType unitType) {
3840
return 2;
3941
}
4042
}
41-
4243
}
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
package org.bk.ass.info;
22

3-
43
import bwapi.UnitType;
54

65
public class BWMirrorUnitInfo {
6+
private BWMirrorUnitInfo() {
7+
// Utility class
8+
}
79

8-
public static int stopFrames(UnitType unitType) {
9-
switch (unitType) {
10-
case Terran_Goliath:
11-
case Terran_Siege_Tank_Tank_Mode:
12-
case Terran_Siege_Tank_Siege_Mode:
13-
case Protoss_Reaver:
14-
return 1;
15-
case Terran_Ghost:
16-
case Zerg_Hydralisk:
17-
return 3;
18-
case Protoss_Arbiter:
19-
case Zerg_Zergling:
20-
return 4;
21-
case Protoss_Zealot:
22-
case Protoss_Dragoon:
23-
return 7;
24-
case Terran_Marine:
25-
case Terran_Firebat:
26-
case Protoss_Corsair:
27-
return 8;
28-
case Protoss_Dark_Templar:
29-
case Zerg_Devourer:
30-
return 9;
31-
case Zerg_Ultralisk:
32-
return 14;
33-
case Protoss_Archon:
34-
return 15;
35-
case Terran_Valkyrie:
36-
return 40;
37-
default:
38-
return 2;
39-
}
10+
public static int stopFrames(UnitType unitType) {
11+
switch (unitType) {
12+
case Terran_Goliath:
13+
case Terran_Siege_Tank_Tank_Mode:
14+
case Terran_Siege_Tank_Siege_Mode:
15+
case Protoss_Reaver:
16+
return 1;
17+
case Terran_Ghost:
18+
case Zerg_Hydralisk:
19+
return 3;
20+
case Protoss_Arbiter:
21+
case Zerg_Zergling:
22+
return 4;
23+
case Protoss_Zealot:
24+
case Protoss_Dragoon:
25+
return 7;
26+
case Terran_Marine:
27+
case Terran_Firebat:
28+
case Protoss_Corsair:
29+
return 8;
30+
case Protoss_Dark_Templar:
31+
case Zerg_Devourer:
32+
return 9;
33+
case Zerg_Ultralisk:
34+
return 14;
35+
case Protoss_Archon:
36+
return 15;
37+
case Terran_Valkyrie:
38+
return 40;
39+
default:
40+
return 2;
4041
}
42+
}
4143
}

src/main/java/org/bk/ass/path/AbstractPathFinder.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.bk.ass.path;
22

3-
import static java.lang.Math.abs;
4-
import static java.lang.Math.max;
5-
import static java.lang.Math.min;
6-
73
import java.util.ArrayList;
84
import java.util.Collections;
95
import java.util.List;
106
import java.util.PriorityQueue;
117

8+
import static java.lang.Math.*;
9+
1210
abstract class AbstractPathFinder {
1311
private final Node CLOSED = new Node();
1412
private final PriorityQueue<Node> openQueue = new PriorityQueue<>();
@@ -59,26 +57,26 @@ Result searchFrom(Position start) {
5957
addToOpenSet(best, jumpHorizontal(p.x, p.y, dx));
6058
addToOpenSet(best, jumpVertical(p.x, p.y, dy));
6159
addToOpenSet(best, jumpDiag(p.x, p.y, dx, dy));
62-
if (!map.get(p.x - dx, p.y)) {
60+
if (!map.get(p.x - dx, p.y)) {
6361
addToOpenSet(best, jumpDiag(p.x, p.y, -dx, dy));
6462
}
65-
if (!map.get(p.x, p.y - dy)) {
63+
if (!map.get(p.x, p.y - dy)) {
6664
addToOpenSet(best, jumpDiag(p.x, p.y, dx, -dy));
6765
}
6866
} else if (dx != 0) {
6967
addToOpenSet(best, jumpHorizontal(p.x, p.y, dx));
70-
if (!map.get(p.x, p.y - 1)) {
68+
if (!map.get(p.x, p.y - 1)) {
7169
addToOpenSet(best, jumpDiag(p.x, p.y, dx, -1));
7270
}
73-
if (!map.get(p.x, p.y + 1)) {
71+
if (!map.get(p.x, p.y + 1)) {
7472
addToOpenSet(best, jumpDiag(p.x, p.y, dx, 1));
7573
}
7674
} else {
7775
addToOpenSet(best, jumpVertical(p.x, p.y, dy));
78-
if (!map.get(p.x - 1, p.y)) {
76+
if (!map.get(p.x - 1, p.y)) {
7977
addToOpenSet(best, jumpDiag(p.x, p.y, -1, dy));
8078
}
81-
if (!map.get(p.x + 1, p.y)) {
79+
if (!map.get(p.x + 1, p.y)) {
8280
addToOpenSet(best, jumpDiag(p.x, p.y, 1, dy));
8381
}
8482
}
@@ -102,16 +100,18 @@ private int idx(int y, int width, int x) {
102100
protected abstract Position jumpHorizontal(int x, int y, int dx);
103101

104102
private void addToOpenSet(Node parent, Position pos) {
105-
int index;
106-
if (pos != null && nodes[index = idx(pos)] != CLOSED) {
107-
Node node = new Node(parent, pos);
108-
Node existing = nodes[index];
109-
if (existing == null || existing.f > node.f) {
110-
if (existing != null) {
111-
openQueue.remove(existing);
103+
if (pos != null) {
104+
int index = idx(pos);
105+
if (nodes[index] != CLOSED) {
106+
Node node = new Node(parent, pos);
107+
Node existing = nodes[index];
108+
if (existing == null || existing.f > node.f) {
109+
if (existing != null) {
110+
openQueue.remove(existing);
111+
}
112+
openQueue.add(node);
113+
nodes[index] = node;
112114
}
113-
openQueue.add(node);
114-
nodes[index] = node;
115115
}
116116
}
117117
}
@@ -121,9 +121,9 @@ private Position jumpDiag(int px, int py, int dx, int dy) {
121121
assert dy != 0;
122122
int x = px + dx;
123123
int y = py + dy;
124-
int a = (map.get(x - dx, y) ? 0 : 1) | (map.get(x, y - dy) ? 0 : 2);
125-
while (map.get(x, y)) {
126-
int b = (map.get(x - dx, y + dy) ? 1 : 0) | (map.get(x + dx, y - dy) ? 2 : 0);
124+
int a = (map.get(x - dx, y) ? 0 : 1) | (map.get(x, y - dy) ? 0 : 2);
125+
while (map.get(x, y)) {
126+
int b = (map.get(x - dx, y + dy) ? 1 : 0) | (map.get(x + dx, y - dy) ? 2 : 0);
127127
if (x == target.x && y == target.y
128128
|| (a & b) != 0
129129
|| jumpHorizontal(x, y, dx) != null

0 commit comments

Comments
 (0)