Skip to main content

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
0 votes
1 answer
82 views

Fix Alpha-Beta Pruning in Chess Negamax Algorithm

I've made a decently simple chess engine so far and I'm running into a problem related to the chess engine thinking it found mate and playing those moves despite it not having a forced mate. This ...
user24551772's user avatar
0 votes
0 answers
79 views

Stockfish with python-chess on ubuntu

I want to use Stockfish with a simple chess python program I am writing on Ubuntu. It uses the python-chess library and is text based at the moment. There are various references to installation ...
Beasty's user avatar
  • 1
3 votes
0 answers
252 views

I have a code in Python which should compute fully optimal moves in an endgame for Black and White player, but it seems that k is playing suboptimally

In this example "'fen': '7Q/8/8/6k1/2K5/8/8/8 w - -', 'moves_to_mate': 9" should be "'fen': '7Q/8/8/6k1/2K5/8/8/8 w - -', 'moves_to_mate': 11" according to Stock-Fish. EDIT The ...
user2925716's user avatar
1 vote
0 answers
52 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 ...
user2925716's user avatar
3 votes
0 answers
94 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 ...
user2925716's user avatar
4 votes
1 answer
897 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 ...
srv's user avatar
  • 43
1 vote
1 answer
227 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 ...
cmgchess's user avatar
  • 2,692
1 vote
1 answer
174 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 )...
Matt's user avatar
  • 13
5 votes
2 answers
1k 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, ...
Elias's user avatar
  • 51
2 votes
1 answer
136 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 ...
ShadowProgrammer's user avatar
1 vote
0 answers
286 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 ...
Samvel Avakyan's user avatar
4 votes
1 answer
333 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 ...
sebastian's user avatar
2 votes
1 answer
591 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 ...
cuteboy101's user avatar
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-...
Ozzy08's user avatar
  • 121
4 votes
1 answer
650 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 "...
Giorgio's user avatar
  • 43
1 vote
1 answer
964 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: ...
David Smerdon's user avatar
2 votes
2 answers
699 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 ...
Sam Ragusa's user avatar
2 votes
1 answer
500 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++.
Varun W.'s user avatar
  • 883
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....
Hal Heinrich's user avatar
5 votes
2 answers
6k 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 ...
MattY's user avatar
  • 153
1 vote
1 answer
227 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 ...
David Gladson's user avatar
2 votes
2 answers
838 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 -...
Chris's user avatar
  • 738
8 votes
0 answers
423 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 ...
Abhijit Mahabal's user avatar
1 vote
1 answer
688 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?
Rashaad's user avatar
  • 21
4 votes
1 answer
701 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 ...
Eli's user avatar
  • 43
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 ...
nak3c's user avatar
  • 718
2 votes
0 answers
353 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 ...
JohnnyQ's user avatar
  • 223
3 votes
1 answer
6k 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. ...
velotoy's user avatar
  • 33
2 votes
1 answer
430 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 ...
Cory Butzon's user avatar
2 votes
1 answer
593 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 ...
J. Doe's user avatar
  • 29
4 votes
2 answers
4k 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('...
Arman's user avatar
  • 171
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 ...
Destaq's user avatar
  • 193
3 votes
1 answer
334 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 ...
João Paulo Versiani Ladeia's user avatar
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 ?...
Michael's user avatar
  • 41
2 votes
1 answer
537 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 ...
Tarun R's user avatar
  • 81
1 vote
2 answers
224 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. ...
Olórin's user avatar
  • 606
2 votes
1 answer
613 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 ...
Arturo's user avatar
  • 273
2 votes
2 answers
3k 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 ...
BlindKungFuMaster's user avatar
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 ...
Arturo's user avatar
  • 273
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?
Tortank92's user avatar
2 votes
3 answers
742 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 ...
DGGB's user avatar
  • 21
3 votes
1 answer
962 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 ...
shar's user avatar
  • 301
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 ...
shar's user avatar
  • 301
0 votes
1 answer
582 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 ...
r2d2bb8's user avatar
  • 19
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/...
jenny LI's user avatar
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 ...
Fourth's user avatar
  • 51
2 votes
1 answer
281 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 ...
Sam Ragusa's user avatar
3 votes
2 answers
802 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 ...
Qwertford's user avatar
  • 241
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:
MrTrushka's user avatar
1 vote
3 answers
512 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(...
Bee's user avatar
  • 165