Package edu.tufts.hrilab.polycraft.util
Class Movement
java.lang.Object
edu.tufts.hrilab.polycraft.util.Movement
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Predicate
Check that input (x,y) is empty on all sides, and if not, find nearest location that is empty on all sides.static Predicate
Check that input (x,y) has at least one empty adjacent square, and if not, find nearest location that has an empty adjacent square.static Predicate
getClosestObject
(Symbol currX, Symbol currY, Symbol targetObject) Get location of the closest object from (currX,currY).static Symbol
getDegreesToTurn
(Symbol currDir, Symbol targetDir) Get degrees to turn to get from currDir to targetDir.static Symbol
getDirectionToFace
(Symbol currX, Symbol currY, Symbol targetX, Symbol targetY) Get which direction to face in order to face the target location from the current location.static int
getDistance
(int x1, int y1, int x2, int y2) getEmptyCorners
(Symbol x, Symbol y, Symbol radius) getEmptyDirections
(Symbol x, Symbol y, Symbol radius) Get the directions (N,S,E,W) that are empty next to the target location (x,y) with the specified radius.static Predicate
getInFront
(Symbol currX, Symbol currY, Symbol currDir) Get location directly in front of actor that's currently at (currX,currY) and facing currDir.static Predicate
getNewLocation
(Symbol currX, Symbol currY, Symbol currDir, Symbol movementKey) Get actor's new location if the actor is currently at (currX,currY), facing currDir, and moving one step in direction specified by movement key (w/a/d/x)).static Symbol
getNextDirection
(Symbol currDirection, Symbol degrees) Get next cardinal direction if actor is facing currDirection and turning specified degrees left/right.static Symbol
getObjectAt
(Symbol locX, Symbol locY) Get the object at the specified location.getPassableDirections
(int goalX, int goalY, int radius) Checks which directions around a goal location are valid directions for an actor to stand.Get the locations as "at(OBJ,x,y)".static Integer
getPathToLocationHelper
(Symbol currX, Symbol currY, Symbol targetX, Symbol targetY, Symbol distance, List<org.apache.commons.lang3.tuple.Pair<Integer, Integer>> path) For an actor currently at (currX,currY), this method plans a path so that the actor is a certain number of steps (distance) from and facing (targetX,targetY).getPathToObject
(Symbol targetObject, Symbol distance) Get the locations as "at(OBJ,x,y)".
-
Constructor Details
-
Movement
public Movement()
-
-
Method Details
-
getEmptyDirections
Get the directions (N,S,E,W) that are empty next to the target location (x,y) with the specified radius. Radius = 1 means the one block in that direction is empty, radius = 2 means two blocks in that direction are empty.- Parameters:
x
-y
-radius
-- Returns:
- directions that are empty (N,S,E,W)
-
getEmptyCorners
-
getPassableDirections
Checks which directions around a goal location are valid directions for an actor to stand.- Parameters:
goalX
-goalY
-radius
-- Returns:
-
getClosestEmptyAdjacent
Check that input (x,y) has at least one empty adjacent square, and if not, find nearest location that has an empty adjacent square.- Parameters:
x
-y
-- Returns:
- at(X, locX, locY)
-
getClosestAllEmptyAdjacent
Check that input (x,y) is empty on all sides, and if not, find nearest location that is empty on all sides.- Parameters:
x
-y
-- Returns:
- at(X, locX, locY)
-
getObjectAt
Get the object at the specified location. Returns null if nothing is at that location.- Parameters:
locX
-locY
-- Returns:
-
getDistance
public static int getDistance(int x1, int y1, int x2, int y2) -
getNewLocation
public static Predicate getNewLocation(Symbol currX, Symbol currY, Symbol currDir, Symbol movementKey) Get actor's new location if the actor is currently at (currX,currY), facing currDir, and moving one step in direction specified by movement key (w/a/d/x)).- Parameters:
currX
- current X locationcurrY
- current Y locationcurrDir
- current cardinal directionmovementKey
- polycraft movement direction (w/a/d/x)- Returns:
-
getPathToLocationHelper
public static Integer getPathToLocationHelper(Symbol currX, Symbol currY, Symbol targetX, Symbol targetY, Symbol distance, List<org.apache.commons.lang3.tuple.Pair<Integer, Integer>> path) For an actor currently at (currX,currY), this method plans a path so that the actor is a certain number of steps (distance) from and facing (targetX,targetY).- Parameters:
currX
- input starting location XcurrY
- input starting location YtargetX
- input target location XtargetY
- input target location Ydistance
- input distance from target locationpath
- output path- Returns:
- weight of path
-
getDirectionToFace
Get which direction to face in order to face the target location from the current location. This assumes the two locations are one euclidean unit away from each other (i.e., not diagonal).- Parameters:
currX
- current X locationcurrY
- current Y locationtargetX
- target X locationtargetY
- target Y location- Returns:
- cardinal direction
-
getDegreesToTurn
Get degrees to turn to get from currDir to targetDir.- Parameters:
currDir
- current cardinal directiontargetDir
- target cardinal direction- Returns:
- degrees to turn (-180 to 180). (-) left/counter-clockwise, (+) right/clockwise
-
getPathToLocation
public static List<Predicate> getPathToLocation(Symbol currX, Symbol currY, Symbol targetX, Symbol targetY, Symbol distance) Get the locations as "at(OBJ,x,y)".- Parameters:
currX
-currY
-targetX
-targetY
-distance
-- Returns:
-
getPathToObject
Get the locations as "at(OBJ,x,y)".- Parameters:
targetObject
-distance
-- Returns:
-
getNextDirection
Get next cardinal direction if actor is facing currDirection and turning specified degrees left/right.- Parameters:
currDirection
- current cardinal directiondegrees
- degrees to turn (-) left/counter-clockwise, (+) right/clockwise- Returns:
-
getInFront
Get location directly in front of actor that's currently at (currX,currY) and facing currDir.- Parameters:
currX
- current X locationcurrY
- current Y locationcurrDir
- current cardinal direction- Returns:
- at(X, locX, locY)
-
getClosestObject
Get location of the closest object from (currX,currY).- Parameters:
currX
- current X location of actorcurrY
- current Y location of actortargetObject
- target object- Returns:
- at(X, locX, locY)
-