Skip to content

Commit 4591bef

Browse files
author
Bytekeeper
committed
Formatting
1 parent 80b966f commit 4591bef

37 files changed

+474
-518
lines changed

src/jmh/java/org/bk/ass/ArrayCopyVsFill.java

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,35 @@
44
// @Warmup(iterations = 2, time = 5)
55
// @Fork(2)
66

7-
/**
8-
* If you want to see how much Arrays.fill sucks, enable this test.
9-
*/
7+
/** If you want to see how much Arrays.fill sucks, enable this test. */
108
public class ArrayCopyVsFill {
11-
// @State(Scope.Thread)
12-
// public static class MyState {
13-
// byte[] collision = new byte[8192 * 8192 / 16 / 16];
14-
// Object[] objects = new Object[1024 * 1024];
15-
// }
16-
//
17-
// @Benchmark
18-
// public int copyByteArray(MyState state) {
19-
// FastArrayFill.fillArray(state.collision, (byte) 0);
20-
// return state.collision[9];
21-
// }
22-
//
23-
// @Benchmark
24-
// public int fillByteArray(MyState state) {
25-
// Arrays.fill(state.collision, (byte) 0);
26-
// return state.collision[9];
27-
// }
28-
//
29-
// @Benchmark
30-
// public Object copyObjectArray(MyState state) {
31-
// FastArrayFill.fillArray(state.objects, null);
32-
// return state.objects[9];
33-
// }
34-
//
35-
// @Benchmark
36-
// public Object fillObjectArray(MyState state) {
37-
// Arrays.fill(state.objects, null);
38-
// return state.objects[9];
39-
// }
9+
// @State(Scope.Thread)
10+
// public static class MyState {
11+
// byte[] collision = new byte[8192 * 8192 / 16 / 16];
12+
// Object[] objects = new Object[1024 * 1024];
13+
// }
14+
//
15+
// @Benchmark
16+
// public int copyByteArray(MyState state) {
17+
// FastArrayFill.fillArray(state.collision, (byte) 0);
18+
// return state.collision[9];
19+
// }
20+
//
21+
// @Benchmark
22+
// public int fillByteArray(MyState state) {
23+
// Arrays.fill(state.collision, (byte) 0);
24+
// return state.collision[9];
25+
// }
26+
//
27+
// @Benchmark
28+
// public Object copyObjectArray(MyState state) {
29+
// FastArrayFill.fillArray(state.objects, null);
30+
// return state.objects[9];
31+
// }
32+
//
33+
// @Benchmark
34+
// public Object fillObjectArray(MyState state) {
35+
// Arrays.fill(state.objects, null);
36+
// return state.objects[9];
37+
// }
4038
}

src/jmh/java/org/bk/ass/EvaluatorBenchmark.java

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

3-
import java.util.ArrayList;
4-
import java.util.List;
53
import org.openbw.bwapi4j.test.BWDataProvider;
64
import org.openbw.bwapi4j.type.UnitType;
7-
import org.openjdk.jmh.annotations.Benchmark;
8-
import org.openjdk.jmh.annotations.Fork;
9-
import org.openjdk.jmh.annotations.Measurement;
10-
import org.openjdk.jmh.annotations.Scope;
11-
import org.openjdk.jmh.annotations.Setup;
12-
import org.openjdk.jmh.annotations.State;
5+
import org.openjdk.jmh.annotations.*;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
139

1410
@Measurement(iterations = 5, time = 5)
1511
@Fork(3)

src/jmh/java/org/bk/ass/cluster/ClusterBenchmark.java

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

3-
import java.util.Collection;
4-
import java.util.HashMap;
5-
import java.util.List;
6-
import java.util.Map;
7-
import java.util.SplittableRandom;
3+
import org.openbw.bwapi4j.test.BWDataProvider;
4+
import org.openjdk.jmh.annotations.*;
5+
6+
import java.util.*;
87
import java.util.stream.Collectors;
98
import java.util.stream.IntStream;
10-
import org.openbw.bwapi4j.test.BWDataProvider;
11-
import org.openjdk.jmh.annotations.Benchmark;
12-
import org.openjdk.jmh.annotations.Fork;
13-
import org.openjdk.jmh.annotations.Level;
14-
import org.openjdk.jmh.annotations.Measurement;
15-
import org.openjdk.jmh.annotations.Scope;
16-
import org.openjdk.jmh.annotations.Setup;
17-
import org.openjdk.jmh.annotations.State;
189

1910
@Measurement(iterations = 5, time = 5)
2011
@Fork(3)

src/jmh/java/org/bk/ass/path/JpsBenchmark.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public static class MyState {
2424
public void setup() throws IOException {
2525
ImageIO.setUseCache(false);
2626
BufferedImage image = ImageIO.read(JpsTest.class.getResourceAsStream("/dungeon_map.bmp"));
27-
boolean[][] data = new boolean[image.getHeight()][image.getWidth()];
28-
for (int x = 0; x < image.getWidth(); x++) {
29-
for (int y = 0; y < image.getHeight(); y++) {
30-
data[x][y] = image.getRGB(x, y) == -1;
27+
boolean[][] data = new boolean[image.getHeight()][image.getWidth()];
28+
for (int x = 0; x < image.getWidth(); x++) {
29+
for (int y = 0; y < image.getHeight(); y++) {
30+
data[x][y] = image.getRGB(x, y) == -1;
3131
}
3232
}
3333
map = Map.fromBooleanArray(data);
@@ -45,7 +45,7 @@ public void setup() throws IOException {
4545
do {
4646
end = new Position(rnd.nextInt(image.getWidth()), rnd.nextInt(image.getHeight()));
4747
} while (map.get(end.x, end.y));
48-
positions.add(new Position[]{start, end});
48+
positions.add(new Position[] {start, end});
4949
}
5050
}
5151
}

src/jmh/java/org/bk/ass/query/PositionQueriesBenchmark.java

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,48 @@
1414
@Fork(3)
1515
public class PositionQueriesBenchmark {
1616

17-
@State(Scope.Thread)
18-
public static class MyState {
19-
20-
PositionQueries<Position> positionQueries;
21-
List<PositionAndId> entities;
22-
List<Position> items;
23-
24-
@Setup
25-
public void setup() {
26-
SplittableRandom rnd = new SplittableRandom(815);
27-
entities = new ArrayList<>();
28-
items = new ArrayList<>();
29-
for (int i = 0; i < 1000; i++) {
30-
int x = rnd.nextInt(0, 10000);
31-
int y = rnd.nextInt(0, 10000);
32-
entities.add(new PositionAndId(i, x, y));
33-
items.add(new Position(x, y));
34-
}
35-
positionQueries = new PositionQueries<>(items, Function.identity());
36-
}
17+
@State(Scope.Thread)
18+
public static class MyState {
19+
20+
PositionQueries<Position> positionQueries;
21+
List<PositionAndId> entities;
22+
List<Position> items;
23+
24+
@Setup
25+
public void setup() {
26+
SplittableRandom rnd = new SplittableRandom(815);
27+
entities = new ArrayList<>();
28+
items = new ArrayList<>();
29+
for (int i = 0; i < 1000; i++) {
30+
int x = rnd.nextInt(0, 10000);
31+
int y = rnd.nextInt(0, 10000);
32+
entities.add(new PositionAndId(i, x, y));
33+
items.add(new Position(x, y));
34+
}
35+
positionQueries = new PositionQueries<>(items, Function.identity());
3736
}
37+
}
3838

39-
static {
40-
try {
41-
BWDataProvider.injectValues();
42-
} catch (Exception e) {
43-
throw new RuntimeException(e);
44-
}
45-
}
46-
47-
48-
@Benchmark
49-
public PositionQueries<Position> queryCreation(MyState state) {
50-
return new PositionQueries<>(state.items, Function.identity());
51-
}
52-
53-
54-
@Benchmark
55-
public Collection<Position> inRadius(MyState state) {
56-
return state.positionQueries.inRadius(5000, 5000, 1000);
57-
}
58-
59-
@Benchmark
60-
public Position nearest(MyState state) {
61-
return state.positionQueries.nearest(2500, 2500);
39+
static {
40+
try {
41+
BWDataProvider.injectValues();
42+
} catch (Exception e) {
43+
throw new RuntimeException(e);
6244
}
45+
}
46+
47+
@Benchmark
48+
public PositionQueries<Position> queryCreation(MyState state) {
49+
return new PositionQueries<>(state.items, Function.identity());
50+
}
51+
52+
@Benchmark
53+
public Collection<Position> inRadius(MyState state) {
54+
return state.positionQueries.inRadius(5000, 5000, 1000);
55+
}
56+
57+
@Benchmark
58+
public Position nearest(MyState state) {
59+
return state.positionQueries.nearest(2500, 2500);
60+
}
6361
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public class Agent {
7070
Agent lastAlly;
7171

7272
// Allow replacement of units on death (for example bunker -> marines)
73-
Consumer<Collection<Agent>> onDeathReplacer = ignored -> {
74-
};
73+
Consumer<Collection<Agent>> onDeathReplacer = ignored -> {};
7574

7675
public Agent(String name) {
7776
this.name = name;
@@ -290,9 +289,7 @@ final Weapon weaponVs(Agent other) {
290289
return groundWeapon;
291290
}
292291

293-
/**
294-
* Has to be called *after* max health has been set
295-
*/
292+
/** Has to be called *after* max health has been set */
296293
public Agent setHpConstructionRate(int buildTime) {
297294
this.hpConstructionRate =
298295
max(1, (maxHealthShifted - maxHealthShifted / 10 + buildTime - 1) / buildTime);

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public static int distanceSquared(Agent a, Agent b) {
4141
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
4242
}
4343

44-
/**
45-
* Deal splash damage to enemies and allies
46-
*/
44+
/** Deal splash damage to enemies and allies */
4745
public static void dealRadialSplashDamage(
4846
Weapon weapon,
4947
Agent mainTarget,
@@ -76,9 +74,7 @@ private static void applySplashDamage(Weapon weapon, Agent mainTarget, Agent spl
7674
}
7775
}
7876

79-
/**
80-
* Deal splash damage to enemies only
81-
*/
77+
/** Deal splash damage to enemies only */
8278
public static void dealRadialSplashDamage(
8379
Weapon weapon, Agent mainTarget, UnorderedCollection<Agent> enemies) {
8480
for (int i = enemies.size() - 1; i >= 0; i--) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AttackerBehavior implements Behavior {
1515

1616
@Override
1717
public boolean simUnit(
18-
Agent agent, UnorderedCollection<Agent> allies, UnorderedCollection<Agent> enemies) {
18+
Agent agent, UnorderedCollection<Agent> allies, UnorderedCollection<Agent> enemies) {
1919
if (agent.cooldown > agent.maxCooldown - agent.stopFrames) {
2020
return true;
2121
}
@@ -38,10 +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
42-
&& wpn.damageShifted != 0
43-
&& enemy.detected
44-
&& !enemy.isStasised) {
41+
if (enemy.healthShifted >= 1
42+
&& wpn.damageShifted != 0
43+
&& enemy.detected
44+
&& !enemy.isStasised) {
4545
int distanceSquared = distanceSquared(agent, enemy);
4646
if (distanceSquared >= wpn.minRangeSquared && distanceSquared < selectedDistanceSquared) {
4747
selectedDistanceSquared = distanceSquared;
@@ -71,7 +71,7 @@ public boolean simUnit(
7171
}
7272

7373
if (agent.cooldown == 0
74-
&& selectedDistanceSquared
74+
&& selectedDistanceSquared
7575
<= Math.max(Simulator.MIN_SIMULATION_RANGE, selectedWeapon.maxRangeSquared)) {
7676
simAttack(agent, allies, enemies, selectedEnemy, selectedWeapon);
7777
}

0 commit comments

Comments
 (0)