Answers.Body: <p>The problem was that the moves were tested in the context of the new board (after the move). But the correct way is that they should be tested with the board they were played on.</p>
  
  <p>See the discussion here.</p>
  
  <p><a href="https://github.com/niklasf/python-chess/issues/169" rel="nofollow noreferrer">https://github.com/niklasf/python-chess/issues/169</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-10T03:06:48.430Z
Answers.LastActivityDate: 2017-11-10T03:06:48.430Z
Answers.UserDisplayName: Bee
Answers.Body: <p>The code for those routines fairly liberally uses bitwise-and (&amp;) rather than boolean-and (and) for the logical expressions, so I assume integer values rather than booleans are being returned. I would guess that you would see something similar with is_castling if castling is possible; the False value is returned explicitly rather than being the result of an expression evaluation.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-26T04:37:05.890Z
Answers.Text: Do you think `bool(board.is_zeroing(node.move))` is the correct way to get the boolean value? I get True as output with this. Is that correct?
Answers.UserDisplayName: Bee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-26T06:26:42.680Z
Answers.Text: I am not a Python expert but if you want an explicit boolean True or False value then I believe that using bool() will achieve that.
Answers.UserDisplayName: kentdjb
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-07T05:48:29.713Z
Answers.Text: Only now I got time to start this over. Unfortunately bool() doesn't seem to work. It always returns true. :(
Answers.UserDisplayName: Bee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-10T03:07:25.103Z
Answers.Text: I could get it working. Added an answer.
Answers.UserDisplayName: Bee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-25T21:22:04.040Z
Answers.LastActivityDate: 2017-06-25T21:22:04.040Z
Answers.UserDisplayName: kentdjb
Answers.Body: <p>Making a few tests with this package in the shell, is-zeroing seems to work fine and returns a boolean :</p>
  <blockquote>
  <p>import chess</p>
  <p>b=chess.Board()</p>
  <p>b.push_san(&quot;Nf3&quot;)</p>
  </blockquote>
  <p>Move.from_uci('g1f3')</p>
  <blockquote>
  <p>b.push_san(&quot;Nc6&quot;)</p>
  </blockquote>
  <p>Move.from_uci('b8c6')</p>
  <blockquote>
  <p>b.push_san(&quot;Ne5&quot;)</p>
  </blockquote>
  <p>Move.from_uci('f3e5')</p>
  <blockquote>
  <p>m=chess.Move(42,36)</p>
  <p>flag = b.is_zeroing(m)</p>
  <p>print(flag)</p>
  </blockquote>
  <p>True</p>
  <blockquote>
  <p>m=chess.Move(49,41)</p>
  <p>flag=b.is_zeroing(m)</p>
  <p>print(flag)</p>
  </blockquote>
  <p>True</p>
  <blockquote>
  <p>m=chess.Move(42,32)</p>
  <p>flag=b.is_zeroing(m)</p>
  <p>print(flag)</p>
  </blockquote>
  <p>False</p>
  <blockquote>
  <p>print(&quot;Nc6-a5 is not a capture nor a pawn move : &quot; + str(flag))</p>
  </blockquote>
  <p>Nc6-a5 is not a capture nor a pawn move : False</p>
  <p>Did you try with str(board.is_zeroing(node.move)) ?
  To print both a string and a boolean in the same print, you need to turn the boolean intro a string.
  By the way what version of python do you use? From searching a bit, it seems python 3+ already stores strings in UTF8 and doesn't have the unicode() function. So no idea how the unicode() function works. But if your program gives weird results for the is_zeroing function and if it's the same using str(), then you might have to look into the parameters you are sending to the is_zeroing() method (pseudo_legal move? board not corrupted?).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-10T03:08:39.027Z
Answers.Text: I could get it working. Forgot to update here. Added an answer just now. Thank you.
Answers.UserDisplayName: Bee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-09T19:33:19.067Z
Answers.LastActivityDate: 2017-11-09T20:01:35.203Z
Answers.LastEditDate: 2020-06-17T09:59:59.497Z
Answers.UserDisplayName: Emphyrio
Body: <p>I'm using <a href="https://github.com/niklasf/python-chess" rel="nofollow noreferrer">python-chess</a> to analyze a game.</p>
  
  <p>I have my code like this, and I expect 3 boolean outputs.</p>
  
  <pre><code>print("is_castling: " + unicode(board.is_castling(node.move)));
  print("is_zeroing: " + unicode(board.is_zeroing(node.move)));
  print("is_capture: " + unicode(board.is_capture(node.move)));
  </code></pre>
  
  <p>But this is what I get.</p>
  
  <pre><code>is_castling: False
  is_zeroing: 4194304
  is_capture: 4194304
  </code></pre>
  
  <p>What am I missing here? </p>
  
Tags: <engines><programming><python>
Title: Python-chess is_zeroing and is_capture operation outputs
ThreadText: # Python-chess is_zeroing and is_capture operation outputs
  
  (Asked by: username_0 on 2017-06-25)
  
  I'm using [python-chess](https://github.com/niklasf/python-chess) to analyze a game.
  
  I have my code like this, and I expect 3 boolean outputs.
  
  ```
  print("is_castling: " + unicode(board.is_castling(node.move)));
  print("is_zeroing: " + unicode(board.is_zeroing(node.move)));
  print("is_capture: " + unicode(board.is_capture(node.move)));
  
  ```
  
  But this is what I get.
  
  ```
  is_castling: False
  is_zeroing: 4194304
  is_capture: 4194304
  
  ```
  
  What am I missing here?
  
  **Tags:** engines, programming, python
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2017-11-10. Score: 1 | Accepted answer
  
  The problem was that the moves were tested in the context of the new board (after the move). But the correct way is that they should be tested with the board they were played on.
  
  See the discussion here.
  
  <https://github.com/niklasf/python-chess/issues/169>
  
  
  ---
  
  ### Answer by username_1 on 2017-06-25. Score: 2
  
  The code for those routines fairly liberally uses bitwise-and (&) rather than boolean-and (and) for the logical expressions, so I assume integer values rather than booleans are being returned. I would guess that you would see something similar with is\_castling if castling is possible; the False value is returned explicitly rather than being the result of an expression evaluation.
  
  > **Comments:**
  > **username_0**: Do you think `bool(board.is_zeroing(node.move))` is the correct way to get the boolean value? I get True as output with this. Is that correct?  
  > **username_1**: I am not a Python expert but if you want an explicit boolean True or False value then I believe that using bool() will achieve that.  
  > **username_0**: Only now I got time to start this over. Unfortunately bool() doesn't seem to work. It always returns true. :(  
  > **username_0**: I could get it working. Added an answer.  
  
  ---
  
  ### Answer by username_2 on 2017-11-09. Score: 1
  
  Making a few tests with this package in the shell, is-zeroing seems to work fine and returns a boolean :
  
  > import chess
  >
  > b=chess.Board()
  >
  > b.push\_san("Nf3")
  
  Move.from\_uci('g1f3')
  
  > b.push\_san("Nc6")
  
  Move.from\_uci('b8c6')
  
  > b.push\_san("Ne5")
  
  Move.from\_uci('f3e5')
  
  > m=chess.Move(42,36)
  >
  > flag = b.is\_zeroing(m)
  >
  > print(flag)
  
  True
  
  > m=chess.Move(49,41)
  >
  > flag=b.is\_zeroing(m)
  >
  > print(flag)
  
  True
  
  > m=chess.Move(42,32)
  >
  > flag=b.is\_zeroing(m)
  >
  > print(flag)
  
  False
  
  > print("Nc6-a5 is not a capture nor a pawn move : " + str(flag))
  
  Nc6-a5 is not a capture nor a pawn move : False
  
  Did you try with str(board.is\_zeroing(node.move)) ?
  To print both a string and a boolean in the same print, you need to turn the boolean intro a string.
  By the way what version of python do you use? From searching a bit, it seems python 3+ already stores strings in UTF8 and doesn't have the unicode() function. So no idea how the unicode() function works. But if your program gives weird results for the is\_zeroing function and if it's the same using str(), then you might have to look into the parameters you are sending to the is\_zeroing() method (pseudo\_legal move? board not corrupted?).
  
  > **Comments:**
  > **username_0**: I could get it working. Forgot to update here. Added an answer just now. Thank you.  
  
  ---
  
  