All Projects → thomasahle → fastchess

thomasahle / fastchess

Licence: GPL-3.0 license
Predicts the best chess move with 27.5% accuracy by a single matrix multiplication

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to fastchess

Sunfish
Sunfish: a Python Chess Engine in 111 lines of code
Stars: ✭ 2,254 (+2905.33%)
Mutual labels:  chess-engine, chess, chess-ai
Walleye
A chess engine written from scratch in Rust ♞
Stars: ✭ 82 (+9.33%)
Mutual labels:  chess-engine, chess, chess-ai
Bit-Genie
UCI chess engine in C++
Stars: ✭ 19 (-74.67%)
Mutual labels:  chess-engine, chess, chess-ai
Zerofish
An implementation of the AlphaZero algorithm for chess
Stars: ✭ 34 (-54.67%)
Mutual labels:  chess-engine, chess
rustic
Rustic is a chess engine. It is written from scratch, in the Rust programming language.
Stars: ✭ 68 (-9.33%)
Mutual labels:  chess-engine, chess
OpenChess
A cross-platform chess game.
Stars: ✭ 18 (-76%)
Mutual labels:  chess-engine, chess
lc0-docker
lc0docker: run lc0 chess client and lichess bot under Docker and Kubernetes
Stars: ✭ 26 (-65.33%)
Mutual labels:  chess-engine, chess-ai
renpy-chess
A chess GUI built with Ren'Py, python-chess, and Stockfish. Version 2.0 of https://github.com/RuolinZheng08/renpy-chess-engine
Stars: ✭ 36 (-52%)
Mutual labels:  chess-engine, chess
php-grandmaster
Chess engine written in PHP
Stars: ✭ 100 (+33.33%)
Mutual labels:  chess-engine, chess-ai
Realtime-OpenCV-Chess
♔ Chess-playing with Open-CV [Human vs AI (Stockfish engine)]
Stars: ✭ 18 (-76%)
Mutual labels:  chess-engine, chess
stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (-72%)
Mutual labels:  chess-engine, chess
elephantfish
elephantfish: 一个只有124行的中国象棋引擎
Stars: ✭ 129 (+72%)
Mutual labels:  chess-engine, chess
uci
A thin wrapper on a uci chess engine
Stars: ✭ 33 (-56%)
Mutual labels:  chess-engine, chess
ConvChess
Convolutional Neural Networks learns to play chess moves
Stars: ✭ 14 (-81.33%)
Mutual labels:  chess-engine, chess
littlewing
Chess engine written in Rust ♛
Stars: ✭ 27 (-64%)
Mutual labels:  chess-engine, chess
liground
A free, open-source and modern Chess Variant Analysis GUI for the 21st century
Stars: ✭ 41 (-45.33%)
Mutual labels:  chess-engine, chess
ChessVisionBot
Chessbot using computer vision to play on any chess website
Stars: ✭ 32 (-57.33%)
Mutual labels:  chess, chess-ai
Demolito
UCI Chess Engine
Stars: ✭ 41 (-45.33%)
Mutual labels:  chess-engine, chess
magic-bits
A C++ header-only library for efficient move generation in Chess using "magic bitboards" technique
Stars: ✭ 26 (-65.33%)
Mutual labels:  chess-engine, chess
bot-o-tron
Try out lichess' bot interface
Stars: ✭ 36 (-52%)
Mutual labels:  chess-engine, chess

Teaching FastText to play Chess

FastChess is a chess engine predicting the next move using the http://fastText.cc text classification library. In other words, it is a simple one-layer + soft-max model, taking the board state as a vector and outputting a vector of probabilities for each possible move.

The project also contains a Monte Carlo Tree Search, following by Alpha Zero, which combines with the simple linear model to provide a higher quality of play.

You can play against FastChess on Lichess: https://lichess.org/@/fastchess-engine (requires log-in). It's current rating (January 2021) is 2052 Bullet and 1901 Blitz.

Screenshot

Screenshot

Run it!

You'll need the following libraries:

pip install git+https://github.com/facebookresearch/fastText.git
pip install git+https://github.com/niklasf/python-chess.git
pip install numpy

Afterwards you can play by

$ python play_chess.py
Do you want to be white or black? white
  8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜
  7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟
  6
  5
  4
  3
  2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙
  1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
    a b c d e f g h

Your move (e.g. Nf3 or d2d4): e4

To disable MCTS and play directly against the fastText model, add the -no-mcts argument. See python play_chess.py --help for more options.

Train the model

There are two ways to train the model. The first one is to download a set of pgn files, like https://storage.lczero.org/files/training_pgns/ and run

python proc.py 'ccrl/**/*.pgn' -test proc.test -train proc.train
fasttext supervised -input proc.train -output proc.model -t 0 -neg 0 -epoch 1
fasttext test proc.model.bin proc.test 1
mv proc.model.bin model.bin
python play_chess.py -selfplay

The other way is to generate your own data, e.g. using stockfish. You can train your own model as:

python make_data.py -games 1000 | shuf > g1000
/opt/fastText/fasttext supervised -input g1000 -output model -t 0 -neg 0 -epoch 4

And then run the program as:

python play_chess.py model.bin

You can also generate more data by self-play (as default games are generated by stockfish)

python make_data.py -games 1000 -selfplay model.bin > games
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].