/** * Helper function that handles logic related to potentially adding a generated child path * to the list of child paths. */ private void processChild(MovePath child, List<MovePath> children, Set<Coords> visitedCoords) { if(!visitedCoords.contains(child.getFinalCoords()) && isLegalMove(child)) { visitedCoords.add(child.getFinalCoords()); children.add(child); } }
public boolean shouldStop(MovePath e) { return destination.equals(e.getFinalCoords()); } }
public CoordsWithFacing(MovePath mp) { this(mp.getFinalCoords(), mp.getFinalFacing()); }
protected double calculateAggressionMod(Entity movingUnit, MovePath path, IGame game, StringBuilder formula) { double distToEnemy = distanceToClosestEnemy(movingUnit, path.getFinalCoords(), game); if ((distToEnemy == 0) && !(movingUnit instanceof Infantry)) { distToEnemy = 2; } double aggression = getOwner().getBehaviorSettings() .getHyperAggressionValue(); double aggressionMod = distToEnemy * aggression; formula.append(" - aggressionMod [") .append(LOG_DECIMAL.format(aggressionMod)).append(" = ") .append(LOG_DECIMAL.format(distToEnemy)).append(" * ") .append(LOG_DECIMAL.format(aggression)).append("]"); return aggressionMod; }
protected double calculateHerdingMod(Coords friendsCoords, MovePath path, StringBuilder formula) { if (friendsCoords == null) { formula.append(" - herdingMod [0 no friends]"); return 0; } double distanceToAllies = friendsCoords.distance(path.getFinalCoords()); double herding = getOwner().getBehaviorSettings() .getHerdMentalityValue(); double herdingMod = distanceToAllies * herding; formula.append(" - herdingMod [").append(LOG_DECIMAL.format(herdingMod)) .append(" = ") .append(LOG_DECIMAL.format(distanceToAllies)).append(" * ") .append(LOG_DECIMAL.format(herding)) .append("]"); return herdingMod; }
static CoordFacingCombo createCoordFacingCombo(MovePath p) { if (p == null) { return null; } return createCoordFacingCombo(p.getFinalCoords(), p.getFinalFacing()); }
/** * Compares MovePaths based on distance from final position to * destination. If those distances are equal then spent movement points * are compared. * */ @Override public int compare(MovePath mp1, MovePath mp2) { int d1 = mp1.getFinalCoords().distance(destination); int d2 = mp2.getFinalCoords().distance(destination); if (d1 != d2) return d1 - d2; else return mp1.getMpUsed() - mp2.getMpUsed(); } }
public Coords getSecondFinalPosition(Coords startPos) { Coords priorPos = startPos; Coords finalPos = getFinalCoords(); // if we moved one or fewer hexes, then just return starting position if (getHexesMoved() < 2) { return priorPos; } for (final Enumeration<MoveStep> i = getSteps(); i.hasMoreElements(); ) { final MoveStep step = i.nextElement(); if (step.getPosition() != finalPos) { priorPos = step.getPosition(); } } return priorPos; }
public int compare(final MovePath first, final MovePath second) { final int firstDist = first.getMpUsed() + first.getFinalCoords().distance(destination) + getFacingDiff(first); final int secondDist = second.getMpUsed() + second.getFinalCoords().distance(destination) + getFacingDiff(second); return firstDist - secondDist; }
protected double calculateSelfPreservationMod(Entity movingUnit, MovePath path, IGame game, StringBuilder formula) { if (getOwner().getFallBack() || movingUnit.isCrippled()) { int newDistanceToHome = distanceToHomeEdge(path.getFinalCoords(), getOwner().getHomeEdge(movingUnit), game); double selfPreservation = getOwner().getBehaviorSettings() .getSelfPreservationValue(); double selfPreservationMod = newDistanceToHome * selfPreservation; formula.append(" - selfPreservationMod [") .append(LOG_DECIMAL.format(selfPreservationMod)) .append(" = ").append(LOG_DECIMAL.format(newDistanceToHome)) .append(" * ") .append(LOG_DECIMAL.format(selfPreservation)).append("]"); return selfPreservationMod; } return 0.0; }
@Override public void performAction() { int curDir = cmd.getFinalFacing(); int dir = curDir; dir = (dir + 7) % 6; Coords curPos = cmd.getFinalCoords(); Coords target = curPos.translated(dir); // We need to set this to get the rotate behavior shiftheld = true; currentMove(target); shiftheld = false; clientgui.bv.drawMovementData(ce(), cmd); } });
@Override public void performAction() { int curDir = cmd.getFinalFacing(); int dir = curDir; dir = (dir + 5) % 6; Coords curPos = cmd.getFinalCoords(); Coords target = curPos.translated(dir); // We need to set this to get the rotate behavior shiftheld = true; currentMove(target); shiftheld = false; clientgui.bv.drawMovementData(ce(), cmd); } });
/** * Convenience function encapsulating logic for whether, if we continue forward * along the current path in the current direction, we will run off the board * @return */ public boolean nextForwardStepOffBoard() { return !game.getBoard().contains(getFinalCoords().translated(getFinalFacing())); } }
public PathState(MovePath p) { location = p.getFinalCoords(); facing = p.getFinalFacing(); hulldown = p.getFinalHullDown() || p.getFinalProne(); isjumping = p.isJumping(); }
private MovePath generateMockPath(int x, int y, Entity mockEntity) { final MovePath mockPath = Mockito.mock(MovePath.class); Mockito.when(mockPath.getEntity()).thenReturn(mockEntity); final Coords mockMyCoords = new Coords(x, y); Mockito.when(mockPath.getFinalCoords()).thenReturn(mockMyCoords); Mockito.when(mockPath.getFinalFacing()).thenReturn(0); return mockPath; }
@Override public boolean shouldStay(MovePath movePath) { boolean isLegal = movePath.isMoveLegal(); return isLegal && (Compute.stackingViolation(getGame(), mover.getId(), movePath.getFinalCoords()) == null); } };
public Key getKey() { return new Key(getFinalCoords(), getFinalFacing(), getFinalProne() ? 0 : isJumping() ? 1 : 2); }
/** * Returns the distance between the highest elevation in the jump path and * the elevation at the landing point. This gives the largest distance the * unit has fallen during the jump. */ public int getJumpMaxElevationChange() { return getMaxElevation() - getGame().getBoard().getHex(getFinalCoords()).getLevel(); }
@Override public CoordsWithFacing getDestination(MovePath e) { MoveStep lastStep = e.getLastStep(); /* * entity moving backwards is like entity with an opposite facing * moving forwards :) NOOOT */ CoordsWithFacing cfw; if (lastStep != null && lastStep.isThisStepBackwards()) { Facing f = Facing.valueOfInt(e.getFinalFacing()); cfw = new CoordsWithFacing(e.getFinalCoords(), f.getOpposite().getIntValue()); } else { cfw = new CoordsWithFacing(e); } return cfw; }
/** * Determines if the given move path ends on the given board edge * @param movePath The move path to check. * @param edge The edge to check for. * @return True or false. */ private boolean isOnBoardEdge(MovePath movePath, int destinationRegion) { Coords coords = movePath.getFinalCoords(); switch(destinationRegion) { case Board.START_N: return coords.getY() == 0; case Board.START_S: return coords.getY() == movePath.getGame().getBoard().getHeight() - 1; case Board.START_E: return coords.getX() == movePath.getGame().getBoard().getWidth() - 1; case Board.START_W: return coords.getX() == 0; default: return false; } }