Example #1
0
def move_by_waypoint(directions):
    way_point = PathPoint(10, 1, 0)
    ship = Point(0, 0)
    for direction in directions:
        code = direction[0]
        argument = int(direction[1:])
        if code == "F":
            ship_x = ship.x_coordinate + argument * way_point.get_point(
            ).x_coordinate
            ship_y = ship.y_coordinate + argument * way_point.get_point(
            ).y_coordinate
            ship = Point(ship_x, ship_y)
        elif code in ("C", "A"):
            if code == "C":
                turn = TurnDirection.RIGHT
            else:
                turn = TurnDirection.LEFT
            new_way_point = rotate(Point(0, 0), way_point.get_point(), turn,
                                   argument)
            way_point = PathPoint(new_way_point.x_coordinate,
                                  new_way_point.y_coordinate, 0)
        else:
            way_path = make_path(way_point, direction)
            way_point = way_path[-1]

    return ship
Example #2
0
 def test_RIGHT(self):
     origin = PathPoint(0, 0, 0)
     result = [
         origin,
         PathPoint(1, 0, 1),
         PathPoint(2, 0, 2),
         PathPoint(3, 0, 3),
         PathPoint(4, 0, 4),
         PathPoint(5, 0, 5)
     ]
     self.assertListEqual(make_path(origin, "R5"), result)
Example #3
0
 def test_Down(self):
     origin = PathPoint(-2, 3, 0)
     result = [
         origin,
         PathPoint(-2, 2, 1),
         PathPoint(-2, 1, 2),
         PathPoint(-2, 0, 3),
         PathPoint(-2, -1, 4),
         PathPoint(-2, -2, 5)
     ]
     self.assertListEqual(make_path(origin, "D5"), result)
Example #4
0
 def test_LEFT(self):
     origin = PathPoint(2, 0, 0)
     result = [
         origin,
         PathPoint(1, 0, 1),
         PathPoint(0, 0, 2),
         PathPoint(-1, 0, 3),
         PathPoint(-2, 0, 4),
         PathPoint(-3, 0, 5)
     ]
     self.assertListEqual(make_path(origin, "L5"), result)
Example #5
0
 def test_EAST(self):
     origin = PathPoint(0, 0, 0)
     result = [
         origin,
         PathPoint(1, 0, 1),
         PathPoint(2, 0, 2),
         PathPoint(3, 0, 3),
         PathPoint(4, 0, 4),
         PathPoint(5, 0, 5)
     ]
     self.assertListEqual(make_path(origin, "F5", CardinalPoint.EAST),
                          result)
Example #6
0
 def test_SOUTH(self):
     origin = PathPoint(-2, 3, 0)
     result = [
         origin,
         PathPoint(-2, 2, 1),
         PathPoint(-2, 1, 2),
         PathPoint(-2, 0, 3),
         PathPoint(-2, -1, 4),
         PathPoint(-2, -2, 5)
     ]
     self.assertListEqual(make_path(origin, "F5", CardinalPoint.SOUTH),
                          result)
Example #7
0
 def test_EmptyPath(self):
     origin = PathPoint(0, 0, 0)
     self.assertListEqual(make_path(origin, ""), [origin])