<p>There is a <strong>1-indexed</strong> <code>8 x 8</code> chessboard containing <code>3</code> pieces.</p>

<p>You are given <code>6</code> integers <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, <code>e</code>, and <code>f</code> where:</p>

<ul>
	<li><code>(a, b)</code> denotes the position of the white rook.</li>
	<li><code>(c, d)</code> denotes the position of the white bishop.</li>
	<li><code>(e, f)</code> denotes the position of the black queen.</li>
</ul>

<p>Given that you can only move the white pieces, return <em>the <strong>minimum</strong> number of moves required to capture the black queen</em>.</p>

<p><strong>Note</strong> that:</p>

<ul>
	<li>Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.</li>
	<li>Bishops can move any number of squares diagonally, but cannot jump over other pieces.</li>
	<li>A rook or a bishop can capture the queen if it is located in a square that they can move to.</li>
	<li>The queen does not move.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/ex1.png" style="width: 600px; height: 600px; padding: 10px; background: #fff; border-radius: .5rem;" />
<pre>
<strong>Input:</strong> a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).
It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/ex2.png" style="width: 600px; height: 600px;padding: 10px; background: #fff; border-radius: .5rem;" />
<pre>
<strong>Input:</strong> a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can capture the black queen in a single move by doing one of the following: 
- Move the white rook to (5, 2).
- Move the white bishop to (5, 2).
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= a, b, c, d, e, f &lt;= 8</code></li>
	<li>No two pieces are on the same square.</li>
</ul>

class Solution:
    def isPathClear(self, x1, y1, x2, y2, a, b, c, d):
        # Check if path between (x1, y1) and (x2, y2) is clear of the other piece
        if x1 == x2:  # Vertical path
            for y in range(min(y1, y2) + 1, max(y1, y2)):
                if (x1 == a and y == b) or (x1 == c and y == d):
                    return False
        elif y1 == y2:  # Horizontal path
            for x in range(min(x1, x2) + 1, max(x1, x2)):
                if (x == a and y1 == b) or (x == c and y1 == d):
                    return False
        else:  # Diagonal path for bishop
            x_step = 1 if x2 > x1 else -1
            y_step = 1 if y2 > y1 else -1
            x, y = x1 + x_step, y1 + y_step
            while x != x2 and y != y2:
                if (x == a and y == b) or (x == c and y == d):
                    return False
                x, y = x + x_step, y + y_step
        
        return True

    def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:
        # Check if the queen can be captured in one move by the rook or the bishop
        canRookCapture = (a == e or b == f) and self.isPathClear(a, b, e, f, c, d, 0, 0)
        canBishopCapture = (abs(c - e) == abs(d - f)) and self.isPathClear(c, d, e, f, a, b, 0, 0)
        
        if canRookCapture or canBishopCapture:
            return 1
        
        # If not in one move, simulate the attack in two moves
        # Try moving the rook in line with the queen
        if self.isPathClear(a, b, e, f, c, d, 0, 0):
            if a != e:
                rookToE = (e, b)
                rookToCapture = (e, f)
                if self.isPathClear(rookToE[0], rookToE[1], e, f, c, d, a, b):
                    return 2
            if b != f:
                rookToF = (a, f)
                rookToCapture = (e, f)
                if self.isPathClear(rookToF[0], rookToF[1], e, f, c, d, a, b):
                    return 2
        
        # Try moving the bishop in line with the queen
        x_diff, y_diff = e - c, f - d
        if abs(x_diff) == abs(y_diff):
            if self.isPathClear(c, d, e, f, a, b, 0, 0):
                return 2

        return 2  # At least two steps required if neither can capture in one move

# Example usage
solver = Solution()
print(solver.minMovesToCaptureTheQueen(1, 1, 8, 8, 2, 3))  # Output: 2
print(solver.minMovesToCaptureTheQueen(5, 3, 3, 4, 5, 2))  # Output: 1
34