Repository navigation
Expand file tree
/
Copy pathBWEM.java
More file actions
68 lines (56 loc) · 2.07 KB
/
Copy pathBWEM.java
File metadata and controls
68 lines (56 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic
// Modified work Copyright (c) 2017-2018 OpenBW Team
//////////////////////////////////////////////////////////////////////////
//
// This file is part of the BWEM Library.
// BWEM is free software, licensed under the MIT/X11 License.
// A copy of the license is provided with the library in the LICENSE file.
// Copyright (c) 2015, 2017, Igor Dimitrijevic
//
//////////////////////////////////////////////////////////////////////////
package bwem;
import bwapi.Game;
import java.io.OutputStream;
/**
* BWEM Broodwar Map analysis library by Igor Dimitrijevic.
* Ported to Java by the OpenBW Team
*
* By default BWEM throws when an invalid state is encountered.
* But if you know what you are doing, you can skip these throws by setting
* {@link #setFailOnError} to `false`.
* These errors will then be outputted to `System.err`, but this can also be changed
* with {@link #setFailOutputStream} (if you set it to `null` the errors will be completely ignored).
*/
public final class BWEM {
private final BWMapInitializer map;
private final Asserter asserter;
public BWEM(final Game game) {
this.asserter = new Asserter();
this.map = new BWMapInitializer(game, asserter);
}
/**
* Returns the root internal data container.
*/
public BWMap getMap() {
return this.map;
}
/**
* Initializes and pre-computes all of the internal data.
*/
public void initialize() {
this.map.initialize();
this.map.assignStartingLocationsToSuitableBases();
}
public void setFailOnError(boolean failOnError) {
asserter.setFailOnError(failOnError);
}
public void setFailOutputStream(OutputStream outputStream) {
asserter.setFailOutputStream(outputStream);
}
public void calculateAreaBoundaries() {
if (!this.map.isInitialized()) {
throw new IllegalStateException("BWEM needs to be initialized first.");
}
this.map.getAreas().forEach(a -> ((AreaInitializer) a).calcBoundaryVertices());
}
}