| 16 | |
| 17 | |
| 18 | class LazerCutter(Agent): |
| 19 | |
| 20 | def __init__(self, port: int, location: Point): |
| 21 | super().__init__(port, location) |
| 22 | self.powered = False |
| 23 | self.cutter_position: Point = Point(0, 0) |
| 24 | |
| 25 | # self.plate |
| 26 | # # using x left-right, y top-bottom cordinates |
| 27 | # self.plate: List[List[bool]] = [] |
| 28 | # for x in range(PLATE_WIDTH): |
| 29 | # self.plate.append([False for y in range(PLATE_HEIGHT)]) |
| 30 | # |
| 31 | # print(f"plate: {self.plate}") |
| 32 | |
| 33 | self.desired_shape: Optional[Shape] |
| 34 | self.remaining_to_cut: Optional[Shape] |
| 35 | |
| 36 | |
| 37 | def power_on(self): |
| 38 | if not self.powered: |
| 39 | self.send("POWR") |
| 40 | self.powered = not self.powered |
| 41 | |
| 42 | def power_off(self): |
| 43 | if self.powered: |
| 44 | self.send("POWR") |
| 45 | self.powered = not self.powered |
| 46 | |
| 47 | def goto(self, target: Point): |
| 48 | print(f"LC: goto {target}") |
| 49 | while self.cutter_position != target: |
| 50 | if target.x > self.cutter_position.x: |
| 51 | self.send("MVXP") |
| 52 | self.cutter_position += Point(1, 0) |
| 53 | elif target.x < self.cutter_position.x: |
| 54 | self.send("MVXN") |
| 55 | self.cutter_position += Point(-1, 0) |
| 56 | elif target.y > self.cutter_position.y: |
| 57 | self.send("MVYP") |
| 58 | self.cutter_position += Point(0, 1) |
| 59 | elif target.y < self.cutter_position.y: |
| 60 | self.send("MVYN") |
| 61 | self.cutter_position += Point(0, -1) |
| 62 | |
| 63 | print(f"LC: goto {target}") |
| 64 | |
| 65 | def closest_uncut(self) -> Optional[Point]: |
| 66 | closest_point = None |
| 67 | closest_distance = 1000 |
| 68 | for point in self.remaining_to_cut.points: |
| 69 | distance = self.cutter_position.taxi_distance(point) |
| 70 | if distance < closest_distance: |
| 71 | closest_distance = distance |
| 72 | closest_point = point |
| 73 | return closest_point |
| 74 | |
| 75 | |