Skip to content

Commit 25efc69

Browse files
committed
refactor bwem using intellij refactor
1 parent a6fce10 commit 25efc69

Some content is hidden

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

51 files changed

+5220
-5171
lines changed

src/main/java/bwem/BWEM.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,28 @@
1818
import bwem.map.MapInitializerImpl;
1919

2020
public final class BWEM {
21-
private final Map map;
21+
private final Map map;
2222

23-
public BWEM(final Game game) {
24-
this.map = new MapInitializerImpl(game);
25-
}
23+
public BWEM(final Game game) {
24+
this.map = new MapInitializerImpl(game);
25+
}
2626

27-
/** Returns the root internal data container. */
28-
public Map getMap() {
29-
return this.map;
30-
}
27+
/**
28+
* Returns the root internal data container.
29+
*/
30+
public Map getMap() {
31+
return this.map;
32+
}
3133

3234

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.");
35+
/**
36+
* Initializes and pre-computes all of the internal data.
37+
*/
38+
public void initialize() {
39+
if (!(this.map instanceof MapInitializer)) {
40+
throw new IllegalStateException("BWEM was not instantiated properly.");
41+
}
42+
((MapInitializer) this.map).initialize();
43+
this.map.assignStartingLocationsToSuitableBases();
4044
}
41-
((MapInitializer) this.map).initialize();
42-
this.map.assignStartingLocationsToSuitableBases();
43-
}
4445
}

src/main/java/bwem/Base.java

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import bwem.unit.Geyser;
2020
import bwem.unit.Mineral;
2121
import bwem.unit.Neutral;
22+
2223
import java.util.List;
2324

2425
/**
@@ -29,54 +30,58 @@
2930
* ChokePoints, the number and the addresses of Base instances remain unchanged.
3031
*/
3132
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();
33+
/**
34+
* Tests whether this base is a start location.<br>
35+
* - Note: all players start at locations taken from {@link MapData#getStartingLocations()},<br>
36+
* which doesn't mean all the locations in {@link MapData#getStartingLocations()} are actually
37+
* used.
38+
*/
39+
boolean isStartingLocation();
3940

40-
/** Returns the area in which this base is located. */
41-
Area getArea();
41+
/**
42+
* Returns the area in which this base is located.
43+
*/
44+
Area getArea();
4245

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();
46+
/**
47+
* Returns the position (top-left TilePosition) of the location for a resource depot.<br>
48+
* - Note: If {@link #isStartingLocation()} == true, it is guaranteed that the location
49+
* corresponds exactly to one of {@link MapData#getStartingLocations()}.
50+
*/
51+
TilePosition getLocation();
4952

50-
/** Returns the center position of {@link #getLocation()}. */
51-
Position getCenter();
53+
/**
54+
* Returns the center position of {@link #getLocation()}.
55+
*/
56+
Position getCenter();
5257

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();
58+
/**
59+
* Returns the available minerals.<br>
60+
* - These minerals are assigned to this base (it is guaranteed that no other base provides them).
61+
* <br>
62+
* - Note: The size of the returned list may decrease, as some of the minerals may get destroyed.
63+
*/
64+
List<Mineral> getMinerals();
6065

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();
66+
/**
67+
* Returns the available geysers.<br>
68+
* - These geysers are assigned to this Base (it is guaranteed that no other Base provides them).
69+
* <br>
70+
* - Note: The size of the returned list will NOT decrease, as geysers never get destroyed.
71+
*/
72+
List<Geyser> getGeysers();
6873

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();
74+
/**
75+
* Returns the blocking minerals.<br>
76+
* - These are special minerals. They are placed at or near the resource depot location,<br>
77+
* thus blocking the building of a resource depot from being close to the resources.<br>
78+
* - So, before trying to build a resource depot, these minerals must be gathered first.<br>
79+
* - Fortunately, these are guaranteed to have their initialAmount() <= 8.<br>
80+
* - As an example of blocking minerals, see the two islands in Andromeda.scx.<br>
81+
* - Note: if {@link #isStartingLocation()} == true, an empty list is returned.<br>
82+
* - Note: {@link #getBlockingMinerals()} should not be confused with {@link
83+
* ChokePoint#getBlockingNeutral()} and {@link Neutral#isBlocking()}:<br>
84+
* The last two refer to a Neutral blocking a ChokePoint, not a Base.
85+
*/
86+
List<Mineral> getBlockingMinerals();
8287
}

src/main/java/bwem/BaseImpl.java

Lines changed: 99 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -20,112 +20,114 @@
2020
import bwem.unit.Mineral;
2121
import bwem.unit.Resource;
2222
import bwem.util.BwemExt;
23+
2324
import java.util.ArrayList;
2425
import java.util.List;
2526
import java.util.Objects;
27+
2628
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();
29+
private final Area area;
30+
private final List<Mineral> minerals = new ArrayList<>();
31+
private final List<Geyser> geysers = new ArrayList<>();
32+
private final List<Mineral> blockingMinerals;
33+
private TilePosition location;
34+
private Position center;
35+
private boolean isStartingLocation = false;
36+
37+
public BaseImpl(
38+
final Area area,
39+
final TilePosition location,
40+
final List<Resource> assignedResources,
41+
final List<Mineral> blockingMinerals) {
42+
this.area = area;
43+
this.location = location;
44+
this.center = BwemExt.centerOfBuilding(location, UnitType.Terran_Command_Center.tileSize());
45+
this.blockingMinerals = blockingMinerals;
46+
47+
// bwem_assert(!AssignedResources.empty());
48+
if (assignedResources.isEmpty()) {
49+
throw new IllegalArgumentException();
50+
}
51+
52+
for (final Resource assignedResource : assignedResources) {
53+
if (assignedResource instanceof Mineral) {
54+
final Mineral assignedMineral = (Mineral) assignedResource;
55+
this.minerals.add(assignedMineral);
56+
} else if (assignedResource instanceof Geyser) {
57+
final Geyser assignedGeyser = (Geyser) assignedResource;
58+
this.geysers.add(assignedGeyser);
59+
}
60+
}
61+
}
62+
63+
@Override
64+
public boolean isStartingLocation() {
65+
return this.isStartingLocation;
66+
}
67+
68+
@Override
69+
public Area getArea() {
70+
return this.area;
4871
}
4972

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-
}
73+
@Override
74+
public TilePosition getLocation() {
75+
return this.location;
5876
}
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();
77+
78+
@Override
79+
public Position getCenter() {
80+
return this.center;
10781
}
10882

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()));
83+
@Override
84+
public List<Mineral> getMinerals() {
85+
return this.minerals;
12486
}
125-
}
12687

127-
@Override
128-
public int hashCode() {
129-
return Objects.hash(this.area, this.location, this.center);
130-
}
88+
@Override
89+
public List<Geyser> getGeysers() {
90+
return this.geysers;
91+
}
92+
93+
@Override
94+
public List<Mineral> getBlockingMinerals() {
95+
return this.blockingMinerals;
96+
}
97+
98+
public void assignStartingLocation(final TilePosition actualLocation) {
99+
this.isStartingLocation = true;
100+
this.location = actualLocation;
101+
this.center =
102+
BwemExt.centerOfBuilding(actualLocation, UnitType.Terran_Command_Center.tileSize());
103+
}
104+
105+
public void onMineralDestroyed(final Mineral mineral) {
106+
// bwem_assert(pMineral);
107+
if (mineral == null) {
108+
throw new IllegalArgumentException();
109+
}
110+
111+
this.minerals.remove(mineral);
112+
this.blockingMinerals.remove(mineral);
113+
}
114+
115+
@Override
116+
public boolean equals(final Object object) {
117+
if (this == object) {
118+
return true;
119+
} else if (!(object instanceof Base)) {
120+
return false;
121+
} else {
122+
final Base that = (Base) object;
123+
return (getArea().equals(that.getArea())
124+
&& getLocation().equals(that.getLocation())
125+
&& getCenter().equals(that.getCenter()));
126+
}
127+
}
128+
129+
@Override
130+
public int hashCode() {
131+
return Objects.hash(this.area, this.location, this.center);
132+
}
131133
}

src/main/java/bwem/CheckMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
package bwem;
1414

1515
public enum CheckMode {
16-
CHECK,
17-
NO_CHECK
16+
CHECK,
17+
NO_CHECK
1818
}

0 commit comments

Comments
 (0)