<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 minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:
        """
        Rough work
        note: upward diagonals share x + y equality, downward diagonals share x - y equality

        white squares: 
            (odd, odd)
            (even, even)
        black squares:
            (odd, even)
            (even, odd)
        both rook and bishop take either 1 or 2 moves to reach any square on the board, but if queen and bishop are on opposite colours and bishop is blocking rook, it just takes 2 (move the rook)

        1. check if queen starts off in the path of rook or bishop
            - for rook: queen x or queen y = rook x or rook y -> return 1
            - for bishop: check colour of square each is on. if on same, then if abs(bishop x - queen x) == abs(bishop y - queen y) -> return 1. if not on same colour squares, then rook needs 2 moves to reach any square
            * caveat: if either bishop or rook in the way of other piece, +1 to result to move it out of the way. how to check: check if coords of other piece is in between coords of queen or rook
        
        fastest ways (fastest to slowest):
        1. board starts in check
        2. 1 move to check (no blockage)
        3. 1 move to prepare for check, 1 move to remove blockage and create check (happens when other piece is on the pathway approaching the queen from the side closest to checker)
        
        CASES:
        all on non-edge squares:
        1 move if in check + no blocks
        2 moves otherwise (whether check + block or bishop can't reach)

        rook only on edge square, queen/bishop not:
        rook still has two ways to approach any square in the middle, i.e. move x then y or move y then x. so it's the same as case 1

        bishop only on edge square, queen/bishop not:

        FINAL INTUITION
        being in corner limits approach methods to 2 directions for rook and 1 for bishop. 

        rook has 2 pathways to approach any tile on the board (change x, then y, or change y, then x)
        but bishop only has 1 way to approach any tile if it starts on an edge (when minimizing moves). for the rook, if the board starts in unimpeded check it's 1 move to win. if the rook is lined up to take and the bishop is blocking, it's 2 moves to move the bishop and then take. otherwise, if the rook doesn't start out in a position to take, then it takes 2 moves to do so and if the bishop is in the way of one of the pathways, the rook can just take the other. so the fastest method involves taking in 1, with either piece with either that is possible, or taking with rook by either moving the bishop out of the way or moving the rook twice.


        """
        rook = (a, b)
        bishop = (c, d)
        queen = (e, f)
        result = 0

        # rook can take in 1, vertically (axes are swapped)
        if rook[0] == queen[0]:
            result += 1
            # check if bishop blocking
            if bishop[0] == rook[0] and bishop[1] < max(queen[1], rook[1]) and bishop[1] > min(queen[1], rook[1]):
                result += 1
        # rook can take in 1, horizontally
        elif rook[1] == queen[1]:
            result += 1
            # check if bishop blocking
            if bishop[1] == rook[1] and bishop[0] < max(queen[0], rook[0]) and bishop[0] > min(queen[0], rook[0]):
                result += 1
        
        # bishop can take in 1, white squares
        elif bishop[0] % 2 == bishop[1] % 2 and queen[0] % 2 == queen[1] % 2 and abs(bishop[0] - queen[0]) == abs(bishop[1] - queen[1]):
            result += 1
            # check if rook blocking (must be on white square, in a straight line to the queen, between the bishop and the queen)
            if rook[0] % 2 == rook[1] % 2 and abs(rook[0] - queen[0]) == abs(rook[1] - queen[1]) and rook[0] > min(queen[0], bishop[0]) and rook[0] < max(queen[0], bishop[0]) and rook[1] > min(queen[1], bishop[1]) and rook[1] < max(queen[1], bishop[1]):
                result += 1
        
        # bishop can take in 1, black squares
        elif bishop[0] % 2 != bishop[1] % 2 and queen[0] % 2 != queen[1] % 2 and abs(bishop[0] - queen[0]) == abs(bishop[1] - queen[1]):
            result += 1
            # check if rook blocking (must be on black square, in a straight line to the queen, between the bishop and the queen)
            if rook[0] % 2 != rook[1] % 2 and abs(rook[0] - queen[0]) == abs(rook[1] - queen[1]) and rook[0] > min(queen[0], bishop[0]) and rook[0] < max(queen[0], bishop[0]) and rook[1] > min(queen[1], bishop[1]) and rook[1] < max(queen[1], bishop[1]):
                result += 1
        else:
            result = 2
    
        return result

        

25