Answers.Body: <p>This comes from python-chess:</p>
  
  <pre><code>def is_insufficient_material(self):
      """Checks for a draw due to insufficient mating material."""
      # Enough material to mate.
      if self.pawns or self.rooks or self.queens:
          return False
  
      # A single knight or a single bishop.
      if popcount(self.occupied) &lt;= 3:
          return True
  
      # More than a single knight.
      if self.knights:
          return False
  
      # All bishops on the same color.
      if self.bishops &amp; BB_DARK_SQUARES == 0:
          return True
      elif self.bishops &amp; BB_LIGHT_SQUARES == 0:
          return True
      else:
          return False
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T15:40:54.277Z
Answers.Text: `if self.knights or self.rooks or self.queens or self.kings: return False` - It is not at all obvious what this line is doing.  I mean, I would ordinarily assume that it's checking whether you have one of the listed pieces - but then it would return false if you had a king, which makes no sense at all.
Answers.UserDisplayName: D M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T16:20:05.137Z
Answers.Text: @DM as far as I understand, these are variables that show possible moves for the specific piece. The whole statement means, "if rooks or queens or knights or kings are available and can move".
Answers.UserDisplayName: lenik
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T19:58:10.433Z
Answers.Text: That doesn't seem to make sense either; it returns an immediate `False` if the king has a legal move?
Answers.UserDisplayName: D M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-01T11:16:19.883Z
Answers.Text: Not sure where you got that source file, but that `or self.kings` isn't there anymore in the [current version of python-chess](https://github.com/niklasf/python-chess/blob/master/chess/__init__.py#L1698). And those variables are bitmasks showing where each piece is, so it just means "if there's any king on the board".
Answers.UserDisplayName: Federico Poloni
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-01T11:42:44.923Z
Answers.Text: @FedericoPoloni yeah, I think I took the wrong chess variant, not the original chess. thank you for the correction, replaced the code with the current version!
Answers.UserDisplayName: lenik
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-03T16:06:58.543Z
Answers.Text: Thank you, can you please explain what this code does? I have no knowledge of python at all.
Answers.UserDisplayName: Wais Kamal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-04T00:41:16.627Z
Answers.Text: @WaisKamal the code checks for the basic things we need to mate. 1) if there are pawns, rooks or queens -- it might be still possible to win. 2) if there's only one light piece left -- we don't have enough material 3) if there's a knight +   something else, it's still possible to win 4) if the bishops are the not the same color, we can win.
Answers.UserDisplayName: lenik
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-30T14:04:19.020Z
Answers.LastActivityDate: 2018-07-01T11:41:23.403Z
Answers.LastEditDate: 2018-07-01T11:41:23.403Z
Answers.UserDisplayName: lenik
Answers.Body: <p>As far as I know, every chess website simply looks at the opponents material to determine if they have mating material or not. It doesn't matter even if mate is possible.</p>
  
  <p>The ruleset you are referring to are the FIDE rules, and for simplicity chess websites do not use these rules because the percentage of positions where self-mate is possible is too low.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-01T01:39:22.103Z
Answers.LastActivityDate: 2018-07-01T01:39:22.103Z
Answers.UserDisplayName: Matthew Liu
Body: <p>So I played many games online where I am winning but then lose on time. Sometimes the game is drawn (when there is no sequence of legal moves that would produce checkmate) and sometimes I lose (when there is such a sequence). The decision the website takes happens instantly. I am wondering, how do they determine whether the game is a draw or not? If they use brute force, then the decision would take longer to arrive at.</p>
  
Tags: <online-chess>
Title: How do I determine whether a game is a draw or not in case of timeout?
ThreadText: # How do I determine whether a game is a draw or not in case of timeout?
  
  (Asked by: username_0 on 2018-06-30)
  
  So I played many games online where I am winning but then lose on time. Sometimes the game is drawn (when there is no sequence of legal moves that would produce checkmate) and sometimes I lose (when there is such a sequence). The decision the website takes happens instantly. I am wondering, how do they determine whether the game is a draw or not? If they use brute force, then the decision would take longer to arrive at.
  
  **Tags:** online-chess
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_4 on 2018-07-01. Score: 5 | Accepted answer
  
  As far as I know, every chess website simply looks at the opponents material to determine if they have mating material or not. It doesn't matter even if mate is possible.
  
  The ruleset you are referring to are the FIDE rules, and for simplicity chess websites do not use these rules because the percentage of positions where self-mate is possible is too low.
  
  
  ---
  
  ### Answer by username_1 on 2018-06-30. Score: 3
  
  This comes from python-chess:
  
  ```
  def is_insufficient_material(self):
      """Checks for a draw due to insufficient mating material."""
      # Enough material to mate.
      if self.pawns or self.rooks or self.queens:
          return False
  
      # A single knight or a single bishop.
      if popcount(self.occupied) <= 3:
          return True
  
      # More than a single knight.
      if self.knights:
          return False
  
      # All bishops on the same color.
      if self.bishops & BB_DARK_SQUARES == 0:
          return True
      elif self.bishops & BB_LIGHT_SQUARES == 0:
          return True
      else:
          return False
  
  ```
  
  > **Comments:**
  > **username_2**: `if self.knights or self.rooks or self.queens or self.kings: return False` - It is not at all obvious what this line is doing.  I mean, I would ordinarily assume that it's checking whether you have one of the listed pieces - but then it would return false if you had a king, which makes no sense at all.  
  > **username_1**: @DM as far as I understand, these are variables that show possible moves for the specific piece. The whole statement means, "if rooks or queens or knights or kings are available and can move".  
  > **username_2**: That doesn't seem to make sense either; it returns an immediate `False` if the king has a legal move?  
  > **username_3**: Not sure where you got that source file, but that `or self.kings` isn't there anymore in the [current version of python-chess](https://github.com/niklasf/python-chess/blob/master/chess/__init__.py#L1698). And those variables are bitmasks showing where each piece is, so it just means "if there's any king on the board".  
  > **username_1**: @username_3 yeah, I think I took the wrong chess variant, not the original chess. thank you for the correction, replaced the code with the current version!  
  > **username_0**: Thank you, can you please explain what this code does? I have no knowledge of python at all.  
  > **username_1**: @username_0 the code checks for the basic things we need to mate. 1) if there are pawns, rooks or queens -- it might be still possible to win. 2) if there's only one light piece left -- we don't have enough material 3) if there's a knight +   something else, it's still possible to win 4) if the bishops are the not the same color, we can win.  
  
  ---
  
  