# Problem Description
This is a ball trajectory problem where we need to determine if a ball starting from a given position with an initial direction can reach a target position after bouncing off the boundaries of a 10x10 grid. The ball follows the law of reflection (angle of incidence equals angle of reflection) when it hits the boundaries.

# Visual Facts
1. The coordinate system is a 10x10 grid (from 0 to 10 on both axes)
2. The grid has clear boundaries at x=0, x=10, y=0, and y=10
3. Start point (green circle) is located around (8, 7)
4. Target point (orange circle) is located around (6, 9)
5. The path is shown with blue dotted lines
6. Blue arrows indicate the direction of movement
7. The path shows multiple bounces off the boundaries
8. The path eventually reaches the target point
9. The path follows straight lines between bounces

# Visual Patterns
1. Bouncing Pattern:
   - When the ball hits a boundary, it reflects with equal angles
   - The angle of reflection equals the angle of incidence
   - The ball maintains constant direction between bounces

2. Movement Constraints:
   - Movement is continuous along straight lines（x += dx，y += dy）
   - Direction changes only occur at boundaries
   - The path never passes through the same point with the same direction twice (suggests a termination condition)

3. Geometric Properties:
   - The trajectory forms a series of connected line segments
   - Each bounce preserves the angle but reverses one component of the direction vector
   - For example, if the original direction (dx, dy) is (1, 1), and the x boundary is encountered (x == 0 or x == 10), then dx = -dx, and the new direction becomes (-1, 1).
   - For example, if the original direction (dx, dy) is (1, 1), and the y boundary is encountered (y == 0 or y == 10), then dy = -dy, and the new direction becomes (1, -1).
   - The path remains within the 10x10 grid boundaries at all times

4. Solution Pattern:
   - To reach the target, the ball must follow a valid sequence of bounces
   - A valid solution exists if there's a path connecting start to target following reflection rules


# Solution
def solution(start: tuple[int, int], target: tuple[int, int], direction: tuple[int, int]) -> bool:
    """
    Determines whether the ball can reach the target.

    Parameters:
    - start: Tuple[int, int], represents the initial position of the ball (x, y).
    - target: Tuple[int, int], represents the position of the target.
    - direction: Tuple[int, int], represents the initial direction of the ball (dx, dy). dx and dy are integers that can be either -1, 0, or 1.

    Returns:
    - bool: True if the ball can reach the target, False otherwise.
    """
    x, y = start
    tx, ty = target
    dx, dy = direction
    while True:
        x += dx
        y += dy
        if (x, y) == (tx, ty):
            return True
        if x == 0 or x == 10:
            dx = -dx
        if y == 0 or y == 10:
            dy = -dy
        if (x, y) == start and (dx, dy) == direction:
            return False


# Test Script
def test():
    test_cases = [
        [(8, 7), (6, 9), (1, -1), True],
        [(8, 7), (6, 10), (1, -1), False],
        [(8, 7), (9, 6), (1, -1), True],
        
        [(0, 0), (1, 1), (1, 0), False],
        [(0, 0), (2, 2), (1, 1), True],
        [(0, 0), (0, 1), (0, 1), True],
        
        [(2, 1), (6, 10), (-1, -1), False],
        [(2, 1), (1, 0), (-1, -1), True],
        
        [(10, 1), (1, 0), (-1, 1), False],
        [(10, 1), (9, 2), (-1, 1), True],
    ]
    
    for test_case in test_cases:
        start, target, direction, expected_output = test_case
        
        try:
            output = solution(start, target, direction)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`start`: {start}\n"
                f"`target`: {target}\n"
                f"`direction`: {direction}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`start`: {start}\n"
                f"`target`: {target}\n" 
                f"`direction`: {direction}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()