Questions tagged [python-chess]

For questions about the python-chess library (for questions about your own chess algorithm, use the [chess] tag instead).

Refers to the python-chess library, developed by Niklas Fiekas.

python-chess is a pure Python chess library with move generation, move validation and support for common formats.

This tag should be used only for questions about the python-chess library.

For general questions about chess-playing algorithms, use the tag combined with the tag. If your question is not actually about chess or the algorithms involved, you should not use the tag.

External Links

129 questions
10
votes
2 answers

How to display an SVG image in Python

I was following this tutorial on how to write a chess program in Python. It uses the python-chess engine. The functions from that engine apparently return SVG data, that could be used to display a chessboard. Code from the tutorial: import…
Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43
6
votes
1 answer

Python-chess open UCI engine permission error denied

I am currently creating a python script that opens a chess engine, Stockfish, using python-chess, and chess.uci. However, when I try opening up the stockfish engine, I get PermissionError: [Errno 13] Permission denied So I looked more into this…
robby
  • 73
  • 5
5
votes
3 answers

How to get a list of all the legal moves in the python-chess module?

I am using the python chess module. On the website, it shows that you can check if a move is legal by using import chess board = chess.Board() move = input("Enter a chess move: ") if move in board.legal_moves: # Some code to do if the move is…
Justin Cheng
  • 153
  • 1
  • 8
5
votes
3 answers

Visualize the full chess board from the library python-chess on line command

I am working a chess game based on this library: https://pypi.org/project/python-chess/ or https://github.com/niklasf/python-chess On Jupyter Notebook, if I run this code: import chess board = chess.Board() board It will display a nice board (i.e.…
FFLS
  • 565
  • 1
  • 4
  • 19
4
votes
1 answer

Printing individual moves with the python-chess library

I want to sequentially print the moves (one string per move at a time) from a game I read (using the python-chess library) from a text file. So, say I have a pgn file with a game that has the following moves... 1. f3 e5 2. g4 Qh4# ... I would like…
BaDer
  • 53
  • 1
  • 3
4
votes
2 answers

python-chess - AttributeError: module 'chess' has no attribute 'pgn'

I'm trying to export a python-chess game to a pgn file. The documentation recommends - import chess . . chessBoard = chess.Board() . . #Play the game and when over do below game = chess.pgn.Game.from_board(chessBoard) with open('output.pgn',…
Achilles
  • 1,099
  • 12
  • 29
3
votes
1 answer

A buffer which shows in pygame does not display in tkinter

The code below illustrates a buffer which displays with pygame.image.frombuffer but not with tkinter PhotoImage import chess, chess.svg, pylunasvg as pl from tkinter import Tk, PhotoImage # This is where I create the buffer board =…
3
votes
1 answer

Move ordering for chess engine

Part 3 of my python programming project. Find it here. Since the last post, I've managed to get work out the transposition tables and started creating the move ordering function. The move function starts by checking if there's a move in the opening…
Bruno
  • 103
  • 6
3
votes
1 answer

Print best move with python_chess

Easy question, but I'm doing something wrong and don't know what :( I'm using the python-chess libary and want to print the best move to the engine (Stockfish). I'm able to print the score from the engine with board = chess.Board(fen) info =…
PixelAim
  • 65
  • 5
2
votes
1 answer

How to get the winning chances of white in python-chess

So I started creating a multiplayer chess game. Now, since it is a GUI, I have the chessboard on the left side, and on the right side, there is an analysis area. Now, I want my analysis area to show both the user's winning chances. Let's say that…
BladeOfLightX
  • 504
  • 4
  • 17
2
votes
1 answer

AttributeError: module 'chess' has no attribute 'Board' chess board error

i'm making chess in python i'm having this error this my code: import chess.board board=chess.Board() board full error: Traceback (most recent call last): File "chess.py", line 1, in import chess File…
2
votes
2 answers

Where do I start with a chess game made in python(with a GUI)

I'm not asking for specific code, but the general structure and how to link the python-chess library with the pygame library with the code that allows the player and AI to move. Any tips on where to start?
Moiz _
  • 23
  • 1
  • 4
2
votes
3 answers

How can I use SVGs with pygame (or perhaps display PNGs at a higher definition)?

I'm trying to make a chess opening trainer with Pygame. Graphically, it's incredibly simple; it works like a slideshow, I am only blitting a single image to the screen at a time which updates when I press the return key. I am using chess.svg to…
2
votes
1 answer

Is there a way to get legal moves for the person whos turn its not? python-chess

I am interested in making a chess algorithm. For this, I will be using the python-chess library. However, to make a good algorithm I need to be able to return the opposing persons legal moves even if it isn't their turn. So in the start of the game…
2
votes
1 answer

How to get a chess board from a final position from read_game?

Here we successfully parse a PGN game: import chess, chess.svg, chess.pgn, io game = chess.pgn.read_game(io.StringIO("1. e4 e5 2. Nf3 *")) print(game) Unfortunately, board() is still the initial position. How to get the final position…
Basj
  • 41,386
  • 99
  • 383
  • 673
1
2 3
8 9