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
0
votes
3 answers

What is the best way to find out if the move captured a piece in python chess?

The best way I found to check if the move captured a piece is to count all the pieces before and after the move and verify if different, but seems to me very inefficient and not elegant.
0
votes
2 answers

Saving an output of a program in python as an image

I need to save an image of a chessboard, like the one created by this code: import chess board = chess.Board() board The output is the starting chessboard: How can I save this image and print it (for example inside a function)? Is there a unique…
0
votes
0 answers

Making Predictions (classifying chess pieces)

I am trying to identify all the pieces present on the Chessboard via machine learning.Currently I am predicting for a single piece.I want to load the trained model from the disk,loop through the board, get the playing square crop, and the model will…
0
votes
1 answer

chessboard pieces won't display

Code: import tkinter, os from PIL import ImageTk, Image def sortFileImages(files): black = [i for i in files if 'black' in i] white = [i for i in files if 'white' in i] pawns = [[i]*7 for i in files if 'pawn' in i] return black +…
lbragile
  • 7,549
  • 3
  • 27
  • 64
0
votes
0 answers

Python: Stockfish is opening too many processes

I am getting: OSError: [Errno 24] Too many open files and stockfish is creating too many processes. How can I fix it? This is the part of my code that makes the error: import chess.engine def stockfish(board, time_limit = 0.1): engine =…
TheLizzard
  • 7,248
  • 2
  • 11
  • 31
0
votes
1 answer

Why is the same function in python-chess returning different results?

I'm new to working with python-chess and I was perusing the official documentation. I noticed this very weird thing I just can't make sense of. This is from the documentation: import chess.pgn pgn =…
Abhishek
  • 553
  • 2
  • 9
  • 26
0
votes
4 answers

How to get a piece in python-chess

I now use python-chess for my chess project. I think I have found the usage of getting it through direct definition. e.g. chess.Board().piece_at(chess.B1) but I want to get it through a variable, is there any way for me to get the piece…
Michael Yang
  • 109
  • 1
  • 6
0
votes
1 answer

Problem with dimensions of input array in Keras (TF) with CNN to play chess

I want to feed a numpy array into a CNN, that contains 2 chess positions, one before a move and the second after a certain move. I want to train the CNN to estimate the evaluation of that move by a conventional chess program. These evaluations are…
0
votes
1 answer

python-chess - Global variable changes when function runs

I'm confused about how Python scoping works here. x = 1 def do(y): y = y * 2 print y print x do(x) print x The code above produces this output: 1 2 1 The global variable remains unchanged, but in the function, the local variable prints…
user8354265
0
votes
1 answer

Cannot call attribute from file despite calling it in cmd prompt

Working with this package - https://pypi.python.org/pypi/python-chess In cmd I can do the following >import chess >b = chess.Board() >print (b) r n b q k b n r p p p p p p p p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . P P P P…
-1
votes
1 answer

How to use Python multiprocessing library in a chess search algorithm?

I am currently working on a chess engine, and I am looking at parallelization as a way to optimize the time it takes to search legal moves to find the best one. I found the Python module multiprocessing, however since it needs to execute in…
kiraksi
  • 3
  • 3
-1
votes
1 answer

who to start as black in stockfish python

I'm trying to start the Stockfish module in Python as the black player instead of the default white. I've been looking for parameters or other information on how to do this, but haven't been able to find anything that works. Can you please help me…
-1
votes
3 answers

python chess board.attackers how to use

I'm playing around with some python chess code, its for fun. However i have difficulty in using the board.attackers function. I'm not sure what it accepts This code below makes use of the chess lib described…
Peter
  • 2,043
  • 1
  • 21
  • 45
-1
votes
1 answer

How do slice and print the mainline with the python-chess library?

There's a way to slice the mainline like we slice lists on Python? For example: mainline[start:stop] # moves start through stop-1 mainline[start:] # moves start through the rest of the mainline mainline[:stop] # moves from the beginning…
mykahveli
  • 113
  • 4
-1
votes
1 answer

Queen moves function does not return correct number of moves

This is my function to calculate all the possible moves for the queen's Diagonals: def dia(n, r_q, c_q, obs): ans = 0 # up right cnt = 1 while cnt + r_q <= n and cnt + c_q <= n: if [cnt + r_q, cnt + c_q] in obs: …
1 2 3
8
9