Moving steadily along with Python Chess. Although it now looks completely different, the underlying game mechanics are the same. I used Pygame to do the graphics and user input via the mouse. I’m pleased with Pygame; it made importing and displaying images pretty easy. Most of the questions I had while coding were answered through the documentation on the Pygame website. Also on the Pygame website are a ton of examples of games (etc) people have made that you can look at to get an idea of how to do things. (I may put Python Chess up there when it’s finished.)
I spent about as much time getting the text on the right side of the chess board (“ScrollingTextBox”) working as I did getting the chess board to display right. The ScrollingTextBox uses Pygame to render fonts. It keeps track of how much info is in the window and bumps everything up when needed. It was more trouble to code than it’s worth…about half-way through, I figured there is probably an easier solution out there, but I kept on going and got it to work anyway.
A few things remain to do:
- Replace the current, rather simple, chess piece graphics with better looking images. (From the screenshot, it looks like the piece graphics might be rendered text, but they are actually imported .png files. I used Paint.NET to create 50×50 pixel transparent squares and added the appropriate text in the right color, then saved the files. Pygame imports the files and displays them as images.)
- Replace/add more options to the AI. The current AI is dumb. Really dumb. It just picks a random piece of its own color and moves it to a random (legal) space. (If you can’t beat it, then you probably don’t know anything about chess!) I think it would be interesting to implement a few different chess AI routines, then pit AI vs. AI over a set number of randomized trials (“Monte Carlo simulation”) and see some results – win %, number of turns taken, etc.
- Tkinter! I don’t have anything in the “GetGameSetupParams” function in the ChessGUI_pygame class. I’m thinking of branching out even further with this project and trying to use Tkinter to create a window for the user(s) to enter their name and select black/white, human/AI. I’m sure there is something like my scrolling text box already in Tkinter, too. I’ll probably try to turn this into a Tkinter project next.