1212
1313package bwem ;
1414
15+ import bwapi .Pair ;
1516import bwapi .WalkPosition ;
1617import bwem .area .Area ;
1718import bwem .map .Map ;
2021import bwem .typedef .CPPath ;
2122import bwem .typedef .Index ;
2223import bwem .unit .Neutral ;
23- import bwapi .Pair ;
24-
2524import java .util .ArrayList ;
2625import java .util .List ;
2726import java .util .Objects ;
@@ -38,13 +37,13 @@ public class ChokePointImpl implements ChokePoint {
3837 private Neutral blockingNeutral ;
3938 private ChokePoint pathBackTrace = null ;
4039
41- public ChokePointImpl (
42- final Graph graph ,
43- final Index index ,
44- final Area area1 ,
45- final Area area2 ,
46- final List <WalkPosition > geometry ,
47- final Neutral blockingNeutral ) {
40+ ChokePointImpl (
41+ final Graph graph ,
42+ final Index index ,
43+ final Area area1 ,
44+ final Area area2 ,
45+ final List <WalkPosition > geometry ,
46+ final Neutral blockingNeutral ) {
4847 if (geometry .isEmpty ()) {
4948 throw new IllegalArgumentException ();
5049 }
@@ -86,55 +85,30 @@ > getMap().getData().getMiniTile(geometry.get(i)).getAltitude().intValue())) {
8685 }
8786 this .nodes [Node .MIDDLE .ordinal ()] = geometry .get (i );
8887
88+ Map map = getMap ();
8989 for (int n = 0 ; n < Node .NODE_COUNT .ordinal (); ++n ) {
9090 for (final Area area : new Area []{area1 , area2 }) {
9191 final WalkPosition nodeInArea =
92- getGraph ()
93- .getMap ()
94- .breadthFirstSearch (
95- this .nodes [n ],
96- // findCond
97- args -> {
98- final Object ttile = args [0 ];
99- final Object tpos = args [1 ];
100- final Object tmap = args [args .length - 1 ];
101- if (ttile instanceof MiniTile
102- && tpos instanceof WalkPosition
103- && tmap instanceof Map ) {
104- final MiniTile miniTile = (MiniTile ) ttile ;
105- final WalkPosition w = (WalkPosition ) tpos ;
106- final Map map = (Map ) tmap ;
107- return (miniTile .getAreaId ().equals (area .getId ())
108- && map .getData ()
109- .getTile (w .toTilePosition (), CheckMode .NO_CHECK )
110- .getNeutral ()
111- == null );
112- } else {
113- throw new IllegalArgumentException ();
114- }
115- },
116- // visitCond
117- args -> {
118- final Object ttile = args [0 ];
119- final Object tpos = args [1 ];
120- final Object tmap = args [args .length - 1 ];
121- if (ttile instanceof MiniTile && tpos instanceof WalkPosition ) {
122- final MiniTile miniTile = (MiniTile ) ttile ;
123- final WalkPosition w = (WalkPosition ) tpos ;
124- final Map map = (Map ) tmap ;
125- return (miniTile .getAreaId ().equals (area .getId ())
126- || (isBlocked ()
127- && (((MiniTileImpl ) miniTile ).isBlocked ()
128- || map .getData ()
129- .getTile (w .toTilePosition (), CheckMode .NO_CHECK )
130- .getNeutral ()
131- != null )));
132- } else {
133- throw new IllegalArgumentException ("Invalid argument list." );
134- }
135- });
136-
137- /**
92+ getGraph ()
93+ .getMap ()
94+ .breadthFirstSearch (
95+ this .nodes [n ],
96+ // findCond
97+ (MiniTile miniTile , WalkPosition w ) -> (
98+ miniTile .getAreaId ().equals (area .getId ())
99+ && map .getData ()
100+ .getTile (w .toTilePosition (), CheckMode .NO_CHECK )
101+ .getNeutral () == null ),
102+ // visitCond
103+ (MiniTile miniTile , WalkPosition w ) -> (
104+ miniTile .getAreaId ().equals (area .getId ())
105+ || (isBlocked ()
106+ && (((MiniTileImpl ) miniTile ).isBlocked ()
107+ || map .getData ()
108+ .getTile (w .toTilePosition (), CheckMode .NO_CHECK )
109+ .getNeutral () != null ))));
110+
111+ /*
138112 * Note: In the original C++ code, "nodeInArea" is a reference to a "WalkPosition" in
139113 * "nodesInArea" which changes! Change that object here (after the call to
140114 * "breadthFirstSearch")...
@@ -153,12 +127,12 @@ > getMap().getData().getMiniTile(geometry.get(i)).getAltitude().intValue())) {
153127 }
154128 }
155129
156- public ChokePointImpl (
157- final Graph graph ,
158- final Index index ,
159- final Area area1 ,
160- final Area area2 ,
161- final List <WalkPosition > geometry ) {
130+ ChokePointImpl (
131+ final Graph graph ,
132+ final Index index ,
133+ final Area area1 ,
134+ final Area area2 ,
135+ final List <WalkPosition > geometry ) {
162136 this (graph , index , area1 , area2 , geometry , null );
163137 }
164138
@@ -187,7 +161,6 @@ public WalkPosition getCenter() {
187161
188162 @ Override
189163 public WalkPosition getNodePosition (final Node node ) {
190- // bwem_assert(n < NODE_COUNT);
191164 if (!(node .ordinal () < Node .NODE_COUNT .ordinal ())) {
192165 throw new IllegalArgumentException ();
193166 }
@@ -196,7 +169,6 @@ public WalkPosition getNodePosition(final Node node) {
196169
197170 @ Override
198171 public WalkPosition getNodePositionInArea (final Node node , final Area area ) {
199- // bwem_assert((pArea == areas.getLeft()) || (pArea == areas.getRight()));
200172 if (!(area .equals (this .areas .getLeft ()) || area .equals (this .areas .getRight ()))) {
201173 throw new IllegalArgumentException ();
202174 }
@@ -236,7 +208,6 @@ public CPPath getPathTo(final ChokePoint cp) {
236208 }
237209
238210 public void onBlockingNeutralDestroyed (final Neutral pBlocking ) {
239- // bwem_assert(pBlocking && pBlocking->blocking());
240211 if (!(pBlocking != null && pBlocking .isBlocking ())) {
241212 throw new IllegalStateException ();
242213 }
@@ -247,23 +218,21 @@ public void onBlockingNeutralDestroyed(final Neutral pBlocking) {
247218 this .blockingNeutral =
248219 getMap ().getData ().getTile (this .blockingNeutral .getTopLeft ()).getNeutral ();
249220
250- if (this .blockingNeutral == null ) {
251- if (getGraph ().getMap ().automaticPathUpdate ()) {
252- this .isBlocked = false ;
253- }
221+ if (this .blockingNeutral == null && getGraph ().getMap ().automaticPathUpdate ()) {
222+ this .isBlocked = false ;
254223 }
255224 }
256225 }
257226
258- public Index getIndex () {
227+ Index getIndex () {
259228 return this .index ;
260229 }
261230
262- public ChokePoint getPathBackTrace () {
231+ ChokePoint getPathBackTrace () {
263232 return this .pathBackTrace ;
264233 }
265234
266- public void setPathBackTrace (final ChokePoint pathBackTrace ) {
235+ void setPathBackTrace (final ChokePoint pathBackTrace ) {
267236 this .pathBackTrace = pathBackTrace ;
268237 }
269238
@@ -279,8 +248,8 @@ public boolean equals(final Object object) {
279248 final boolean ler = this .areas .getLeft ().equals (that .areas .getRight ());
280249 final boolean rer = this .areas .getRight ().equals (that .areas .getRight ());
281250 final boolean rel = this .areas .getRight ().equals (that .areas .getLeft ());
282- return ((( lel && rer )
283- || ( ler && rel ))) ; /* true if area pairs are an exact match or if one pair is reversed. */
251+ return lel && rer
252+ || ler && rel ; /* true if area pairs are an exact match or if one pair is reversed. */
284253 }
285254 }
286255
0 commit comments