Skip to content

Commit 241194f

Browse files
committed
call assignStartingLocationsToSuitableBases in initialise bwem
1 parent 346fba0 commit 241194f

File tree

2 files changed

+25
-47
lines changed

2 files changed

+25
-47
lines changed

src/main/java/bwem/BWEM.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public Map getMap() {
3737
public void initialize() {
3838
if (!(this.map instanceof MapInitializer)) {
3939
throw new IllegalStateException("BWEM was not instantiated properly.");
40-
} else {
41-
((MapInitializer) this.map).initialize();
4240
}
41+
((MapInitializer) this.map).initialize();
42+
this.map.assignStartingLocationsToSuitableBases();
4343
}
4444
}

src/test/java/marinehell/MarineHell.java

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import bwem.BWEM;
1010
import bwem.Base;
1111
import bwem.ChokePoint;
12-
import bwem.typedef.CPPath;
1312

1413
public class MarineHell extends DefaultBWListener {
1514

@@ -22,41 +21,35 @@ public class MarineHell extends DefaultBWListener {
2221
private int frameskip = 0;
2322
private int cyclesForSearching = 0;
2423
private int maxCyclesForSearching = 0;
25-
private int enemies = 0;
2624
private int searchingScv = 0;
2725
private int searchingTimeout = 0;
2826
private boolean dontBuild = false;
2927
private int timeout = 0;
30-
Unit bunkerBuilder;
31-
Unit searcher;
28+
private Unit bunkerBuilder;
29+
private Unit searcher;
3230

3331
private BWEM BWTA;
3432

3533
private String debugText = "";
3634

3735
private enum Strategy {
3836
WaitFor50, AttackAtAllCost
39-
};
37+
}
4038

4139
private Strategy selectedStrategy = Strategy.WaitFor50;
4240

4341
private Set<Position> enemyBuildingMemory = new HashSet<>();
4442

45-
public void run() {
43+
private void run() {
4644
mirror.startGame();
4745
}
4846

49-
@Override
50-
public void onUnitCreate(Unit unit) {
51-
52-
}
53-
5447
@Override
5548
public void onStart() {
5649
frameskip = 0;
5750
cyclesForSearching = 0;
5851
maxCyclesForSearching = 0;
59-
enemies = 0;
52+
int enemies = 0;
6053
searchingScv = 0;
6154
searchingTimeout = 0;
6255
dontBuild = false;
@@ -68,13 +61,8 @@ public void onStart() {
6861
self = game.self();
6962
game.setLocalSpeed(0);
7063

71-
// Use BWTA to analyze map
72-
// This may take a few minutes if the map is processed first time!
73-
7464
BWTA = new BWEM(game);
7565
BWTA.initialize();
76-
77-
int i = 0;
7866
}
7967

8068
@Override
@@ -87,11 +75,7 @@ public void onFrame() {
8775
game.drawTextScreen(10, 40, "Elapsed time: " + game.elapsedTime() + "; Strategy: " + selectedStrategy);
8876
game.drawTextScreen(10, 50, debugText);
8977
game.drawTextScreen(10, 60, "supply: " + self.supplyTotal() + " used: " + self.supplyUsed());
90-
/*
91-
* if (game.elapsedTime() > 2001) { int x = (game.elapsedTime() / 500) %
92-
* 2; if (x == 0) { selectedStrategy = Strategy.FindEnemy; } else {
93-
* selectedStrategy = Strategy.HugeAttack; } }
94-
*/
78+
9579

9680
if (maxCyclesForSearching > 300000) {
9781
dontBuild = true;
@@ -104,7 +88,6 @@ public void onFrame() {
10488
}
10589
cyclesForSearching = 0;
10690

107-
StringBuilder units = new StringBuilder("My units:\n");
10891
List<Unit> workers = new ArrayList<>();
10992
List<Unit> barracks = new ArrayList<>();
11093
Unit commandCenter = null;
@@ -115,11 +98,11 @@ public void onFrame() {
11598
Position workerAttacked = null;
11699

117100

118-
if (bunkerBuilder != null && bunkerBuilder.exists() == false) {
101+
if (bunkerBuilder != null && !bunkerBuilder.exists()) {
119102
bunkerBuilder = null;
120103
}
121104

122-
if (searcher != null && searcher.exists() == false) {
105+
if (searcher != null && !searcher.exists()) {
123106
searcher = null;
124107
}
125108

@@ -141,15 +124,15 @@ public void onFrame() {
141124
commandCenter = myUnit;
142125
}
143126

144-
if (myUnit.getType() == UnitType.Terran_Barracks && myUnit.isBeingConstructed() == false) {
127+
if (myUnit.getType() == UnitType.Terran_Barracks && !myUnit.isBeingConstructed()) {
145128
barracks.add(myUnit);
146129
}
147130

148131
if (myUnit.getType() == UnitType.Terran_Marine) {
149132
marines.add(myUnit);
150133
}
151134

152-
if (myUnit.getType() == UnitType.Terran_Bunker && myUnit.isBeingConstructed() == false) {
135+
if (myUnit.getType() == UnitType.Terran_Bunker && !myUnit.isBeingConstructed()) {
153136
bunker = myUnit;
154137
}
155138

@@ -165,8 +148,7 @@ public void onFrame() {
165148
// patch
166149
if (myUnit.getType().isWorker() && myUnit.isIdle()) {
167150
boolean skip = false;
168-
if (bunker == null && bunkerBuilder != null && myUnit.equals(bunkerBuilder)
169-
&& barracks.isEmpty() == false) {
151+
if (bunker == null && myUnit.equals(bunkerBuilder) && !barracks.isEmpty()) {
170152
skip = true;
171153
}
172154

@@ -184,7 +166,7 @@ public void onFrame() {
184166

185167
// if a mineral patch was found, send the worker to gather it
186168
if (closestMineral != null) {
187-
if (skip == false) {
169+
if (!skip) {
188170
myUnit.gather(closestMineral, false);
189171
}
190172
}
@@ -204,7 +186,7 @@ public void onFrame() {
204186
bunkerBuilder = workers.get(10);
205187
}
206188

207-
if (bunker == null && barracks.size() >= 1 && workers.size() > 10 && dontBuild == false) {
189+
if (bunker == null && barracks.size() >= 1 && workers.size() > 10 && !dontBuild) {
208190
game.setLocalSpeed(20);
209191

210192
if (timeout < 200) {
@@ -224,13 +206,13 @@ public void onFrame() {
224206
game.drawTextMap(workers.get(10).getPosition(), "He will build bunker");
225207
}
226208

227-
if (bunker != null && bunkerBuilder != null && bunkerBuilder.isRepairing() == false) {
209+
if (bunker != null && bunkerBuilder != null && !bunkerBuilder.isRepairing()) {
228210
game.drawTextMap(bunkerBuilder.getPosition(), "Reparing bunker");
229211
bunkerBuilder.repair(bunker);
230212
}
231213

232214
if (commandCenter.getTrainingQueue().isEmpty() && workers.size() < 20 && self.minerals() >= 50) {
233-
commandCenter.build(UnitType.AllUnits.Terran_SCV);
215+
commandCenter.build(UnitType.Terran_SCV);
234216
}
235217

236218
frameskip++;
@@ -246,7 +228,7 @@ public void onFrame() {
246228

247229
int i = 1;
248230
for (Unit worker : workers) {
249-
if (worker.isGatheringMinerals() && dontBuild == false) {
231+
if (worker.isGatheringMinerals() && !dontBuild) {
250232
if (self.minerals() >= 150 * i && barracks.size() < 6) {
251233
TilePosition buildTile = getBuildTile(worker, UnitType.Terran_Barracks, self.getStartLocation());
252234
if (buildTile != null) {
@@ -272,7 +254,7 @@ public void onFrame() {
272254

273255
for (Unit barrack : barracks) {
274256
if (barrack.getTrainingQueue().isEmpty()) {
275-
barrack.build(UnitType.AllUnits.Terran_Marine);
257+
barrack.build(UnitType.Terran_Marine);
276258
}
277259
}
278260

@@ -285,10 +267,9 @@ public void onFrame() {
285267
allLocations.add(b);
286268
}
287269

288-
Random random = new Random();
289270
int k = 0;
290271
for (Unit marine : marines) {
291-
if (marine.isAttacking() == false && marine.isMoving() == false) {
272+
if (!marine.isAttacking() && !marine.isMoving()) {
292273
if (marines.size() > 50 || selectedStrategy == Strategy.AttackAtAllCost) {
293274
if (marines.size() > 40) {
294275
selectedStrategy = Strategy.AttackAtAllCost;
@@ -349,17 +330,14 @@ public void onFrame() {
349330
searcher.move(baseLocations.get(searchingScv).getCenter());
350331
searchingScv++;
351332
}
352-
353-
// debugText = "Size: " + workers.size() + "; isGathering" + workers.get(7).isGatheringMinerals() + "; location: "
354-
// + baseLocations.size() + "; num: " + searchingScv;
333+
int workersSize = workers.size();
334+
debugText = "Size: " + workersSize + "; isGathering" + workers.get(workersSize > 7 ? 7 : workersSize - 1).isGatheringMinerals() + "; location: "
335+
+ baseLocations.size() + "; num: " + searchingScv;
355336

356337
for (Unit u : game.enemy().getUnits()) {
357338
// if this unit is in fact a building
358339
if (u.getType().isBuilding()) {
359-
// check if we have it's position in memory and add it if we
360-
// don't
361-
if (!enemyBuildingMemory.contains(u.getPosition()))
362-
enemyBuildingMemory.add(u.getPosition());
340+
enemyBuildingMemory.add(u.getPosition());
363341
}
364342
}
365343

@@ -385,7 +363,7 @@ public void onFrame() {
385363

386364
// if there is no more any building, remove that position from
387365
// our memory
388-
if (buildingStillThere == false) {
366+
if (!buildingStillThere) {
389367
enemyBuildingMemory.remove(p);
390368
break;
391369
}

0 commit comments

Comments
 (0)