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
#2
Cool, I didn't know lichess had an API.

In any case, what have you found in the docs to let you get the board at a particular move? What type does that board method return? Basically, what have you looked up and tried?
Reply
#3
I can't figure out how to do #2 and #3 listed in my first post. I read through the documentation, but I can't figure out how to do these two things. I haven't tried anything yet as I am having a difficult time understanding what I am reading and can't find the commands that I want. I don't know what the board command returns.
Reply


Forum Jump:

User Panel Messages

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