This is a hobbyist's attempt at machine learning by creating a chess engine in C++.
Consider reading the wiki for more information on the theory behind some of the engine's components.
- Board Representation
- Move Generation
- Search
- Evaluation
This code is written with readability in mind and is not meant to be fully optimized.
- C++17 (minimum)
Clone the directory and build the executable
git clone https://github.com/hgducharme/meatball.git
cd meatball/
make meatball
If successful, you should see the executable /bin/meatball
.
Run make help
for more information about what targets can be ran.
- Make sure the docker daemon is already running (see: starting docker daemon)
- Run the test suite
cd /path/to/meatball/
make docker-tests
- googletest 1.13.0
- cmake for building googletest
To install googletest-1.13.0
:
cd /tmp
wget https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz
tar xf v1.13.0.tar.gz
cd googletest-1.13.0
mkdir install
cd install
cmake ..
make
make install
cd ../../
rm -rf googletest-1.13.0 && v1.13.0.tar.gz
Next, edit the GOOGLETEST
variable inside meatball/Makefile
to point to where googletest
was installed. Replace /usr/local/lib
with the directory that houses your libgtest.a
and libgtest_main.a
files.
GOOGLETEST := -L/usr/local/lib -lgtest -lgtest_main
Build and run the tests:
make tests
./bin/tests
To build and run only the unit tests:
make unit_tests
./bin/unit_tests
To build (and run) only the inegration tests:
make integration_tests
./bin/integration_tests
This only works locally. Make sure you have gcov
and gcovr
installed on your system:
gcov
is included withgcc
andclang
gcovr
can be installed withpip
andbrew
make coverage
The test_coverage/
directory will contain .gcov
files generated by gcov
and html files generated by gcovr
.
To see the HTML coverage report just open the file meatball/test_coverage/html/coverage.html
in your browser.
It can be difficult to know where to start debugging the move generation when a test case fails because the number of calculated nodes don't match up with the expected number of nodes. To achieve a more specific error output we can do a perft divide. For each top level move, the perft divide function will show the number of child nodes. So in order to debug move generation in a practical way, the following steps are recommended:
- Go to your stockfish repo and make sure the executable has been built.
- Start the executable
./stockfish
. - Run the commands in the shell:
position startpos
and thengo perft [depth]
. You should see the number of nodes that fall under each top level move. You can recurse down the tree to get more and more precise results. - In
test_movegeneration.cpp
, make sure theshowDivideOutput
argument in theperft()
calls are set totrue
. This will print the divide output to the console. - Compare the results.
If you have docker installed then you can do any of the following things within a docker container.
NOTE: The docker daemon must be already running
- Build the source code (
BUILD_FLAGS
is optional)
make docker-build BUILD_FLAGS="CXX=g++ DEBUG_LEVEL=0 OPTIMIZATION_LEVEL=3"
- Run a linter
make docker-linter
- Run the test suite
make docker-tests