In this project, we build a parallel chess engine using OpenMP and run experiments to explain the speed of the algorithms compared to their sequential counterpart. This program is made as part of the Multicore Processors class in NYU.
This chess engine is built upon the StockDory chess system. We only used the chessboard logic, so we replaced the original repository's engine and evaluation function to implement our own.
- Download the repository onto your local computer and unzip. Rename the folder to MulticoreChess (to be consistent with our commands below - if using the default name 'MulticoreChess-master', you will need to replace the commands below with MulticoreChess-master rather than MulticoreChess). This renaming has been already done in our submission.
- scp the folder to the Crunchy machines.
- cd into the folder with cd:
cd MulticoreChess
- Run the following commands
cmake -B Build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -G Ninja
cmake --build Build --config Release
- To run the program:
./Build/MulticoreChess <depth of search>
Note that the depth of search only applies to testing each function individually. It does not apply to the testing function (choice 8) - The testing function depths are fixed according to how we tested them.
The results are written onto disk with the name "results-mN.txt" where N represents the mate number.
- When you enter the program, there are 8 options avaliable. The first 7 run the algorithms once and the last is the testing function we used. The depth of search entered as a command line argument above only applies to choices 1 to 7. Enter a choice from 1 to 8.
- Then, the program will ask you for a FEN. This is a chess position notation. If you do not have a FEN and want to start from the starting position, enter 0.
- Lastly, enter your thread number for the algorithm. If you've picked a sequential algorithm, this number will do nothing. Otherwise, it will set the number of threads to that value for the parallel algorithms. Note that
omp_set_nested()is not present/commented out, so you will be running the non-nested version of this program by default - this is because the nested version has much more limitations on thread and speed. To try the nested version, this is only in test case 8, which you need to uncomment out theomp_set_nested(1)for it to work and only run it on m1 or m2 with lower threads similar to what we reported in our report.
play-bot.cppis a variation onmain.cppthat allows the user to paste in a new FEN every time after the engine calculates the best move for the previous FEN that was pasted in (it will start with the starting position). This allows the user to simulate playing the bot, which is how we tested the capabilities of our engine and evaluation function against other chess engines as well as humans. Just paste in a new FEN each time, and the bot will calculate what it thinks the best move in that position is, at the depth that you specified.- The program will complain if you paste in a FEN with an en passant target that is not applicable to the current player. For example, pasting in the FEN
rnbqkbnr/ppp2ppp/4p3/3p4/P7/2P5/1P1PPPPP/RNBQKBNR w KQkq d6 0 3does not work because white has no pawn that can actually take the pawn that moved to d5 on d6. This is mainly relevant if you are pasting FENs from Chess.com. Just replace the en passant target with a-and the FEN will work perfectly.(rnbqkbnr/ppp2ppp/4p3/3p4/P7/2P5/1P1PPPPP/RNBQKBNR w KQkq - 0 3)
- The program will complain if you paste in a FEN with an en passant target that is not applicable to the current player. For example, pasting in the FEN
m4.cppcalculates mate in 4 FENs. This was made a separate file because due to the amount of time it would take to run all of the algorithms 20 times for all of the FENs. Therefore, the number of times each FEN is tested with each specific algorithm has been lowered from 20 to 5. Despite this, it still took too long to run for us to add to the report. Naive parallel minimax being extremely slow may be partly to blame. You can run this at your own leisure.
Note that there are some extra commented out test cases at the bottom. These are either:
- The same code as the normal tests, but removes argc and argv to run locally
- The test cases for finding critical section entries and moves evaluated in YBWC and PVS
These are for the user to use for their own volition.
Note that we also commented out the mate in 2 fens and mate in 1 fens since running these all in one chunk would take a long time. To test the other FENs, uncomment them.