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.
This code is written with readability in mind and is not meant to be fully optimized.
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.
cd /path/to/meatball/
make docker-tests
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 with gcc
and clang
gcovr
can be installed with pip
and brew
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:
./stockfish
.position startpos
and then go 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.test_movegeneration.cpp
, make sure the showDivideOutput
argument in the perft()
calls are set to true
. This will print the divide output to the console.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