private void adjustPathsForBridges(List<MovePath> paths) { if (!worryAboutBridges()) { return; } for (MovePath path : paths) { adjustPathForBridge(path); } }
getOwner().methodBegin(getClass(), METHOD_NAME); try { Set<Integer> returnSet = new TreeSet<>(); return returnSet; for (Integer id : getUnitPotentialLocations().keySet()) { if (groundOnly && getGame().getEntity(id) != null && getGame().getEntity(id).isAero()) { continue; if (getUnitPotentialLocations().get(id).contains(CoordFacingCombo.createCoordFacingCombo (location, facing))) { returnSet.add(id); getOwner().methodEnd(getClass(), METHOD_NAME);
void clear() { final String METHOD_NAME = "clear()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { getUnitPaths().clear(); getUnitPotentialLocations().clear(); getLastKnownLocations().clear(); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
Coords getLastKnownCoords(Integer entityId) { final String METHOD_NAME = "getLastKnownCoords(Integer)"; getOwner().methodBegin(getClass(), METHOD_NAME); try { CoordFacingCombo ccr = getLastKnownLocations().get(entityId); if (ccr == null) { return null; } return ccr.getCoords(); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
getOwner().methodBegin(getClass(), METHOD_NAME); try { getLastKnownLocations().put( mover.getId(), CoordFacingCombo.createCoordFacingCombo( getUnitPaths().remove(mover.getId()); AeroGroundPathFinder apf = AeroGroundPathFinder.getInstance(getGame()); MovePath startPath = new MovePath(getGame(), mover); apf.run(startPath); paths.addAll(apf.getAllComputedPathsUncategorized()); NewtonianAerospacePathFinder npf = NewtonianAerospacePathFinder.getInstance(getGame()); npf.run(new MovePath(game, mover)); paths.addAll(npf.getAllComputedPathsUncategorized()); AeroSpacePathFinder apf = AeroSpacePathFinder.getInstance(getGame()); apf.run(new MovePath(game, mover)); paths.addAll(apf.getAllComputedPathsUncategorized()); AeroLowAltitudePathFinder apf = AeroLowAltitudePathFinder.getInstance(getGame()); apf.run(new MovePath(game, mover)); paths.addAll(apf.getAllComputedPathsUncategorized()); InfantryPathFinder ipf = InfantryPathFinder.getInstance(getGame()); ipf.run(new MovePath(game, mover)); paths.addAll(ipf.getAllComputedPathsUncategorized());
getPathEnumerator().getLastKnownLocations().remove(id); getPathEnumerator().getUnitMovableAreas().remove(id); getPathEnumerator().getUnitPaths().remove(id); getPathEnumerator().getUnitPotentialLocations().remove(id); return; getPathEnumerator().getEntitiesWithLocation( getGame().getEntity(id).getPosition(), true)); if (getPathEnumerator().getLastKnownLocations() .containsKey(id)) { if ((getGame().getEntity(id) != null) && getGame().getEntity(id).isSelectableThisTurn()) { toDirty.addAll(getPathEnumerator() .getEntitiesWithLocation(getPathEnumerator() .getLastKnownLocations().get(id) .getCoords(), true)); getDirtyUnits().add(id); } else if (entity != null) { getPathEnumerator().getLastKnownLocations().put(id, CoordFacingCombo.createCoordFacingCombo(entity));
Princess princess = new Princess("test", "localhost", 2020, LogLevel.DEBUG); princess.getGame().setBoard(this.game.getBoard()); PathEnumerator pathEnum = new PathEnumerator(princess, this.game); pathEnum.recalculateMovesFor(this.selectedEntity); ConvexBoardArea cba = pathEnum.getUnitMovableAreas().get(this.selectedEntity.getId()); for(int x = 0; x < game.getBoard().getWidth(); x++) { for(int y = 0; y < game.getBoard().getHeight(); y++) {
/** * From a list of potential moves, make a potential ending location chart */ void updateUnitLocations(Entity entity, List<MovePath> paths) { final String METHOD_NAME = "updateUnitLocations(Entity, ArrayList<MovePath>)"; getOwner().methodBegin(getClass(), METHOD_NAME); try { // clear previous locations for this entity getUnitPotentialLocations().remove(entity.getId()); // Set<CoordFacingCombo> toAdd = new HashSet<>(); for (MovePath path : paths) { toAdd.add(CoordFacingCombo.createCoordFacingCombo(path)); } getUnitPotentialLocations().put(entity.getId(), toAdd); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
getOwner().methodBegin(getClass(), METHOD_NAME); try { LogAeroMoveLegalityEvaluation("illegal move with null last step", path); return false; LogAeroMoveLegalityEvaluation("illegal move without return/off at the end", path); return false; if ((path.getLastStep().getType() != MoveStepType.RETURN) && (path.getLastStep().getType() != MoveStepType.OFF)) { LogAeroMoveLegalityEvaluation("not all velocity used without return/off at the end", path); return false; getOwner().methodEnd(getClass(), METHOD_NAME);
continue; if (((!getPathEnumerator().getLastKnownLocations().containsKey(entity.getId())) || (!getPathEnumerator().getLastKnownLocations().get(entity.getId()) .equals(CoordFacingCombo.createCoordFacingCombo(entity))))) { if (entity != null) { getOwner().log(getClass(), METHOD_NAME, "recalculating paths for " + entity.getDisplayName()); getPathEnumerator().recalculateMovesFor(entity); getOwner().log(getClass(), METHOD_NAME, "finished recalculating paths for " + entity .getDisplayName());
continue; if (position.equals(getPathEnumerator().getLastKnownCoords(entity.getId()))) { continue; // no sense in updating a unit if it hasn't moved getPathEnumerator().clear(); for (Entity entity : getGame().getEntitiesVector()) { if (entity.isActive() && entity.isDeployed() && entity.getPosition() != null) {
private boolean worryAboutBridges() { if (mapHasBridges != null) { return mapHasBridges.get(); } synchronized (BRIDGE_LOCK) { if (mapHasBridges != null) { return mapHasBridges.get(); } mapHasBridges = new AtomicBoolean(getGame().getBoard() .containsBridges()); } return mapHasBridges.get(); } }
private void LogAeroMoveLegalityEvaluation(String whyNot, MovePath path) { this.getOwner().log(this.getClass(), "isLegalAeroMove", LogLevel.DEBUG, path.length() + ":" + path.toString() + ":" + whyNot); }
public Precognition(Princess owner) { this.owner = owner; this.game = new Game(); getGame().addGameListener(new GameListenerAdapter() { @Override public void gameEntityChange(GameEntityChangeEvent changeEvent) { getEventsToProcess().add(changeEvent); wakeUp(); } @Override public void gamePhaseChange(GamePhaseChangeEvent changeEvent) { getEventsToProcess().add(changeEvent); wakeUp(); } }); setPathEnumerator(new PathEnumerator(owner, getGame())); // Initialize ECM Info, especially important if Princess added mid-game ecmInfo = ComputeECM.computeAllEntitiesECMInfo( getGame().getEntitiesVector()); }
@Override public boolean shouldStay(MovePath movePath) { boolean isLegal = movePath.isMoveLegal(); return isLegal && (Compute.stackingViolation(getGame(), mover.getId(), movePath.getFinalCoords()) == null); } };
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()); }