public MoveStep getLastStep() { for (int i = getStepVector().size() - 1; i >= 0; i--) { MoveStep last = getStepVector().get(i); if (last != null) { return last; } } return null; }
@Override public int compare(final MovePath first, final MovePath second) { final int firstSteps = first.getStepVector().size(); final int secondSteps = second.getStepVector().size(); return firstSteps - secondSteps; } }
public Set<Coords> getCoordsSet() { if (coordsSet != null) { return coordsSet; } synchronized (COORD_SET_LOCK) { if (coordsSet != null) { return coordsSet; } coordsSet = new HashSet<>(); for (MoveStep step : getStepVector()) { if (step.getPosition() == null) { continue; } coordsSet.add(step.getPosition()); } } return coordsSet; }
/** * Determines if the given move path is "redundant". * In this case, it means that the path has not visited any new hexes. * @param mp The move path to examine. * @return Whether or not the move path is redundant. */ // goes through a path. // if it does not take us off-board, records the coordinates it visits // returns true if this path visits hexes that have not been visited before protected boolean pathIsRedundant(MovePath mp) { boolean newHexVisited = false; if(!mp.fliesOffBoard()) { for(MoveStep step : mp.getStepVector()) { if(!visitedCoords.containsKey(step.getPosition())) { visitedCoords.put(step.getPosition(), mp); newHexVisited = true; } } } return newHexVisited; } }
Vector<MoveStep> steps = path.getStepVector();
@Test public void testGetLastStep() { IGame mockGame = Mockito.mock(IGame.class); Entity mockMech = Mockito.mock(BipedMech.class); Vector<MoveStep> stepVector = new Vector<MoveStep>(); MoveStep mockStep1 = Mockito.mock(MoveStep.class); stepVector.add(mockStep1); MoveStep mockStep2 = Mockito.mock(MoveStep.class); stepVector.add(mockStep2); MoveStep mockStep3 = Mockito.mock(MoveStep.class); stepVector.add(mockStep3); MoveStep mockStep4 = Mockito.mock(MoveStep.class); stepVector.add(mockStep4); MovePath testPath = Mockito.spy(new MovePath(mockGame, mockMech)); Mockito.doReturn(stepVector).when(testPath).getStepVector(); Assert.assertEquals(mockStep4, testPath.getLastStep()); stepVector.add(null); Assert.assertEquals(mockStep4, testPath.getLastStep()); } }
startingEdge.getStepVector().size() == 0) { MovePath fleePath = startingEdge.clone(); fleePath.addStep(MoveStepType.FLEE);
boolean intersected = false; for(MoveStep step : startingPath.getStepVector()) { if(step.getPosition() == joinedPath.getFinalCoords()) { matchFacingToPath(joinedPath, step); for(MoveStep step : endingPath.getStepVector()) {
Coords previousCoords = null; MoveStep lastStep = path.getLastStep(); for (MoveStep step : path.getStepVector()) { Coords coords = step.getPosition(); if ((coords == null) || coords.equals(previousCoords)) {
private void adjustPathForBridge(MovePath path) { boolean needsAdjust = false; for (Coords c : path.getCoordsSet()) { IHex hex = getGame().getBoard().getHex(c); if ((hex != null) && hex.containsTerrain(Terrains.BRIDGE)) { if (getGame().getBoard().getBuildingAt(c).getCurrentCF(c) >= path.getEntity().getWeight()) { needsAdjust = true; break; } else { needsAdjust = false; break; } } } if (!needsAdjust) { return; } MovePath adjusted = new MovePath(getGame(), path.getEntity()); adjusted.addStep(MoveStepType.CLIMB_MODE_ON); adjusted.addSteps(path.getStepVector(), true); adjusted.addStep(MoveStepType.CLIMB_MODE_OFF); path.replaceSteps(adjusted.getStepVector()); }
Mockito.when(mockPath.getLastStep()).thenReturn(mockFinalStep); Mockito.when(mockPath.getFinalCoords()).thenReturn(testFinalCoords); Mockito.when(mockPath.getStepVector()).thenReturn(stepVector);
for (final MoveStep step : mp.getStepVector()){ if (step.getType() == MoveStepType.MANEUVER){ return false;