Hot answers tagged

6 votes
Accepted

Is there Python code to use the Leela neural network?

Python utilities for experimenting with Leela Chess Zero a neural network based chess engine: https://github.com/glinscott/leela-chess/ Here: https://github.com/so-much-meta/lczero_tools This allows ...
user avatar
5 votes

Quickly converting board to bitboard representation using python-chess library

To convert a single bitboard to a numpy array: def bitboard_to_array(bb: int) -> np.ndarray: s = 8 * np.arange(7, -1, -1, dtype=np.uint64) b = (bb >> s).astype(np.uint8) b = np....
user avatar
5 votes

Quickly converting board to bitboard representation using python-chess library

python-chess already has the built in utilities to handle conversions. Here is an example: import chess board = chess.Board('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1') WP = board....
user avatar
5 votes
Accepted

Unable to run Stockfish on Python

The argument needs to point to the Stockfish executable. If you download the v11 zip from the Stockfish website, extract it and find the directories with the executables. I extracted it to C:\Users\&...
user avatar
4 votes

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

You can do this by sending out MultiPV, something like: engine = chess.uci.popen_engine(...) engine.setoption({ "MultiPV" : multiPV}) The module will generate multiple lines for you, as an array.
user avatar
  • 21.4k
4 votes

How to install chess.pgn on python?

First you need to install this library: pip install python-chess And make sure you're using the right pip, because still in some Linus distros pip and python are python 2.x and for python 3.x you ...
user avatar
4 votes
Accepted

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

As per: https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis engine.analysis(board) now returns an AnalysisResult object, which has the property info that you ...
user avatar
  • 2,983
4 votes

Chess Engine with Python-Based / API?

Yes, there is a chess engine in Python: Sunfish There is also a python library for chess: python-chess
user avatar
  • 141
4 votes
Accepted

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

Both approaches will work. In the second approach, you will have better accuracy of your evaluations but you may miss an important move. For example, if 20...Rxc3 positional exchange sacrifice is a ...
user avatar
  • 21.4k
3 votes
Accepted

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

Build a cache. You're exposing yourself to endless transposition. Please don't shuffle your moves. I don't have the numbers but I doubt randomly shuffle all your lists can be quick. It's O(n). I fail ...
user avatar
  • 21.4k
3 votes
Accepted

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

This should get you started, up to you to add extra features based on your objective (such as saving the games and moves, etc.) import chess import chess.engine import os import sys arguments = sys....
user avatar
  • 11.8k
3 votes

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

I used the following python script using python-chess library : import chess import chess.pgn def KPvK_up_to_symmetry_export_to_FEN_func(pgn_file_path, nb_games, output_pgn_file_name): ...
user avatar
  • 566
3 votes

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

In the error log you've pasted you can see it's a permission error, which can occur for files that behave as "executables" if you will (think any form of program, e.g. scripts, compiled files etc), ...
user avatar
  • 11.8k
3 votes

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

The volatility of the score here is caused by the time limit you have set. With time=0.100 you're restricting the engine to 100 milliseconds. With such a small time limit, there are a lot of small ...
user avatar
  • 171
3 votes
Accepted

Is there a chess.com Python api?

Yes there is a Python wrapper to the Chess.com API. Here's the package: https://pypi.org/project/chess.com/
user avatar
  • 1,949
3 votes
Accepted

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

There is Board.san() which gives you the algebraic notation. You can check the docs here. You will need a Board object for it. import chess board = chess.Board() move = chess.Move.from_uci("e2e4&...
user avatar
  • 1,573
2 votes

Python-chess is_zeroing and is_capture operation outputs

The code for those routines fairly liberally uses bitwise-and (&) rather than boolean-and (and) for the logical expressions, so I assume integer values rather than booleans are being returned. I ...
user avatar
  • 1,541
2 votes

Python and UCI engine

To get evaluation score for each legal move, you can do: Set MultiPV to a high number, like in your answer Play the moves, then invoke SF on each of the resulting FEN. For example, in the starting ...
user avatar
  • 21.4k
2 votes

Looking for a Python chess engine

I have experience with only SunFish, but I doubt it's 2500+ level. http://talkchess.com/forum3/viewtopic.php?f=2&t=67025 This link should help you. If you're not happy with the folks at ...
user avatar
  • 21.4k
2 votes

Python Engines to Beat to Take the Crown

You may claim yourself the World Computer Champion in Python if you beat all of them: http://talkchess.com/forum3/viewtopic.php?f=2&t=67025
user avatar
  • 21.4k
2 votes

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

As the version of python-chess I'm running doesn't support chess.uci, here's what worked for me. engine = chess.engine.SimpleEngine.popen_uci("/path/to/engine.exe") board = chess.Board() ...
user avatar
2 votes

Play chess in Python programming language?

Yes. You can use the package to play against yourself and an engine. While I don't think there is one function that can do everything for you, but I can give you hints: To setup up a game against an ...
user avatar
  • 21.4k
2 votes

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

I need to get two things out of the way: If your are concerned about performance, Python is not for you. The language just isn't built for this kind of thing. That said, I do think it can be useful ...
user avatar
2 votes

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

First, engine.options["NeverClearHash"] is wrong on two counts. It is engine.option, not engine.options and that command queries the value rather than sets it. To set the value you have to do ...
user avatar
  • 73.9k
2 votes
Accepted

How to install chess.pgn on python?

If you've already installed python-chess via pip/conda/choco or your favourite package manager, then to use chess.pgn, in your .py files just call from chess import pgn or import chess.pgn. You have ...
user avatar
  • 4,830
2 votes

Communication with Stockfish engine via Python

The Problem was p.communicate(), which kills the subprocess. The interaction with the engine works well with the following code: def put(command, inf_list, tmp_time): engine.stdin.write(command+'...
user avatar
  • 41
2 votes

running stockfish with docker and docker-compose

not quite the solution I was looking for but everything is working with the following Dockerfile FROM nvidia/cuda:10.0-cudnn7-devel RUN apt-get update && apt-get dist-upgrade -y && ...
user avatar
  • 688

Only top scored, non community-wiki answers of a minimum length are eligible