1

I'm using 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?

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.

| improve this answer | |
  • 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? – Bee Jun 26 '17 at 4:37
  • 3
    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. – kentdjb Jun 26 '17 at 6:26
  • Only now I got time to start this over. Unfortunately bool() doesn't seem to work. It always returns true. :( – Bee Oct 7 '17 at 5:48
  • I could get it working. Added an answer. – Bee Nov 10 '17 at 3:07
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?).

| improve this answer | |
  • I could get it working. Forgot to update here. Added an answer just now. Thank you. – Bee Nov 10 '17 at 3:08
1

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.