-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarmer.java
More file actions
46 lines (33 loc) · 1.35 KB
/
Farmer.java
File metadata and controls
46 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import processing.core.PImage;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
public abstract class Farmer extends ActivityEntity implements Move, Transform, PathingStrategy {
private final int resourceLimit;
public Farmer(String id, Point position, double animationPeriod, double actionPeriod, int resourceLimit, List<PImage> images) {
super(id, position, animationPeriod, actionPeriod, images);
this.resourceLimit = resourceLimit;
}
@Override
public Point nextPosition(WorldModel world, Point destPos) {
Predicate<Point> canPassThrough = p -> world.withinBounds(p)
&& (world.getOccupant(p).isEmpty() || world.getOccupant(p).get().getClass().equals(WolfSearching.class));
BiPredicate<Point, Point> withinReach = Point::adjacent;
PathingStrategy strategy = new AStarPathingStrategy();
List<Point> path = strategy.computePath(
getPosition(),
destPos,
canPassThrough,
withinReach,
PathingStrategy.CARDINAL_NEIGHBORS
);
if (path == null || path.isEmpty()) {
return getPosition();
}
return path.getFirst();
}
public int getResourceLimit() {
return resourceLimit;
}
}