Monday, October 12, 2020

IslandT: Beginning steps to create a Stockfish chess application

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:-

  1. Python will be the programming language that needs to develop this application.
  2. Stockfish chess engine will be needed as the central mind of this application.
  3. stockfish module will be needed to link to the Stockfish chess engine.
  4. Pygame will be needed to display the graphic user interface of this chess application.
  5. 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.

altThe position on the chess board

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!



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...