public class TargetVisitChecker
extends java.lang.Object
The set of locations is represented as an array of (non-null) Google Maps LatLng objects. The path array contains indexes of the captured targets in the order they were captured. To ensure that's it's possible to capture all targets, the path array has the same size as the targets array. If not all targets have been captured yet, unused slots of the path array have the value -1. The path array is filled starting at the beginning, so all instances of -1 are contiguous at the end of the array.
Constructor and Description |
---|
TargetVisitChecker() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkSnakeRule(com.google.android.gms.maps.model.LatLng[] targets,
int[] path,
int tryVisit)
Determines whether the specified target can be visited without violating the snake rule.
|
static int |
getVisitCandidate(com.google.android.gms.maps.model.LatLng[] targets,
int[] path,
com.google.android.gms.maps.model.LatLng currentLocation,
int range)
Gets an index of an unvisited target within the specified range of the current location.
|
static boolean |
isTargetVisited(int[] path,
int targetIndex)
Determines whether a target is already visited.
|
static boolean |
isTargetWithinRange(com.google.android.gms.maps.model.LatLng[] targets,
int targetIndex,
com.google.android.gms.maps.model.LatLng currentLocation,
int range)
Determines whether the specified target is within range of the current location.
|
static int |
visitTarget(int[] path,
int targetIndex)
Marks a target captured by putting its index in the first available (-1) slot of the path array.
|
public static boolean checkSnakeRule(com.google.android.gms.maps.model.LatLng[] targets, int[] path, int tryVisit)
The snake rule is violated if the new line created between the last captured target and this new target would cross the straight line connecting two sequentially captured targets. For example, there is a line between the first-captured and second-captured targets, and between the second-captured and third-captured targets, but no line directly connecting the first-captured and third-captured targets. If zero or one targets have been captured so far, there are no lines and it is permissible to capture any target.
It is assumed that all parameters are valid. The two arrays are non-null and of the same length. All coordinates are valid. The index of the target to visit is a valid index into the coordinate arrays. The index of the target to visit does not appear in the path array (i.e. the target has not been visited yet). No existing lines violate the snake rule.
This function should not modify the arrays it receives.
targets
- positions of all targetspath
- indexes of targets visited so far (-1 for empty slots)tryVisit
- index of the target to try to visitpublic static int getVisitCandidate(com.google.android.gms.maps.model.LatLng[] targets, int[] path, com.google.android.gms.maps.model.LatLng currentLocation, int range)
It is assumed that all parameters are valid. The two arrays are non-null and of the same length. All coordinates are valid. The range is positive.
This function should not modify the arrays it receives.
targets
- positions of all targetspath
- indexes of targets visited so far (same size as targets, -1 for empty slots)currentLocation
- the current locationrange
- maximum distance to target, in meterspublic static boolean isTargetVisited(int[] path, int targetIndex)
A target is visited if its index appears in the path array.
It is assumed that the index is valid. This function should not modify the array it receives.
path
- indexes of targets visited so far (-1 for empty slots)targetIndex
- the index of the target to check for visitednesspublic static boolean isTargetWithinRange(com.google.android.gms.maps.model.LatLng[] targets, int targetIndex, com.google.android.gms.maps.model.LatLng currentLocation, int range)
It is assumed that all parameters are valid. All coordinates are valid. The range is positive.
This function should not modify the array it receives.
targets
- coordinates of all targets in the gametargetIndex
- the index (for the targets array) of the target to check for proximitycurrentLocation
- the player's current location to check for proximity to the targetrange
- the proximity thresholdpublic static int visitTarget(int[] path, int targetIndex)
It is assumed that all parameters are valid. The path array is non-null and does not yet contain the target index. The target index is non-negative.
path
- the path arraytargetIndex
- the target being visited