public static CoordinateStream streamBorder(ShortPoint2D center, int radius) { return streamBorder(center.x, center.y, radius); } }
public CoordinateStream streamBorder() { return streamBorder(cX, cY, maxRadius); }
private void sendManyMovables(ShortPoint2D targetPosition, List<ILogicMovable> movables) { for (int radius = 0, ringsWithoutSuccessCtr = 0; ringsWithoutSuccessCtr <= Math.max(5, 15 - radius + ringsWithoutSuccessCtr) && !movables.isEmpty(); radius++) { MutableInt numberOfSendMovables = new MutableInt(0); HexGridArea .streamBorder(targetPosition.x, targetPosition.y, radius) .filterBounds(grid.getWidth(), grid.getHeight()) .getEvery(2) .forEach((x, y) -> { Optional<ILogicMovable> movableOptional = removeMovableThatCanMoveTo(movables, x, y); movableOptional.ifPresent(movable -> { movable.moveTo(new ShortPoint2D(x, y)); numberOfSendMovables.value++; }); }); if (numberOfSendMovables.value > 0) { ringsWithoutSuccessCtr = 0; } else { ringsWithoutSuccessCtr++; } } }
private ShortPoint2D getCloseWorkablePos() { MutablePoint2D bestNeighbourPos = new MutablePoint2D(-1, -1); MutableDouble bestNeighbourDistance = new MutableDouble(Double.MAX_VALUE); // distance from start point HexGridArea.streamBorder(movable.getPosition(), 2).filter((x, y) -> super.isValidPosition(x, y) && canWorkOnPos(x, y)).forEach((x, y) -> { double distance = ShortPoint2D.getOnGridDist(x - centerPos.x, y - centerPos.y); if (distance < bestNeighbourDistance.value) { bestNeighbourDistance.value = distance; bestNeighbourPos.x = x; bestNeighbourPos.y = y; } }); if (bestNeighbourDistance.value != Double.MAX_VALUE) { return bestNeighbourPos.createShortPoint2D(); } else { return null; } }
@Test public void testGetOnGridDist() { ShortPoint2D center = new ShortPoint2D(100, 100); for (int radius = 1; radius < 30; radius++) { int expectedRadius = radius; HexGridArea.streamBorder(center.x,center.y, radius).forEach((x,y)->{ assertEquals(expectedRadius, center.getOnGridDistTo(x,y)); }); } }
area = HexGridArea.stream(x, y, (short) 1, Constants.SOLDIER_SEARCH_RADIUS); } else { area = HexGridArea.streamBorder(x, y, Constants.SOLDIER_SEARCH_RADIUS - 1);
area = HexGridArea.stream(position.x, position.y, 1, Constants.TOWER_ATTACKABLE_SEARCH_RADIUS); } else { area = HexGridArea.streamBorder(position.x, position.y, Constants.TOWER_ATTACKABLE_SEARCH_RADIUS - 1);