bpoptimizer package
bpoptimizer.floor module
This class is used for internally representing a BlockParty floor
- class bpoptimizer.floor.Floor(image: Union[str, numpy.ndarray], interval: float = 0.25)[source]
Bases:
object- __init__(image: Union[str, numpy.ndarray], interval: float = 0.25)[source]
Reads an image file representing a BlockParty floor and store an internal representation of it
- Args:
- image (Union[str, np.ndarray]):
path to image of floor or a valid numpy array representation of an image
- interval (float, optional):
dictates how fine the spot calculation will be, defaults to 0.25 meaning that every position checked will be 0.25 blocks apart. Note: values below 0.25 can get very slow!
- Attributes:
- floor (np.ndarray):
the internal 2D representation of the floor where each unique colour is a different integer
- Raises:
TypeError: if provided floor is not a path as string or numpy array FileNotFoundError: if provided path is invalid AssertionError: if floor is of unexpected size or has too many colours
- BLACK = (0, 0, 0)
- CANVAS_COLOURS = {0: (255, 0, 0), 1: (255, 152, 173), 2: (255, 165, 0), 3: (255, 255, 0), 4: (191, 255, 0), 5: (0, 255, 0), 6: (0, 128, 128), 7: (48, 204, 255), 8: (0, 0, 255), 9: (128, 0, 128), 10: (255, 0, 255), 11: (101, 67, 33), 12: (100, 100, 100), 13: (220, 220, 220), 14: (0, 0, 0), 15: (255, 255, 255)}
- MAX_COLOURS = 16
- RED = (255, 0, 0)
- WHITE = (255, 255, 255)
- property count: int
Number of colours in the floor
- display(spot: Optional[numpy.ndarray] = None, reachable_distance: float = inf, scale: int = 30, path: Optional[str] = None) numpy.ndarray[source]
Displays an image of the floor
- Args:
- spot (np.ndarray, optional):
if provided, draws the location, lines to all unique colours from the location and writes the distance to farther away colours as well
- rechable_distance (float, optional):
if provided, highlights any spots that would be too far to reach from the spot being display
- scale (int, optional):
factor to upscale original image by, defaults to 30
- path (str, optional):
saves image to specified path if provided along with returning image as numpy array
- Returns:
- np.ndarray:
the image to display represented as a numpy array
- get_spots(reachable_distance: float = inf) numpy.ndarray[source]
Returns a list of the best spots based on how far you are able to travel
For determining the best spots, we first try to maximize the number of unique colours that can be reached, from those candidates we take the ones which minimize the distance to the farthest colour that can be reached and finally we reduce those candidates by taking the spots with the lowest sum of squared distances to the colours that can be reached. If there are multiple candidates left, all are returned.
- Args:
- reachable_distance (float, optional):
the maximum number of blocks that you can travel, no limit if not provided
- Returns:
List[Tuple[int, int]]: a list of coords for the best spots
- static simplify_image(image: numpy.ndarray) numpy.ndarray[source]
Removes pixel data from an image to produce an array where each pixel is represented by a unique integer
- Args:
- image (np.ndarray):
the image to simplify
- Returns:
np.ndarray: the simplified image with the same height and width dimensions