niklasf on master
Link python-chess-engine-extens… (compare)
niklasf on master
Move required Python to install… (compare)
@SamQ26867433_twitter, ah, now I understand. If you looked at the documentation that I gave you, there is this thing: https://python-chess.readthedocs.io/en/latest/pgn.html#chess.pgn.GameNode.variations
There is this wonderful variations()
function that you should use to do what you want to do, but you need to have a chess.pgn.GameNode
object, of course.
@SamQ26867433_twitter, I also use a dictionary as my chess opening database. The way I have it implemented is this: a key
of the dictionary is a FEN string
, and the value
of that key is a tuple
of an ECO code
of the chess opening and a name
of the chess opening.
Like this:
{
"rn1qkbnr/ppp2ppp/8/3p4/5p2/6PB/PPPPP2P/RNBQK2R w KQkq -": ("A00", "Amar Gambit"),
"rn1qkbnr/ppp2ppp/8/3p4/8/6PB/PPPPP3/RNBQ1RK1 b kq -": ("A00", "Amar Opening: Gent Gambit",
etc.
}
@AphilipA, it all depends on the PGN file that you're passing to read_game()
. If any game in the PGN file is not properly formatted, then you get errors such as the one you descibed. Please check that all the games in your PGN file are properly formatted according to the PGN specification.
As an example, a game in a PGN file should look like this:
[Event "F/S Return Match"]
[Site "Belgrade, Serbia JUG"]
[Date "1992.11.04"]
[Round "29"]
[White "Fischer, Robert J."]
[Black "Spassky, Boris V."]
[Result "1/2-1/2"]
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 {This opening is called the Ruy Lopez.}
4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7
11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5
Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6
23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5
hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5
35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6
Nf2 42. g4 Bd3 43. Re6 1/2-1/2
The PyPI package name python-chess
was renamed to chess
, so if python-chess is installed with pip install python-chess
, you get version 1.999
which is not maintained anymore and never will be. To get the latest and the actively maintained version of python-chess, it needs to be installed with pip install chess
. This actively maintained version of python-chess is currently at 1.7.0
. And to check which version of python-chess you are using, do this:
import chess
print(chess.__version__)
or
import chess
chess.__version__
Please respond with the version number you get on Google Colab.
%pip install chess
1.7.0
of python-chess. If I do import chess
, Google Colab always imports version 0.23.11
. I don't know why. It's very frustrating. Anyway, I'm glad your code works on the newest version of python-chess outside Google Colab. Fuck Google Colab, it's stupid.
@niklasf python-chess is really great! When first using chess.polyglot, all went well where I got:
import chess
import chess.polyglot
board = chess.Board()
with chess.polyglot.open_reader(polyglot_books/Cerebellum3Merge.bin') as reader:
for entry in reader.find_all(board):
print(entry.move, entry.weight, entry.learn)
e2e4 255 0
d2d4 127 0
So how do I get the rest of possible openings in book? (e.g. - 1.c4, 1.Nf3....etc)
@niklasf, don't you think some aliases are missing in chess.variant
for the 3-check chess variant? Currently, python-chess has these aliases for it: aliases = ["Three-check", "Three check", "Threecheck", "Three check chess", "3-check", "3 check", "3check"]
The list should be:aliases = ["Three-check", "Three check", "Threecheck", "Three-check chess", "Three check chess", "Threecheck chess", "3-check", "3 check", "3check", "3-check chess", "3 check chess", "3check chess"]
@niklasf, I have found a bug in python-chess. The bug involves chess.Board().status()
. Here's my proof of concept:
>>> import chess
>>> chess.Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1").status()
<Status.VALID: 0>
As you can see, I passed the starting FEN to chess.Board()
, but I set Black (b
) as being the first to move. And since this is clearly not valid, please add a check to the status()
method to detect whether it is actually White that is on turn to move in the starting position.
Fixing this bug also involves adding a new Status
enum.
w
is a b
(color part of the FEN) in the starting position, indicating that Black starts a game of chess. And since White always moves first, not Black, so a FEN like this should be reported as not valid by the status()
method.
1
: https://github.com/niklasf/python-chess/blob/eef8a29907e91662a24a4f0a79416f14c8a6d24c/chess/svg.py#L51