6
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....
6
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....
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 ...
6
votes
Accepted
My Transposition Tables implementation slows down Alpha Beta Pruning
Your current implementation just stores on which positions quiesce search was ran. If it was run before, then it skips the position.
But you don't want to skip searching all positions you searched ...
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\&...
5
votes
Accepted
Quick method for generating FEN strings from PGN using Python Chess
If you are not tied to using PythonChess and simply want FEN encodings of each position, you might like to consider using my free, open-source pgn-extract program with its -Wepd option to output in ...
5
votes
Accepted
Can't properly use python stockfish package in Mac
Download an appropriate stockfish binary at https://stockfishchess.org/download/.
Remember where it is and use that location and engine filename.
stockfish = Stockfish('/engine_path/engine_filename')
5
votes
Accepted
UCI Play Colors
The engine receives a position command.
Example 1:
position startpos
In startpos, the side to move is white.
The startpos is just equal to a fen:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - ...
5
votes
How to run lichess stockfish analysis locally?
Download Stockfish form official website. Note that there are different versions for different cpus - pick first one that works.
Then you can communicate with stockfish using UCI protocol. For python ...
5
votes
Accepted
Is there an en passant opportunity in this position?
So the situation is that there would be an en passant opportunity, except it's not a legal move because the pawn on e5 is pinned. Both choices are functionally the same as the tree of legal moves from ...
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.
4
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), ...
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 ...
4
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....
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 ...
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 ...
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
4
votes
how to download pgn of a chess.com game by game ID programmatically
It is possible to download games from chess.com, otherwise services like Opening Tree would not work.
Chess.com has published it's data API.
It includes endpoints for downloading games in PGN format.
...
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 ...
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):
...
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 ...
3
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 ...
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/
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&...
3
votes
Accepted
How do you nerf Stockfish to analyze the same position multiple times?
Use engine.play because you are using skill level, note use info parameter to get the score. You don't need to worry about the hash table because you quit the engine for every skill levels.
Method 1
...
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 ...
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
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()
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
python × 56engines × 29
programming × 21
stockfish × 15
software × 13
pgn × 10
analysis × 5
computer-chess × 5
uci × 5
minimax × 3
endgame × 2
database × 2
chessbase × 2
chess.com × 2
online-chess × 1
evaluation × 1
notation × 1
mathematics × 1
tablebases × 1
lichess × 1
websites × 1
en-passant × 1
fen × 1
performance × 1
leela × 1