Python Chess



Chess for player vs. player, player vs. AI, or AI vs. AI.   Uses Tkinter to get initial game parameters.  Uses Pygame to draw the board and pieces and to get user mouse clicks.  Run with the “-h” option to get full listing of available command line flags.

Python Chess has a Pygame website page, too.


Download the latest version,  Once unzipped, run with your favorite Python interpreter.  Prerequisites are Python and Pygame.  Tested with Python 2.6 and 2.4, Pygame 1.8.1.

Development History

Yes, the final version is 0.7.  I started at 0.1 and incremented from there as I thought of new features.  The project seemed pretty complete (to me) after about v. 0.5 or so.

13 responses

  1. Hello. I was using your source for creating my own board game. While doing that, I cleaned up alot of your source code/removed unneccesary stuff. If you want me to, I could send the cleaned code to you for future reference. :)

    1. Do you have a link to it? I’ll put it up here for reference.

  2. Garry Kasparov, chess grandmaster made famous from his dueling with Deep Blue a decade ago, wrote a fascinating article on chess and computing.

  3. I just found out someone created a homebrew chess game for PSP which uses some of my code. Awesome!

    If anyone else has used Python Chess code in their own projects, I would love to hear about it.

  4. I want to use your program on my
    It is a online chess program ?

    1. No, it is not an online program. You have to download Python Chess, Python, and Pygame for it to work.

  5. Hi, I’m new to python and am struggling to run PythonChess – I have python and pygame, open up idle and attempt open the Main, but it has issues when trying to run the code. I’m probably running into an obvious flaw, but would you mind guiding me in the right direction, if you’re still around.

  6. Apologies for the double post but here is the error it gives: (thing is I don’t know a thing about the syntax of python…)

    Traceback (most recent call last):
    File “C:Documents and”, line 65, in
    from ChessBoard import ChessBoard
    File “C:Documents and”, line 84
    def ConvertToAlgebraicNotation(self,(row,col)):
    SyntaxError: invalid syntax

  7. @Dipz – I think the problem is you can’t run Pygame from Idle. Try running it just from the command line:

    (your python path)python.exe

    Or maybe you have a Python / Pygame version mismatch? Make sure you’re using the 32 bit versions. I’ve just tested it again with Python 2.6.6 and Pygame 1.9.1, both 32 bit versions, on my 64 bit Windows 7 laptop and it seems to work fine.

    Good luck!

    1. To get to the command line in windows, run “cmd.exe”

  8. Hi! I sent you an email to the address listed in the source files. If you can’t access that any more, I’ll forward it to a different email. I’ve added speech recognition to your python chess game. Let me know what you think!

    1. Note, this is only for running your game on a Linux system.

    2. Very cool! I’m glad it was useful for you.

      Here’s a link to Eric’s project and some notes he emailed me:

      I saw your python chess game and thought it would be the perfect first test for my speech application framework.

      Here is my project that I used:

      Sample commands:
      “pawn to e 4” ==> [piece] to [position]
      “e 2 to e 4” ==> [position] to [position]

      Since letters are hard to recognize, I also recognize NATO letters:
      a -> alpha
      b -> beta/bravo
      c -> charlie
      d -> delta
      e -> epsilon/echo
      f -> fox/foxtrot
      h -> hotel/hospital

      “echo 2 to echo 6”
      “horsie to echo 3”, etc…

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: