Answers.Body: <p>Since several lower bounds have already been posted, I would like to elaborate a bit more on the possible upper bounds, since the estimate in the question is a bit oversimplified in my opinion (although the conclusion is still correct).</p>
  
  <p>First, let us have a look at naive upper bounds, not considering interference between piece types, for each possible checking piece. The number of moves per piece type in the respective scenario (with the optimal number of pieces given in brackets) are given below:</p>
  
  <pre><code>    R       B       N       P   
  ---------------------------------
  K   7 (1)   7 (1)   8 (1)   8 (1)
  Q   3 (7)   3 (8)   1 (1)   1 (3)
  R   1 (2)   2 (2)   1 (2)   1 (2)
  B   2 (2)   1 (1)   1 (1)   1 (1)
  N   2 (2)   2 (2)   1 (8)   1 (8)
  P   4 (2)   4 (1)   4 (2)   1 (0)
  ---------------------------------
      46      44      28      22  
  </code></pre>
  
  <p>It is quite obvious that checks of non-sliding piece (N/P) do not need to be considered, since they can not be blocked. The case of a bishop is only slightly worse than a rook, but it is relatively obvious that it can not be better (because of opposite colored bishops, and pawns can not be effectively used against bishops), so we can focus on the scenario of a rook check.</p>
  
  <p>The naive/conservative upper bound is 46 as given above. However, there are several interferences that make it impossible to achieve this:</p>
  
  <ul>
  <li>The slider blocking moves only work if the king is not next to the piece giving check, therefore, the king effectively can only have 6 moves, i.e., one less than the maximum.</li>
  <li>The 8x8 board is too small to fit all possible interposing pieces into their optimal positions:
  
  <ul>
  <li>When the king <strong>is not</strong> at the edge of the board, we only have 8 squares available for the 2 pawns, 7 queens, and 2 bishops. Therefore, 3 of these pieces need to be put on suboptimal squares or need to be replaced by a different piece, which will lose at least 3x1 move.</li>
  <li>When the king <strong>is</strong>  at the edge of the board, we still have only 10 squares for the 11 P/Q/B, so we lose one move. Furthermore, the king of course has two moves less compared to when it is not at the edge of the board.</li>
  </ul></li>
  </ul>
  
  <p>For those reasons, the theoretical maximum needs to be lowered by 4, arriving at 42. Since we already know the lower bound 42 from Remellion's answer, we can conclude that 42 is both the lower and the upper bound, so it has to be the optimum.</p>
  
  <p>The number of 42 can be achieved with different scenarios, just using different ways to concede the 4 moves that we have to lose compared to the naive upper bound, but all of them are similar to the position from Remellion's answer:</p>
  
  <ul>
  <li>King at the edge, one queen replaced by a knight</li>
  </ul>
  
  <pre><code>3r3k/2P1P3/1NQ1QN2/2Q1QN2/2Q1B3/2Q1B3/1R3R2/3K4 w - - 0 1
  </code></pre>
  
  <ul>
  <li>King at the edge, one bishop at a suboptimal square</li>
  </ul>
  
  <pre><code>3rB2k/2P1P3/1NQ1QN2/2Q1Q3/2Q1Q3/2Q1B3/1R3R2/3K4 w - - 0 1
  </code></pre>
  
  <ul>
  <li>Three queens replaced by knights.</li>
  </ul>
  
  <pre><code>3r3k/2P1P3/1NQ1QN2/1NQ1BN2/2Q1BN2/1R3R2/3K4/8 w - - 0 1
  </code></pre>
  
  <ul>
  <li>etc.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-22T13:44:37.037Z
Answers.LastActivityDate: 2019-06-22T13:44:37.037Z
Answers.UserDisplayName: Fabian Fichter
Answers.Body: <p>Building on @Remellion's matrix for 42 in a legal position, here is <strong>68</strong> in an illegal position.</p>
  <pre><code>[Title &quot;mec chess.stackexchange.com 9/22/2019, 68 Check Blocks&quot;]
  [FEN &quot;1NQrQN2/1NP1PN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1N1K1N2 w - - 0 1&quot;]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-18T12:07:32.700Z
Answers.LastActivityDate: 2021-06-10T00:22:46.827Z
Answers.LastEditDate: 2021-06-10T00:22:46.827Z
Answers.UserDisplayName: Rewan Demontay
Answers.Body: <p>Needed this for a test case. (engine check extension heuristics)</p>
  <p>42, like already proven in other answers, but with no underpromoted pieces and <em>no block resulting in a stalemate or lost position</em></p>
  <pre><code>[Title &quot;chess.stackexchange.com 2022-07-19, 42 Check Blocks&quot;]
  [FEN &quot;R3q2R/2NP1PN1/3Q1Q2/3Q1Q2/pn1Q1Q2/1p1B1Q2/k7/4K1B1 w - - 0 1&quot;]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-19T17:38:02.130Z
Answers.Text: nb: White has two bishops on dark squares, with all pawns still on the board as either pawns or queens, so the position is not attainable. Move the bottom bishop over one square toward the king to fix this.
Answers.UserDisplayName: L. Scott Johnson
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-19T14:18:27.027Z
Answers.LastActivityDate: 2022-07-19T18:27:48.090Z
Answers.LastEditDate: 2022-07-19T18:27:48.090Z
Answers.UserDisplayName: SE - stop firing the good guys
Answers.Body: <p>Of course we can do better. We can always do better. 42 legal responses with a little trick.</p>
  
  <pre><code>[FEN "3rB2k/2P1P3/1NQ1QN2/2Q1QN2/2Q1Q3/1R3R2/3K1B2/8 w - - 0 1"]
  </code></pre>
  
  <p>My previous attempt, 40 legal responses:</p>
  
  <pre><code>[FEN "8/4N2R/3QQQQ1/1K5r/3QQQQ1/BB1NN2R/8/1k6 w - - 0 1"]
  </code></pre>
  
  <p>And 39 legal responses with a bishop check (and the position is legal, black's last move was ...h2-h1=B+):</p>
  
  <pre><code>[FEN "7k/1K6/4RN2/5QN1/B1R3QN/3Q3Q/3NQ3/4NQ1b w - - 0 1"]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-03T17:05:54.723Z
Answers.Text: Just a minor comment from a purely aesthetical point of view. In the last position, Black's last move could also have been 0...gxh1=B+. If you place a black pawn (it can't be white) on h2 then that move is unique.
Answers.UserDisplayName: kamekura
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-04T02:13:47.813Z
Answers.Text: No, it can't be gxh1B. White's pawns all promoted and the only missing piece is a dark squared bishop.
Answers.UserDisplayName: Remellion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-04T06:22:53.117Z
Answers.Text: I stand corrected.
Answers.UserDisplayName: kamekura
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-18T13:18:35.940Z
Answers.LastActivityDate: 2019-06-22T07:11:19.640Z
Answers.LastEditDate: 2019-06-22T07:11:19.640Z
Answers.UserDisplayName: Remellion
Body: <p>What is the maximum number of legal moves in a legal position, <strong>given that the player is in check?</strong></p>
  
  <p>It's easy to see that 43 is an upper bound. Let's suppose the white K is in check along a diagonal by a Q or B (other cases are similar or easier). Then White has at most 7 legal K moves; a white Q has at most 3 moves (interposition or capture); a white B of the right color has at most one move; and a white R, N, or P has at most 2 moves. Even if White has lost no pieces and has promoted all his pawns to queens, he has no more than 1*7 + 9*3 + 1*1 + 4*2 = 43 legal moves.</p>
  
  <p>In fact it's easy to see that 43 cannot be attained. If White has 7 legal K moves, then one of them must be to capture the checking piece. But in that case no interposition is possible, the only legal non-K moves are captures, so White has at most 21 moves total. </p>
  
Tags: <problems><check><records>
Title: Maximum number of ways to get out of check
ThreadText: # Maximum number of ways to get out of check
  
  (Asked by: username_0 on 2019-06-18)
  
  What is the maximum number of legal moves in a legal position, **given that the player is in check?**
  
  It's easy to see that 43 is an upper bound. Let's suppose the white K is in check along a diagonal by a Q or B (other cases are similar or easier). Then White has at most 7 legal K moves; a white Q has at most 3 moves (interposition or capture); a white B of the right color has at most one move; and a white R, N, or P has at most 2 moves. Even if White has lost no pieces and has promoted all his pawns to queens, he has no more than 1\*7 + 9\*3 + 1\*1 + 4\*2 = 43 legal moves.
  
  In fact it's easy to see that 43 cannot be attained. If White has 7 legal K moves, then one of them must be to capture the checking piece. But in that case no interposition is possible, the only legal non-K moves are captures, so White has at most 21 moves total.
  
  **Tags:** problems, check, records
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_5 on 2019-06-18. Score: 9 | Accepted answer
  
  Of course we can do better. We can always do better. 42 legal responses with a little trick.
  
  ```
  [FEN "3rB2k/2P1P3/1NQ1QN2/2Q1QN2/2Q1Q3/1R3R2/3K1B2/8 w - - 0 1"]
  
  ```
  
  My previous attempt, 40 legal responses:
  
  ```
  [FEN "8/4N2R/3QQQQ1/1K5r/3QQQQ1/BB1NN2R/8/1k6 w - - 0 1"]
  
  ```
  
  And 39 legal responses with a bishop check (and the position is legal, black's last move was ...h2-h1=B+):
  
  ```
  [FEN "7k/1K6/4RN2/5QN1/B1R3QN/3Q3Q/3NQ3/4NQ1b w - - 0 1"]
  
  ```
  
  > **Comments:**
  > **username_6**: Just a minor comment from a purely aesthetical point of view. In the last position, Black's last move could also have been 0...gxh1=B+. If you place a black pawn (it can't be white) on h2 then that move is unique.  
  > **username_5**: No, it can't be gxh1B. White's pawns all promoted and the only missing piece is a dark squared bishop.  
  > **username_6**: I stand corrected.  
  
  ---
  
  ### Answer by username_1 on 2019-06-22. Score: 4
  
  Since several lower bounds have already been posted, I would like to elaborate a bit more on the possible upper bounds, since the estimate in the question is a bit oversimplified in my opinion (although the conclusion is still correct).
  
  First, let us have a look at naive upper bounds, not considering interference between piece types, for each possible checking piece. The number of moves per piece type in the respective scenario (with the optimal number of pieces given in brackets) are given below:
  
  ```
      R       B       N       P   
  ---------------------------------
  K   7 (1)   7 (1)   8 (1)   8 (1)
  Q   3 (7)   3 (8)   1 (1)   1 (3)
  R   1 (2)   2 (2)   1 (2)   1 (2)
  B   2 (2)   1 (1)   1 (1)   1 (1)
  N   2 (2)   2 (2)   1 (8)   1 (8)
  P   4 (2)   4 (1)   4 (2)   1 (0)
  ---------------------------------
      46      44      28      22  
  
  ```
  
  It is quite obvious that checks of non-sliding piece (N/P) do not need to be considered, since they can not be blocked. The case of a bishop is only slightly worse than a rook, but it is relatively obvious that it can not be better (because of opposite colored bishops, and pawns can not be effectively used against bishops), so we can focus on the scenario of a rook check.
  
  The naive/conservative upper bound is 46 as given above. However, there are several interferences that make it impossible to achieve this:
  
  * The slider blocking moves only work if the king is not next to the piece giving check, therefore, the king effectively can only have 6 moves, i.e., one less than the maximum.
  * The 8x8 board is too small to fit all possible interposing pieces into their optimal positions:
    + When the king **is not** at the edge of the board, we only have 8 squares available for the 2 pawns, 7 queens, and 2 bishops. Therefore, 3 of these pieces need to be put on suboptimal squares or need to be replaced by a different piece, which will lose at least 3x1 move.
    + When the king **is** at the edge of the board, we still have only 10 squares for the 11 P/Q/B, so we lose one move. Furthermore, the king of course has two moves less compared to when it is not at the edge of the board.
  
  For those reasons, the theoretical maximum needs to be lowered by 4, arriving at 42. Since we already know the lower bound 42 from username_5's answer, we can conclude that 42 is both the lower and the upper bound, so it has to be the optimum.
  
  The number of 42 can be achieved with different scenarios, just using different ways to concede the 4 moves that we have to lose compared to the naive upper bound, but all of them are similar to the position from username_5's answer:
  
  * King at the edge, one queen replaced by a knight
  
  ```
  3r3k/2P1P3/1NQ1QN2/2Q1QN2/2Q1B3/2Q1B3/1R3R2/3K4 w - - 0 1
  
  ```
  
  * King at the edge, one bishop at a suboptimal square
  
  ```
  3rB2k/2P1P3/1NQ1QN2/2Q1Q3/2Q1Q3/2Q1B3/1R3R2/3K4 w - - 0 1
  
  ```
  
  * Three queens replaced by knights.
  
  ```
  3r3k/2P1P3/1NQ1QN2/1NQ1BN2/2Q1BN2/1R3R2/3K4/8 w - - 0 1
  
  ```
  
  * etc.
  
  
  ---
  
  ### Answer by username_2 on 2019-06-18. Score: 3
  
  Building on @username_5's matrix for 42 in a legal position, here is **68** in an illegal position.
  
  ```
  [Title "mec chess.stackexchange.com 9/22/2019, 68 Check Blocks"]
  [FEN "1NQrQN2/1NP1PN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1N1K1N2 w - - 0 1"]
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2022-07-19. Score: 2
  
  Needed this for a test case. (engine check extension heuristics)
  
  42, like already proven in other answers, but with no underpromoted pieces and *no block resulting in a stalemate or lost position*
  
  ```
  [Title "chess.stackexchange.com 2022-07-19, 42 Check Blocks"]
  [FEN "R3q2R/2NP1PN1/3Q1Q2/3Q1Q2/pn1Q1Q2/1p1B1Q2/k7/4K1B1 w - - 0 1"]
  
  ```
  
  > **Comments:**
  > **username_4**: nb: White has two bishops on dark squares, with all pawns still on the board as either pawns or queens, so the position is not attainable. Move the bottom bishop over one square toward the king to fix this.  
  
  ---
  
  