Skip to content

Commit 66aead7

Browse files
committed
add (untested) bwem
1 parent be620df commit 66aead7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+7063
-0
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
<version>4.5.2</version>
3636
</dependency>
3737

38+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
39+
<dependency>
40+
<groupId>org.apache.commons</groupId>
41+
<artifactId>commons-lang3</artifactId>
42+
<version>3.8.1</version>
43+
</dependency>
44+
3845

3946
</dependencies>
4047

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ abstract class Point {
1515
this.scalar = type;
1616
}
1717

18+
public int getX() {
19+
return x;
20+
}
21+
22+
public int getY() {
23+
return y;
24+
}
25+
1826
public double getLength() {
1927
return Math.sqrt(x * x + y * y);
2028
}

src/main/java/bwem/BWEM.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic
2+
// Modified work Copyright (c) 2017-2018 OpenBW Team
3+
4+
//////////////////////////////////////////////////////////////////////////
5+
//
6+
// This file is part of the BWEM Library.
7+
// BWEM is free software, licensed under the MIT/X11 License.
8+
// A copy of the license is provided with the library in the LICENSE file.
9+
// Copyright (c) 2015, 2017, Igor Dimitrijevic
10+
//
11+
//////////////////////////////////////////////////////////////////////////
12+
13+
package bwem;
14+
15+
import bwapi.Game;
16+
import bwem.map.Map;
17+
import bwem.map.MapInitializer;
18+
import bwem.map.MapInitializerImpl;
19+
20+
public final class BWEM {
21+
private final Map map;
22+
23+
public BWEM(final Game game) {
24+
this.map = new MapInitializerImpl(game);
25+
}
26+
27+
/** Returns the root internal data container. */
28+
public Map getMap() {
29+
return this.map;
30+
}
31+
32+
33+
/**
34+
* Initializes and pre-computes all of the internal data.
35+
*
36+
*/
37+
public void initialize() {
38+
if (!(this.map instanceof MapInitializer)) {
39+
throw new IllegalStateException("BWEM was not instantiated properly.");
40+
} else {
41+
((MapInitializer) this.map).initialize();
42+
}
43+
}
44+
}

src/main/java/bwem/Base.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic
2+
// Modified work Copyright (c) 2017-2018 OpenBW Team
3+
4+
//////////////////////////////////////////////////////////////////////////
5+
//
6+
// This file is part of the BWEM Library.
7+
// BWEM is free software, licensed under the MIT/X11 License.
8+
// A copy of the license is provided with the library in the LICENSE file.
9+
// Copyright (c) 2015, 2017, Igor Dimitrijevic
10+
//
11+
//////////////////////////////////////////////////////////////////////////
12+
13+
package bwem;
14+
15+
import bwapi.point.Position;
16+
import bwapi.point.TilePosition;
17+
import bwem.area.Area;
18+
import bwem.map.MapData;
19+
import bwem.unit.Geyser;
20+
import bwem.unit.Mineral;
21+
import bwem.unit.Neutral;
22+
import java.util.List;
23+
24+
/**
25+
* After Areas and ChokePoints, Bases are the third kind of object BWEM automatically computes from
26+
* Brood War's maps. A Base is essentially a suggested location (intended to be optimal) to put a
27+
* resource depot. It also provides information on the resources available, and some statistics. A
28+
* Base always belongs to some Area. An Area may contain zero, one or several Bases. Like Areas and
29+
* ChokePoints, the number and the addresses of Base instances remain unchanged.
30+
*/
31+
public interface Base {
32+
/**
33+
* Tests whether this base is a start location.<br>
34+
* - Note: all players start at locations taken from {@link MapData#getStartingLocations()},<br>
35+
* which doesn't mean all the locations in {@link MapData#getStartingLocations()} are actually
36+
* used.
37+
*/
38+
boolean isStartingLocation();
39+
40+
/** Returns the area in which this base is located. */
41+
Area getArea();
42+
43+
/**
44+
* Returns the position (top-left TilePosition) of the location for a resource depot.<br>
45+
* - Note: If {@link #isStartingLocation()} == true, it is guaranteed that the location
46+
* corresponds exactly to one of {@link MapData#getStartingLocations()}.
47+
*/
48+
TilePosition getLocation();
49+
50+
/** Returns the center position of {@link #getLocation()}. */
51+
Position getCenter();
52+
53+
/**
54+
* Returns the available minerals.<br>
55+
* - These minerals are assigned to this base (it is guaranteed that no other base provides them).
56+
* <br>
57+
* - Note: The size of the returned list may decrease, as some of the minerals may get destroyed.
58+
*/
59+
List<Mineral> getMinerals();
60+
61+
/**
62+
* Returns the available geysers.<br>
63+
* - These geysers are assigned to this Base (it is guaranteed that no other Base provides them).
64+
* <br>
65+
* - Note: The size of the returned list will NOT decrease, as geysers never get destroyed.
66+
*/
67+
List<Geyser> getGeysers();
68+
69+
/**
70+
* Returns the blocking minerals.<br>
71+
* - These are special minerals. They are placed at or near the resource depot location,<br>
72+
* thus blocking the building of a resource depot from being close to the resources.<br>
73+
* - So, before trying to build a resource depot, these minerals must be gathered first.<br>
74+
* - Fortunately, these are guaranteed to have their initialAmount() <= 8.<br>
75+
* - As an example of blocking minerals, see the two islands in Andromeda.scx.<br>
76+
* - Note: if {@link #isStartingLocation()} == true, an empty list is returned.<br>
77+
* - Note: {@link #getBlockingMinerals()} should not be confused with {@link
78+
* ChokePoint#getBlockingNeutral()} and {@link Neutral#isBlocking()}:<br>
79+
* The last two refer to a Neutral blocking a ChokePoint, not a Base.
80+
*/
81+
List<Mineral> getBlockingMinerals();
82+
}

src/main/java/bwem/BaseImpl.java

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic
2+
// Modified work Copyright (c) 2017-2018 OpenBW Team
3+
4+
//////////////////////////////////////////////////////////////////////////
5+
//
6+
// This file is part of the BWEM Library.
7+
// BWEM is free software, licensed under the MIT/X11 License.
8+
// A copy of the license is provided with the library in the LICENSE file.
9+
// Copyright (c) 2015, 2017, Igor Dimitrijevic
10+
//
11+
//////////////////////////////////////////////////////////////////////////
12+
13+
package bwem;
14+
15+
import bwapi.point.Position;
16+
import bwapi.point.TilePosition;
17+
import bwapi.types.UnitType;
18+
import bwem.area.Area;
19+
import bwem.unit.Geyser;
20+
import bwem.unit.Mineral;
21+
import bwem.unit.Resource;
22+
import bwem.util.BwemExt;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.Objects;
26+
public class BaseImpl implements Base {
27+
private final Area area;
28+
private TilePosition location;
29+
private Position center;
30+
private final List<Mineral> minerals = new ArrayList<>();
31+
private final List<Geyser> geysers = new ArrayList<>();
32+
private final List<Mineral> blockingMinerals;
33+
private boolean isStartingLocation = false;
34+
35+
public BaseImpl(
36+
final Area area,
37+
final TilePosition location,
38+
final List<Resource> assignedResources,
39+
final List<Mineral> blockingMinerals) {
40+
this.area = area;
41+
this.location = location;
42+
this.center = BwemExt.centerOfBuilding(location, UnitType.Terran_Command_Center.tileSize());
43+
this.blockingMinerals = blockingMinerals;
44+
45+
// bwem_assert(!AssignedResources.empty());
46+
if (assignedResources.isEmpty()) {
47+
throw new IllegalArgumentException();
48+
}
49+
50+
for (final Resource assignedResource : assignedResources) {
51+
if (assignedResource instanceof Mineral) {
52+
final Mineral assignedMineral = (Mineral) assignedResource;
53+
this.minerals.add(assignedMineral);
54+
} else if (assignedResource instanceof Geyser) {
55+
final Geyser assignedGeyser = (Geyser) assignedResource;
56+
this.geysers.add(assignedGeyser);
57+
}
58+
}
59+
}
60+
61+
@Override
62+
public boolean isStartingLocation() {
63+
return this.isStartingLocation;
64+
}
65+
66+
@Override
67+
public Area getArea() {
68+
return this.area;
69+
}
70+
71+
@Override
72+
public TilePosition getLocation() {
73+
return this.location;
74+
}
75+
76+
@Override
77+
public Position getCenter() {
78+
return this.center;
79+
}
80+
81+
@Override
82+
public List<Mineral> getMinerals() {
83+
return this.minerals;
84+
}
85+
86+
@Override
87+
public List<Geyser> getGeysers() {
88+
return this.geysers;
89+
}
90+
91+
@Override
92+
public List<Mineral> getBlockingMinerals() {
93+
return this.blockingMinerals;
94+
}
95+
96+
public void assignStartingLocation(final TilePosition actualLocation) {
97+
this.isStartingLocation = true;
98+
this.location = actualLocation;
99+
this.center =
100+
BwemExt.centerOfBuilding(actualLocation, UnitType.Terran_Command_Center.tileSize());
101+
}
102+
103+
public void onMineralDestroyed(final Mineral mineral) {
104+
// bwem_assert(pMineral);
105+
if (mineral == null) {
106+
throw new IllegalArgumentException();
107+
}
108+
109+
this.minerals.remove(mineral);
110+
this.blockingMinerals.remove(mineral);
111+
}
112+
113+
@Override
114+
public boolean equals(final Object object) {
115+
if (this == object) {
116+
return true;
117+
} else if (!(object instanceof Base)) {
118+
return false;
119+
} else {
120+
final Base that = (Base) object;
121+
return (getArea().equals(that.getArea())
122+
&& getLocation().equals(that.getLocation())
123+
&& getCenter().equals(that.getCenter()));
124+
}
125+
}
126+
127+
@Override
128+
public int hashCode() {
129+
return Objects.hash(this.area, this.location, this.center);
130+
}
131+
}

src/main/java/bwem/CheckMode.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic
2+
// Modified work Copyright (c) 2017-2018 OpenBW Team
3+
4+
//////////////////////////////////////////////////////////////////////////
5+
//
6+
// This file is part of the BWEM Library.
7+
// BWEM is free software, licensed under the MIT/X11 License.
8+
// A copy of the license is provided with the library in the LICENSE file.
9+
// Copyright (c) 2015, 2017, Igor Dimitrijevic
10+
//
11+
//////////////////////////////////////////////////////////////////////////
12+
13+
package bwem;
14+
15+
public enum CheckMode {
16+
CHECK,
17+
NO_CHECK
18+
}

0 commit comments

Comments
 (0)