Questions tagged [python]

Python is a general purpose and high level programming language. You can use Python for developing desktop GUI applications, websites and web applications.

Filter by
Sorted by
Tagged with
1 vote
0 answers
37 views

I have a simple code which has a bug at the particular place given below, but I'm unable to detect it exactly and fix it

I have asked a similar question elsewhere and I have detected where roughly is a problem. It is in this function which gets processed for node "1" only, see the output section below: (I'm ...
3 votes
0 answers
77 views

Why this Python code for a simple endgame yields wrong results?

I have a Python code as below for a trivial (for a human) endgame, but I'm unable to make it output correct results. I'm seeking for a fully optimal play by both player: the stronger player should try ...
1 vote
1 answer
153 views

how to download pgn of a chess.com game by game ID programmatically

Every chess.com game has a game ID. For example https://www.chess.com/game/live/2485075845 2485075845 is the game ID. When you go to this URL it is possible to download the PGN by clicking the share ...
4 votes
1 answer
889 views

Is there an en passant opportunity in this position?

I am trying to create a scalable chess move generator in python for my chess engine. My legal move benchmark comes from "python-chess" library. My move generator generates an en passant ...
2 votes
2 answers
775 views

How can I make my chess engine more efficient?

First, here's some context. My chess engine uses bitboards and works like this: A single gameboard is created as a 2d array at the start of the program. Like this: [[-4 -2 -3 -5 -6 -3 -2 -4] [-1 -1 -...
1 vote
1 answer
155 views

List specific moves from a pgn file using python chess.pgn

Using python chess, I would like to be able to list specific moves from a pgn string. For instance, in this string: c4 e5 2. g3 c6 ( 2... d5 3. cxd5 ) 3. Nf3 e4 4. Nd4 d5 5. cxd5 Qxd5 6. Nc2 ( 6. e3 )...
5 votes
2 answers
863 views

How to run lichess stockfish analysis locally?

I am working on a research project where we need to run stockfish on hundreds of thousands of pgns we have collected. We need to extract all information generated from stockfish like centipawns, ...
7 votes
0 answers
396 views

Stockfish position evaluation component terms in Python?

I saw the excellent Javascript-based guide to how Stockfish evaluates (non-NNUE). Is there a python version out there, perhaps using python-chess? What I am trying to do (in case you have other ...
2 votes
1 answer
131 views

UCI Play Colors

How do I get the color the engine should play? My minimax function requires color to return the best move for that color. I'm using uci protocol, but I'm looking at the docs and cannot find anything ...
1 vote
0 answers
235 views

Is there a way to convert a .cbh file to PGN without a GUI?

I want to convert a .cbh file to PGN (or whatever format meta information (elo, player, score, etc) from which I can eventually convert to dataframe/json/anything easy to work with). The most popular ...
5 votes
2 answers
5k views

Quick method for generating FEN strings from PGN using Python Chess

Is there a fast way to generate FEN strings for every move in a PGN? I'm generating an opening book using the Lichess elite database and Python Chess, but Python Chess is taking a surprisingly long ...
4 votes
1 answer
302 views

How do I get the solutions of the puzzle using stockfish?

I have a list of PGN files that are games between top grandmasters where one player resigned at the end of the game. I am looking to find solutions to those position using stockfish/or another chess ...
2 votes
1 answer
539 views

My Transposition Tables implementation slows down Alpha Beta Pruning

I have this implementation of alpha beta pruning I made a couple days ago. I've been trying to look into transposition tables. When I tried this implementation it was slower than the original code. I ...
2 votes
2 answers
1k views

Can't properly use python stockfish package in Mac

I'm trying to get stockfish for python working but I am running into issues. This is my code so far. from stockfish import Stockfish stockfish = Stockfish('/Users/Me/opt/anaconda3/lib/python3.9/site-...
4 votes
1 answer
621 views

How do you nerf Stockfish to analyze the same position multiple times?

I want to make some statistics by analyzing the same position, multiple times, at different levels of Stockfish. Precisely, I would like Stockfish to analyze a specific position at different "...
1 vote
1 answer
886 views

Optimising Stockfish parameters when batch-analyzing with python-chess

I am running a python script that analyzes a large batch of PGN games (each of ~5,000 games) across and exports the games evaluations. It calls Stockfish 14 to analyze each game at depth 20. **[EDIT: ...
2 votes
2 answers
557 views

Python Efficient Board Scoring Function To Use As Placeholder

I'm building a chess engine in Python. I'd like to find a board evaluation function that would be easy to put into my engine as a placeholder while I work on other aspects of the engine first. I would ...
2 votes
1 answer
494 views

Chess engine in python

Are there any open-source chess engines that are written in primarily or fully in python? For example, Stockfish is written in primarily C++.
4 votes
2 answers
3k views

Quickly converting board to bitboard representation using python-chess library

I would like to convert a given chess board into its bitboard representation, but my implementation is rather slow. Here is what I'm doing (using the python-chess package): board = chess.Board('...
2 votes
1 answer
2k views

How do I convert a move from coordinate notation to algebraic notation?

The following Python code gives the best move in coordinate notation: import chess import chess.engine sfEngineTxt = "E:\Chess\Stockfish\stockfish_14_x64_modern" sfEngine = chess.engine....
1 vote
1 answer
223 views

How to avoid the same opening move in an engine built using Python chess

I created a chess engine using the Python chess library. It has an evaluation function (piece values, piece square values, and capture values) and minimax. Alpha-beta pruning is also implemented. At ...
2 votes
2 answers
2k views

Is there Python code to use the Leela neural network?

I am interested in doing some analyses of chess games using the neural network trained for Lc0. To that end I need to be able to turn PGN into the right kind of input vectors and to load and use the ...
3 votes
2 answers
738 views

How can I get multiple computer recommended lines in python-chess module?

In python-chess you can communicate with the engine on a given position. However the method presented in https://python-chess.readthedocs.io/en/latest/uci.html using the engine.go() function with only ...
5 votes
1 answer
2k views

Python script to let stockfish selfplay 10 games from a given position

I would like to have Stockfish to selfplay 10 games starting from a given position. Game should end after 10 moves. From the python-chess documentation there is an example of playing only one such ...
1 vote
1 answer
656 views

Is there a chess.com Python api?

I want to program a bot and implement it on chess.com, but are there any types of chess.com Python api which will make the bot use the chess.com interface?
4 votes
1 answer
654 views

Obtaining the correct move from syzygy tablebases (Python)

I have created a chess engine in Python and now want to start using the endgame tables in syzygy. I have downloaded all the relevant files and is now ready to start. I have found how to access the ...
2 votes
1 answer
1k views

running stockfish with docker and docker-compose

I have access to a powerful computer at work so naturally I want to run a chess engine on it (stockfish for now and later leela). I am trying to use docker-compose to link a stockfish image and a ...
4 votes
2 answers
2k views

How can I increase the search ply depth of my minimax function for my chess engine?

I have programmed a minimax function with alpha-beta pruning for a chess engine I am building. However, it is very slow and I cannot analyze to a deeper depth as it would take too much time. I believe ...
2 votes
0 answers
350 views

How to turn off Contempt in engine analysis?

I'm trying to analyze a game with the python-chess package, and for that I want to turn off the "Analysis Contempt" option in Stockfish. However, it seems it doesn't work, and I don't know ...
3 votes
1 answer
5k views

Unable to run Stockfish on Python

I know this isn't a programming forum, though it's chess-related, hence the placement on here. Basically, I'm trying to setup stockfish with Python on my PC. I installed it via pip install stockfish. ...
2 votes
1 answer
407 views

What's the best way to get the top n engine moves?

I want to use python-chess to get the top 5 Stockfish moves from a given position with a numerical evaluation for each move. Is it more accurate to run the engine for 10 minutes with MultiPV=5, or to ...
2 votes
1 answer
561 views

Chess Engine with Python-Based / API?

I went through the most popular chess engines, e.g. StockFish, Komodo, Rykba and so forth, but I wasn't able to a.) find an API or b.) a python based Engine - does anyone know a suitable project? I ...
1 vote
2 answers
222 views

Export KPvK endings positions (up to black/white symmetry) from ChessBase 15 using python-chess

I have the Mega Database 2020 from ChessBase and ChessBase 15. I am using ChessBase 15 to search the Mega Database 2020, my search criterion being all games ended through a KPvK (king and pawn vs. ...
2 votes
1 answer
2k views

Communication with Stockfish engine via Python

I try to access the Stockfish engine via Python, but only get bestmove = a2a3. If I enter the same commands into the MAC-terminal, the engine calculates the correct move. Can anyone help me, please ?...
3 votes
1 answer
322 views

Question on how to access a move on a line outside the main line using python-chess

I'm trying to write a simple code that is capable of reading a PGN file and searching for moves and comments throughout the variant tree. However, I have not been successful, I have not yet been able ...
2 votes
3 answers
720 views

How to use Arena GUI outputs in a python program

I'm currently developing a self-playing chessboard on which I'd like to implement an Artificial Intelligence (AI) (currently it's Stockfish. I would like to know how I could, if I can, export Arena ...
3 votes
1 answer
951 views

Python-chess : Are the move scores enough to rank moves from the most to least likely moves played by an engine?

My goal is to make a script to finding the most and least likely move an engine will play, and then make a list it. I tried using the scores to make such a list, with the best score equalling the most ...
5 votes
2 answers
2k views

Looking for a Python chess engine

I am looking for a Python chess engine package. It must be fully contained in Python, I don't want to download separate files for the engine itself and link them up somehow. All I want it to be able ...
3 votes
1 answer
5k views

Python-chess : how to get a list for the best engine moves

I am working on a simple cheat detection script to find if a user used one of the top engine moves in a game, so I found this great python-chess library Additionally, I found this example to getting ...
1 vote
3 answers
501 views

Python-chess is_zeroing and is_capture operation outputs

I'm using python-chess to analyze a game. I have my code like this, and I expect 3 boolean outputs. print("is_castling: " + unicode(board.is_castling(node.move))); print("is_zeroing: " + unicode(...
4 votes
2 answers
2k views

Python and UCI engine

I'm working with Stockfish in Python 3. And when I do something like this: I get just "bestmove e2e4". How can I retrieve full information? Like this:
2 votes
1 answer
280 views

Python Engines to Beat to Take the Crown

Since Python is extremely slow, chess engines are almost never written using it. I've been building a Python engine to avoid this issue (through JIT compilation), and want to compare my engine ...
0 votes
1 answer
3k views

Why can't I use my stockfish engine with python chess? [closed]

I'm using python chess and I'm trying to use my stockfish 10 engine downloaded from the stockfish website. import chess.uci engine = chess.uci.popen_engine(r"stockfish-10-linux/Linux/...
0 votes
1 answer
574 views

Python and Stockfish [duplicate]

I am trying to get Stockfish to work in Python 3. Just to get started on my project, I tried to have Stockfish think until a depth of 20. However, the program instantly returns that Stockfish ...
3 votes
2 answers
2k views

How to install chess.pgn on python?

I don't know how to import chess.pgn on Python. I searched everywhere, but I didn't find anything. Can anybody here help me?
14 votes
1 answer
7k views

How to convert PGN moves to long algebraic notation (in python)?

I want to read a PGN file and then advance to a certain move number, and feed that to an UCI engine. Turns out engines work using long algebraic notation, and PGNs are in short algebraic. What is an ...
4 votes
3 answers
2k views

Play chess in Python programming language?

I am searching for a program/library in Python which will let two users or a user and an AI play chess with each other. PS: I have found python-chess. Can this be used for the above along with a ...
2 votes
1 answer
596 views

How can I send a UCI command to a chess engine in Python?

I have a followup question to my previous thread: Python script to let stockfish selfplay 10 games from a given position There are some engines that allow you to set a command that imposes that the ...
2 votes
1 answer
522 views

PythonChess - Get engine to predict a list of the best moves in a position

Say that I currently have a board, and then on that board I move my e2 pawn to e4. I'm looking for a way to get the engine to predict the X amount of best moves for black. I know how to predict the ...