Skip to content

Commit 822c6be

Browse files
committed
feat: put Pathing as interface to MovePath
1 parent fab4781 commit 822c6be

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

megamek/src/megamek/client/bot/caspar/ClassificationScore.java

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public boolean isHoldPosition() {
4848
return holdPosition > offensive && holdPosition > defensive;
4949
}
5050

51+
@Override
5152
public String toString() {
5253
return String.format("ClassificationScore<%s>[offensive=%.2f, defensive=%.2f, holdPosition=%.2f]",
5354
getClassification(), offensive, defensive, holdPosition);

megamek/src/megamek/client/bot/caspar/MovementClassification.java

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public enum MovementClassification {
3232
DEFENSIVE(1),
3333
HOLD_POSITION(2);
3434

35+
/**
36+
* The value associated with the movement classification.
37+
* It is defined by how the tensorflow model was trained and the data generated and tagged.
38+
*/
3539
private final int value;
3640

3741
MovementClassification(int value) {
@@ -53,4 +57,13 @@ public boolean isDefensive() {
5357
public boolean isHoldPosition() {
5458
return this == HOLD_POSITION;
5559
}
60+
61+
public static MovementClassification fromValue(int value) {
62+
for (MovementClassification classification : values()) {
63+
if (classification.value == value) {
64+
return classification;
65+
}
66+
}
67+
throw new IllegalArgumentException("Invalid value: " + value);
68+
}
5669
}

megamek/src/megamek/common/MovePath.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Holds movement path for an entity.
3434
*/
35-
public class MovePath implements Cloneable, Serializable {
35+
public class MovePath implements Cloneable, Serializable, Pathing {
3636
private static final MMLogger logger = MMLogger.create(MovePath.class);
3737

3838
private static final long serialVersionUID = -4258296679177532986L;
@@ -247,6 +247,7 @@ public MovePath(Game game, Entity entity, @Nullable Coords waypoint) {
247247
* Checks if there is a waypoint referenced by this MovePath.
248248
* @return true if there is a waypoint, false otherwise.
249249
*/
250+
@Override
250251
public boolean hasWaypoint() {
251252
return waypoint != null;
252253
}
@@ -255,10 +256,12 @@ public boolean hasWaypoint() {
255256
* Returns the waypoint referenced by this MovePath.
256257
* @return the waypoint, or null if there is none.
257258
*/
259+
@Override
258260
public @Nullable Coords getWaypoint() {
259261
return waypoint;
260262
}
261263

264+
@Override
262265
public Entity getEntity() {
263266
return entity;
264267
}
@@ -404,6 +407,7 @@ protected MovePath addStep(final MoveStep step) {
404407
return addStep(step, true);
405408
}
406409

410+
@Override
407411
public Set<Coords> getCoordsSet() {
408412
if (coordsSet != null) {
409413
return coordsSet;
@@ -993,6 +997,7 @@ public boolean hasActiveSupercharger() {
993997
* path, or
994998
* null if there's an issue with determining the coords
995999
*/
1000+
@Override
9961001
public @Nullable Coords getFinalCoords() {
9971002
if (getGame().useVectorMove()) {
9981003
return Compute.getFinalPosition(getEntity().getPosition(), getFinalVectors());
@@ -1006,6 +1011,7 @@ public boolean hasActiveSupercharger() {
10061011
/**
10071012
* Returns the starting {@link Coords} of this path.
10081013
*/
1014+
@Override
10091015
public @Nullable Coords getStartCoords() {
10101016
for (final Enumeration<MoveStep> e = getSteps(); e.hasMoreElements();) {
10111017
final MoveStep step = e.nextElement();
@@ -1021,6 +1027,7 @@ public boolean hasActiveSupercharger() {
10211027
* Returns the final facing if a mek were to perform all the steps in this
10221028
* path.
10231029
*/
1030+
@Override
10241031
public int getFinalFacing() {
10251032
MoveStep last = getLastStep();
10261033
if (last != null) {
@@ -1032,6 +1039,7 @@ public int getFinalFacing() {
10321039
/**
10331040
* Returns whether or not a unit would end up prone after all of the steps
10341041
*/
1042+
@Override
10351043
public boolean getFinalProne() {
10361044
if (getLastStep() != null) {
10371045
return getLastStep().isProne();
@@ -1342,6 +1350,7 @@ public static int getAdjustedFacing(final int facing, final MoveStepType movemen
13421350
/**
13431351
* Returns the number of MPs used in the path
13441352
*/
1353+
@Override
13451354
public int getMpUsed() {
13461355
if (getLastStep() != null) {
13471356
return getLastStep().getMpUsed();
@@ -1353,6 +1362,7 @@ public int getMpUsed() {
13531362
* Returns the logical number of hexes moved the path (does not count turns,
13541363
* etc).
13551364
*/
1365+
@Override
13561366
public int getHexesMoved() {
13571367
if (getLastStep() == null) {
13581368
return 0;
@@ -1363,6 +1373,7 @@ public int getHexesMoved() {
13631373
/**
13641374
* Returns the linear distance between the first and last hexes in the path.
13651375
*/
1376+
@Override
13661377
public int getDistanceTravelled() {
13671378
var currentEntityPosition = getEntity().getPosition();
13681379
if (currentEntityPosition == null) {
@@ -1378,6 +1389,7 @@ public int getDistanceTravelled() {
13781389
/**
13791390
* Returns true if the entity is jumping or if it's a flying lam.
13801391
*/
1392+
@Override
13811393
public boolean isJumping() {
13821394
return contains(MoveStepType.START_JUMP);
13831395
}

megamek/unittests/megamek/ai/neuralnetwork/BrainTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static Collection<TestValue> loadTestValues() {
163163
*/
164164
private static MovementClassification getMovementClassificationFromSplitLine(String[] values) {
165165
// The last value in the line is the classification
166-
return MovementClassification.values()[Integer.parseInt(values[values.length-1])];
166+
return MovementClassification.fromValue(Integer.parseInt(values[values.length-1]));
167167
}
168168

169169
/**

0 commit comments

Comments
 (0)