Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python-chess question
#1
I am a fairly new Python user, and I was trying to use the python-chess module (documentation here: https://readthedocs.org/projects/python-...df/stable/) to essentially do the following.

1. I want to load from lichess a series of games from a user. Essentially I got this part working using the python-lichess module. My code gets the last 7 games from this lichess user thibault (used as just an example). Here is the code so far:
import lichess.api
from lichess.format import SINGLE_PGN
import chess.pgn
import io

pgn = lichess.api.user_games('thibault', max=7, format=SINGLE_PGN)
print(pgn)

pgn2=io.StringIO(pgn)
game=chess.pgn.read_game(pgn2)
2. Next, I want to have the ability to go to say the 5th game in this series of games and to then move to say the 9th move in this game and to display the configuration of the board into a 2D numpy array. I know that the python-lichess module allows you to print to the screen the board's configuration such as in the code below:
import lichess.api
from lichess.format import PYCHESS
game = lichess.api.game('Qa7FJNk2', format=PYCHESS)
print(game.end().board())
. . k . R b r .
. p p r . N p .
p . . . . . . p
. . . . . . . .
. . . p . . . .
P . . P . . . P
. P P . . P P .
. . K R . . . .
However, I want to have the output be a 2D numpy array of strings, and I want to be able to load those values into the numpy array for any arbitrary game number N1 and any move number N2 of that game. I tried reading through the documentation, but I'm still puzzled as to how to do this. Any help would be appreciated.

3. And lastly, I'd like to be able to get the outcome of game number N1.
Reply


Messages In This Thread
python-chess question - by djf123 - Jul-11-2020, 10:55 PM
RE: python-chess question - by ndc85430 - Jul-12-2020, 05:10 AM
RE: python-chess question - by djf123 - Jul-12-2020, 12:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020