Building NN-powered engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

maelic
Posts: 12
Joined: Wed Jul 05, 2017 12:44 pm
Location: Czech Republic

Building NN-powered engine

Post by maelic »

Hello guys!

I was assigned a master's thesis with a goal of building an chess engine based on Neural Networks. I do have an idea but I wanted to ask you, experts in the field, what you think about it.

I would like to build the engine using Python and Keras. I found a method of compiling .exe file from Python script which I suppose will be essential since I want to use UCI protocol to communicate with various GUIs. It will be a long road but I have almost a year to do it.
The main idea is to use neural network as evaluation function together with MCTS, somewhat AlphaZero style, or to build two nets, one for eval and second for move choice.

My goal will be to build engine able to defeat myself - and average player of 1850 FIDE elo. I realize the potential of engine is very dependant not only on correct design but also on raw machine power which I will most definitively lack.

Please, if you feel like it, leave me any kinds of comments on how you think this goal could be achieved, if you can use UCI without the need of compiling to .exe etc. Any suggestion, any advice, anything at all will be greatly appreciated!

Thank you, have a great day!
Miloslav Macurek

(I am kind of begginer programmer, starting this project because I love chess and it suits my field of study. I will make it open source. I am still battling with concept and don't have everything ready yet, that will take time. But I am determined to finish it at the best of my capabilities!)
Best regards,
Miloš
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: Building NN-powered engine

Post by elcabesa »

A simple but we'll programmed engine will be able to defeat a 1800 elo player very easily.

processing power is not so important, unless you want to defeat very strong engines.

Good luck with you peoject
konsolas
Posts: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

Re: Building NN-powered engine

Post by konsolas »

Leela Chess Zero is a open source project which aims to recreate the published AlphaZero paper, and uses self-play to train convolutional neural networks.

Giraffe is an older project that uses neural networks with the more common alpha-beta search.

Both are open source, so it might be interesting to take a look at the techniques and frameworks used in those projects.
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Building NN-powered engine

Post by jdart »

One approach would be to use a traditional searcher and a NN for the evaluation function.

This won't be high performance since the NN will have to be evaluated frequently at runtime. But it would suffice for an 1800 level engine.

I will caution though as others have said here that building even a minimal chess engine is not a small task. It is not so hard to build something that plays legal moves, but making it bug-free is another matter, and bugs can have a significant effect on playing strength. For this reason you might consider, if it is allowed, starting with an open-source Python engine or at least a library such as python chess and adding a NN into it. This would let you concentrate more on the eval and training.

See also https://github.com/gareththegeek/chesslearn - looks relevant.

--Jon
mkchan
Posts: 88
Joined: Thu Oct 06, 2016 9:17 pm
Location: India

Re: Building NN-powered engine

Post by mkchan »

jdart wrote: Fri Jun 22, 2018 3:05 pm One approach would be to use a traditional searcher and a NN for the evaluation function.

This won't be high performance since the NN will have to be evaluated frequently at runtime. But it would suffice for an 1800 level engine.

I will caution though as others have said here that building even a minimal chess engine is not a small task. It is not so hard to build something that plays legal moves, but making it bug-free is another matter, and bugs can have a significant effect on playing strength. For this reason you might consider, if it is allowed, starting with an open-source Python engine or at least a library such as python chess and adding a NN into it. This would let you concentrate more on the eval and training.

See also https://github.com/gareththegeek/chesslearn - looks relevant.

--Jon
I second using python-chess. Better to focus on the problem of search and nn but if you insist on making everything yourself, it's a bit of a task
brianr
Posts: 536
Joined: Thu Mar 09, 2006 3:01 pm

Re: Building NN-powered engine

Post by brianr »

There are some simpler implementations than Leela Chess (or Lc0), or even Giraffe.

You could look here:
https://github.com/Zeta36/chess-alpha-zero

or even start with the Zeta36 Connect4 game before tackling chess.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Building NN-powered engine

Post by Ras »

The Giraffe project is well known, but here is another academic paper that you might quote: https://arxiv.org/abs/1711.09667

This stuff here might also be interesting for a NN implementation: http://leenissen.dk/ This is in C for performance, but you can interface from Python.
Rasmus Althoff
https://www.ct800.net
maelic
Posts: 12
Joined: Wed Jul 05, 2017 12:44 pm
Location: Czech Republic

Re: Building NN-powered engine

Post by maelic »

Thank you all for valuable comments!

I know about Leela and I will definitively take a look at it. I know chess is a very hard task to do but I love the game and it will give me more motivation. I will discuss using python chess and give it a try if allowed.
Best regards,
Miloš
brianr
Posts: 536
Joined: Thu Mar 09, 2006 3:01 pm

Re: Building NN-powered engine

Post by brianr »

I have used both the Deep paper approach and FANN per the links mentioned above. Given your goals I still recommend the Zeta repos as a good starting point to see how things work. Python and Keras are a good combination.

Also, no need to compile Python to .exe to work with GUIs. Most will work with "python" as the command with appropriate parameters to start your whatever_name_engine.py file.

I have been continuing to train a Zeta NN/MCTS chess version (on and off, after various setbacks), and will soon be requesting a pull with new weights that is about 700 elo better than the current best weights file from a few months ago.

BTW, you should have a medium to high-end graphics card. An NVIDIA GPU with CUDA and cuDNN libs is good. Minimally a GTX-1060, better is a 1070 which has 8GB gpu ram (what I have), or even better a 1080 or 1080-ti (best), although newer models are expected quite soon. Your choice on getting a good price for an older (current) card or waiting for the newer ones (more $$$).

Expect to take the better part of a week to train your NN to play reasonably. Consider using supervised learning instead of the pure "zero" approach with only self-play. Generating self-play training games will take far more time/resources than using pgn files. Creating a 2000 elo NN engine should be quite doable.

Finally, most things will still work better under Linux, although Windows support has become much better. Python and Keras can mask that somewhat, but pay close attention to the various versions and GitHub requirements.txt files when installing. Strongly suggest using virtual environments and beware of version churns that break backwards compatibility.
jpqy
Posts: 550
Joined: Thu Apr 24, 2008 9:31 am
Location: Belgium

Re: Building NN-powered engine

Post by jpqy »

A other project you can have a look:

Deep Pepper: Expert Iteration based Chess agent in the Reinforcement Learning Setting

https://arxiv.org/pdf/1806.00683.pdf

https://github.com/saikrishna-1996/deep_pepper_chess

JP.