示例#1
0
def draw_coordinates(
    coordinates: Iterable[Pos],
    including_areas: bool = False,
    distance_limit: int = None,
    bounds: Rect = Rect.at_origin(10, 10),
    empty_char: str = '·',
    safe_char: str = '#',
) -> None:
    coordinates_list = list(coordinates)

    # draw points
    canvas = dict(zip(coordinates_list, string.ascii_uppercase))

    if including_areas:
        # draw claims for part 1
        areas = claim_areas(coordinates_list, include_infinite=True)
        canvas.update((area_pos, canvas[pos].lower())
                      for pos, area in areas.items() for area_pos in area
                      if area_pos not in canvas)

    elif distance_limit is not None:
        # draw safe region for part 2
        region = safe_region(coordinates_list, distance_limit)
        canvas.update((pos, safe_char) for pos in region if pos not in canvas)

    for y in bounds.range_y():
        print("".join(
            canvas.get((x, y), empty_char) for x in bounds.range_x()))
示例#2
0
def draw_map(seed: int,
             region: Rect,
             *,
             highlighted: Iterable[Pos] = (),
             char_space='·',
             char_wall='#',
             char_highlighted='O') -> None:

    highlighted = set(highlighted)

    def char(pos: Pos) -> str:
        if pos in highlighted:
            return char_highlighted
        elif is_wall(seed, pos):
            return char_wall
        else:
            return char_space

    assert region.width <= 10
    assert region.height <= 10

    x_coor = "".join(str(x)[-1] for x in region.range_x())
    print(f"  {x_coor}")

    for y in region.range_y():
        row = ''.join(char((x, y)) for x in region.range_x())
        print(f'{y} {row}')
示例#3
0
def drawn(stars: Stars,
          bounds: Rect = None,
          char_star='*',
          char_sky='·') -> str:
    positions = set(tuple(pos) for pos, _ in stars)
    if bounds is None:
        bounds = Rect.with_all((x, y) for x, y in positions)

    return "\n".join(''.join(char_star if (x, y) in positions else char_sky
                             for x in bounds.range_x())
                     for y in bounds.range_y())
示例#4
0
def draw_region(x: int,
                y: int,
                serial: int,
                square_size: int = 3,
                margin: int = 1) -> None:
    bounds = Rect((x - margin, y - margin),
                  (x + square_size + margin - 1, y + square_size + margin - 1))

    def cell(c_x: int, c_y: int) -> str:
        left, right = " ", " "
        if c_x == bounds.left_x:
            left = ""
        elif c_x == bounds.right_x:
            right = ""
        elif c_y in range(y, y + square_size):
            if c_x == x:
                left = "["
            elif c_x == x + square_size - 1:
                right = "]"

        return f"{left}{power_level(c_x, c_y, serial):2}{right}"

    for dy in bounds.range_y():
        print("".join(cell(dx, dy) for dx in bounds.range_x()))