Class Movement

java.lang.Object
edu.tufts.hrilab.polycraft.util.Movement

public class Movement extends Object
  • Constructor Details

    • Movement

      public Movement()
  • Method Details

    • getEmptyDirections

      public static List<Direction> 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. 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

      public static List<Direction> getEmptyCorners(Symbol x, Symbol y, Symbol radius)
    • getPassableDirections

      public static List<Direction> getPassableDirections(int goalX, int goalY, int radius)
      Checks which directions around a goal location are valid directions for an actor to stand.
      Parameters:
      goalX -
      goalY -
      radius -
      Returns:
    • getClosestEmptyAdjacent

      public static Predicate getClosestEmptyAdjacent(Symbol x, Symbol y)
      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

      public static Predicate getClosestAllEmptyAdjacent(Symbol x, Symbol y)
      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

      public static Symbol getObjectAt(Symbol locX, Symbol locY)
      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 location
      currY - current Y location
      currDir - current cardinal direction
      movementKey - 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 X
      currY - input starting location Y
      targetX - input target location X
      targetY - input target location Y
      distance - input distance from target location
      path - output path
      Returns:
      weight of path
    • getDirectionToFace

      public 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. This assumes the two locations are one euclidean unit away from each other (i.e., not diagonal).
      Parameters:
      currX - current X location
      currY - current Y location
      targetX - target X location
      targetY - target Y location
      Returns:
      cardinal direction
    • getDegreesToTurn

      public static Symbol getDegreesToTurn(Symbol currDir, Symbol targetDir)
      Get degrees to turn to get from currDir to targetDir.
      Parameters:
      currDir - current cardinal direction
      targetDir - 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

      public static List<Predicate> getPathToObject(Symbol targetObject, Symbol distance)
      Get the locations as "at(OBJ,x,y)".
      Parameters:
      targetObject -
      distance -
      Returns:
    • getNextDirection

      public static Symbol getNextDirection(Symbol currDirection, Symbol degrees)
      Get next cardinal direction if actor is facing currDirection and turning specified degrees left/right.
      Parameters:
      currDirection - current cardinal direction
      degrees - degrees to turn (-) left/counter-clockwise, (+) right/clockwise
      Returns:
    • getInFront

      public 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.
      Parameters:
      currX - current X location
      currY - current Y location
      currDir - current cardinal direction
      Returns:
      at(X, locX, locY)
    • getClosestObject

      public static Predicate getClosestObject(Symbol currX, Symbol currY, Symbol targetObject)
      Get location of the closest object from (currX,currY).
      Parameters:
      currX - current X location of actor
      currY - current Y location of actor
      targetObject - target object
      Returns:
      at(X, locX, locY)