Skip to content

Commit bb0ee1a

Browse files
author
Bytekeeper
committed
Additional inRadius and estimation function.
1 parent be38023 commit bb0ee1a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/org/bk/ass/Simulator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@
2222
* Be cautious when modifying {@link Agent}s after they have been added to the simulation.
2323
*/
2424
public class Simulator {
25+
/**
26+
* Use to count health and shields as equal, maybe useful in PvP?
27+
*/
2528
public static final ToIntFunction<Agent> HEALTH_AND_SHIELD =
26-
agent -> agent.getHealth() + agent.getShields();
29+
agent -> agent.getHealth() + agent.getShields();
30+
/**
31+
* Use to count shields as half the value of health.
32+
*/
33+
public static final ToIntFunction<Agent> HEALTH_AND_HALFED_SHIELD =
34+
agent -> agent.getHealth() + agent.getShields() / 2;
2735

2836
private static final int MAX_MAP_DIMENSION = 8192;
2937
private static final int TILE_SIZE = 16;

src/main/java/org/bk/ass/query/PositionQueries.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ public Collection<U> inRadius(int x, int y, int radius, Predicate<U> criteria) {
9191
return new RadiusAreaSearcher(x, y, radius, criteria).search();
9292
}
9393

94+
/**
95+
* Returns all elements matching the given criteria in the given radius around the given element,
96+
* including those on the border. <em>The given criteria might be called often, make sure it is
97+
* fast!</em>`
98+
*/
99+
public Collection<U> inRadius(U u, int radius, Predicate<U> criteria) {
100+
if (radius <= 0) throw new IllegalArgumentException("radius should be > 0");
101+
Position position = positionExtractor.apply(u);
102+
return new RadiusAreaSearcher(position.x, position.y, radius, criteria).search();
103+
}
104+
94105
@Override
95106
public Iterator<U> iterator() {
96107
List<U> items = new ArrayList<>();

0 commit comments

Comments
 (0)