@Override protected Vector<Minefield> calculateMinefieldDeployment() { final String METHOD_NAME = "calculateMinefieldDeployment()"; methodBegin(getClass(), METHOD_NAME); try { // currently returns no minefields // make an empty vector return new Vector<>(); } finally { methodEnd(getClass(), METHOD_NAME); } }
ArrayList<WeightedPath> getTopPaths(Entity entity, IGame game, int npaths) { final String METHOD_NAME = "getTopPaths(Entity, IGame, int)"; owner.methodBegin(getClass(), METHOD_NAME); try { ArrayList<WeightedPath> allpaths = getAllWeightedPaths(entity, game); Collections.sort(allpaths); return (ArrayList<WeightedPath>) allpaths.subList(0, npaths); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
@Override protected MovePath calculateMoveTurn() { final String METHOD_NAME = "calculateMoveTurn()"; methodBegin(getClass(), METHOD_NAME); try { return continueMovementFor(getEntityToMove()); } finally { methodEnd(getClass(), METHOD_NAME); } }
synchronized void unPause() { final String METHOD_NAME = "unpause()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { getWaitWhenDone().set(false); notifyAll(); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
/** * Tells the thread there's something to do Note, you can't just call * notifyAll in the event listener because it doesn't have the thread * something something. */ private synchronized void wakeUp() { final String METHOD_NAME = "wake_up()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { notifyAll(); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
/** * Returns a vertex, with zero starting at the upper left of the hex */ public Coords getVertexNum(int i) { final String METHOD_NAME = "getVertexNum(int)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); if (edges[i] == null || edges[(i + 1) % 6] == null) { System.err.println(new IllegalStateException("Edge[" + i + "] is NULL.")); return null; } return edges[i].getIntersection(edges[(i + 1) % 6]); } finally { owner.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); } }
private void pause() { final String METHOD_NAME = "pause()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { getWaitWhenDone().set(true); while (!getWaiting().get() && !getDone().get()) { try { Thread.sleep(100); } catch (InterruptedException ignored) { } } } 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); } }
/** * Returns the best path of a list of ranked paths. * * @param ps The list of ranked paths to process * @return "Best" out of those paths */ public RankedPath getBestPath(List<RankedPath> ps) { final String METHOD_NAME = "getBestPath(ArrayList<Rankedpath>)"; getOwner().methodBegin(PathRanker.class, METHOD_NAME); try { if (ps.size() == 0) { return null; } return Collections.max(ps); } finally { getOwner().methodEnd(PathRanker.class, METHOD_NAME); } }
/** * returns true if a point is inside the area * false if it is not */ public boolean contains(Coords c) { final String METHOD_NAME = "contains(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); if (edges[0] == null) { return false; } for (int i = 0; i < 6; i++) { if (edges[i].judgePoint(c) > 0) { return false; } } return true; } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
void addCoordFacingCombos(Iterator<CoordFacingCombo> cfit) { final String METHOD_NAME = "addCoordFacingCombos(Iterator<CoordFacingCombo>)"; owner.methodBegin(getClass(), METHOD_NAME); try { while (cfit.hasNext()) { CoordFacingCombo cf = cfit.next(); if(cf != null && owner.getGame().getBoard().contains(cf.coords)) { expandToInclude(cf.getCoords()); } } } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
@Override protected Vector<Coords> calculateArtyAutoHitHexes() { final String METHOD_NAME = "calculateArtyAutoHitHexes()"; methodBegin(getClass(), METHOD_NAME); try { // currently returns no artillery hit spots // make an empty list final PlayerIDandList<Coords> artyAutoHitHexes = new PlayerIDandList<>(); // attach my player id to it artyAutoHitHexes.setPlayerID(getLocalPlayer().getId()); return artyAutoHitHexes; } finally { methodEnd(getClass(), METHOD_NAME); } }
/** * 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); } }
/** * expands the board area to include point onc */ void expandToInclude(Coords onc) { final String METHOD_NAME = "expandToInclude(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); for (int i = 0; i < 6; i++) { if ((edges[i] == null) || (edges[i].judgePoint(onc) > 0)) { edges[i] = new HexLine(onc, i, owner); } } setEdges(edges); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
/** * This function only makes sense for directions 1,2,4,5 * Note that the function getXfromY would be multvalued */ public int getYfromX(int x) { final String METHOD_NAME = "getYfromX(int)"; owner.methodBegin(getClass(), METHOD_NAME); try { if ((getDirection() == 0) || (getDirection() == 3)) { return 0; } if ((getDirection() == 1) || (getDirection() == 4)) { return getIntercept() - ((x + 1) / 2); //halfs round down } // direction==5||direction==2 return getIntercept() + ((x) / 2); //halfs round down } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
/** * returns -1 if the point is to the left of the line * +1 if the point is to the right of the line * and 0 if the point is on the line */ public int judgePoint(Coords c) { final String METHOD_NAME = "judgePoint(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine comparor = new HexLine(c, getDirection(), owner); if (comparor.getIntercept() < getIntercept()) { return (getDirection() < 3) ? -1 : 1; } else if (comparor.getIntercept() > getIntercept()) { return (getDirection() < 3) ? 1 : -1; } return 0; } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
/** * Gives the distance to the closest enemy unit, or zero if none exist * * @param me Entity who has enemies * @param position Coords from which the closest enemy is found * @param game IGame that we're playing */ public double distanceToClosestEnemy(Entity me, Coords position, IGame game) { final String METHOD_NAME = "distanceToClosestEnemy(Entity, Coords, IGame)"; getOwner().methodBegin(BasicPathRanker.class, METHOD_NAME); try { Entity closest = findClosestEnemy(me, position, game); if (closest == null) { return 0; } return closest.getPosition().distance(position); } finally { getOwner().methodEnd(BasicPathRanker.class, METHOD_NAME); } }
/** * Returns the (euclidian distance) closest point on this * line to another point */ public Coords getClosestPoint(Coords c) { final String METHOD_NAME = "getClosestPoint(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { if ((getDirection() == 0) || (getDirection() == 3)) { //technically two points are equidistant, // but who's counting return new Coords(getIntercept(), c.getY()); } else if ((getDirection() == 1) || (getDirection() == 4)) { double myx = (-2.0 / 3.0) * (getIntercept() - 0.5 - c.getY() - (2.0 * c.getX())); return new Coords((int) myx, getYfromX((int) myx)); } double myx = (-5.0 / 3.0) * (getIntercept() - (double) c.getY() - (2.0 * c.getX())); return new Coords((int) myx, getYfromX((int) myx)); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
WeaponAttackAction getWeaponAttackAction() { final String METHOD_NAME = "getWeaponAttackAction(IGame)"; owner.methodBegin(getClass(), METHOD_NAME); try { if (null != getAction()) { return getAction(); } if (!getWeapon().getType().hasFlag(WeaponType.F_ARTILLERY)) { setAction(new WeaponAttackAction(getShooter().getId(), getTarget().getTargetId(), getShooter().getEquipmentNum(getWeapon()))); } else { setAction(new ArtilleryAttackAction(getShooter().getId(), getTarget().getTargetType(), getTarget().getTargetId(), getShooter().getEquipmentNum(getWeapon()), getGame())); } if (getAction() == null) { setProbabilityToHit(0); return null; } setProbabilityToHit(Compute.oddsAbove(getAction().toHit(getGame()).getValue(), getShooterState().hasNaturalAptGun()) / 100.0); return getAction(); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }