I am a chess player and I like to play chess, in order to improve my chess skill recently I have decided to create a chess application which I can play with so I can further improve my chess skill and get ready to face a stronger opponent in a site like lichess. The below chess application will take me around a year to complete and I will show you all the progress from time to time.
This application will use the below tools to develop:-
- Python will be the programming language that needs to develop this application.
- Stockfish chess engine will be needed as the central mind of this application.
- stockfish module will be needed to link to the Stockfish chess engine.
- Pygame will be needed to display the graphic user interface of this chess application.
- I am using windows os to develop this application so it might not work for the user with the other OS.
In this chapter, we will first download the Stockfish chess engine from this site. I am using the 64bit version (Maximally compatible but slow) to suite my laptop. This chess engine alone does not do anything, we will need a stockfish engine wrapper which you can get from this site! There are other modules around that do the same thing but stockfish module appears to be very easy to use.
With the above two tools ready, we can now open up our PyCharm IDE and input the following code.
from stockfish import Stockfish stockfish = Stockfish("E:\StockFish\stockfish_20090216_x64") stockfish.set_position(["e2e4", "e7e6"]) print(stockfish.get_board_visual())
As you can see we first need to import the Stockfish module into our program. Next, we will pass in the path to the Stockfish chess engine as an argument when we create a Stockfish object. Next, we will set the first move for both the Milk and the Chocolate players. Finally, we will print out the chess position on the chessboard accordingly.
The chessboard looks really great but as I have mentioned before I will not use this display but instead will use PyGame to create the chess user interface for this chess application instead.
So there you have it, we have successfully installed the Stockfish module as well as downloaded the Stockfish chess engine.
What next? Next time we will install the PyGame module and show the chess pieces on the chessboard!