Play Chess with the Raspberry Pi

You could be an ardent chess player searching for a worthy opponent. A human opponent may not always be conveniently present, but a computerized player can be relied upon to be available at any time of your choosing. With the Single Board Computer, the Raspberry Pi, or RBPi, you can now play a complicated game of chess, provided you are willing to build a chessboard first.

You will need an Arduino to control the chessboard and an RBPi to run the actual chess engine Stockfish, along with Chessboard, which is the chess rules library. The entire arrangement is completely automated – plug in the different parts, press the green button and you start playing. If there is no automated arm, you must move the pieces manually and the computer signals its move by flashing LEDs. You get 21 levels of play along with the ability to set the personality of the computer – coward or aggressive.

Apart from the personality setting and the 21 levels, Stockfish allows several features. Choose to play with black or with white pieces, and play against the computer or another human. Along with providing hints if stuck, Stockfish recognizes and makes special moves such as Castling, En Passent, and Pawn Promotion. It validates all moves against all rules of chess, signaling errors and allowing re-moves. The chess engine has a maximum rating of GM and an ELO level of 2900.

Although you can use the RBPi alone to control the board and play the chess engine, using an Arduino relieves the RBPi of many functions, speeding up the chess engine running on it. Since the Arduino does not use an Operating System, it is not possible to run Stockfish on it. Although there are chess programs to run on the Arduino, none is as strong as the Stockfish. Moreover, if you are using a computerized arm, the Arduino can take care of operating the motors. The combination of RBPi and Arduino for the chessboard works efficiently.

You can make the board out of wood or plastic according to the materials readily available. A chessboard has 64 squares with alternate black and white colors. To sense the pieces, you need reed switches under each square. These will be wired in the form of a matrix with eight rows and eight columns, with a single reed-switch straddling each junction. By numbering the rows as 1-8 and the columns as A-H, a command E2E4 tells the computer to move the piece from the E2 square to the E4 square.

To let the computer signal its move with LEDs, you will need a second matrix similar to that of the reed switches. Only this time, instead of reed switches, you must place LEDs at the junction points. Using sockets for both the reed switches and the LEDs is advisable as it becomes easy for maintenance. Unlike reed switches, LEDs are polarized, and need to be properly oriented to function. Placing them in sockets helps to re-orient them if they are inserted the wrong way. The Arduino controls both the matrices with data from the RBPi.