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.


18 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…

  9. It is showing mousemotion error on python2.7 can you help eradicate it?

    1. This is a pretty old project and I am no longer working on it. I wonder if you are using a newer version of some dependency that is no longer backwards compatible or something? Just a quick guess….


    Hey. I added my own speed recognition script to the code.
    I added a python file, and modified some other code in your files.
    Here’s the content of

    import win32com.client
    # This Python file uses the following encoding: utf-8
    import os, sys
    # coding=utf-8

    def y(n):
    return {
    0: ‘a’,
    1: ‘b’,
    2: ‘c’,
    3: ‘d’,
    4: ‘e’,
    5: ‘f’,
    6: ‘g’,
    7: ‘h’
    return “muy a la derecha o a la izquieda”

    def x(n):
    return {
    0: 8,
    1: 7,
    2: 6,
    3: 5,
    4: 4,
    5: 3,
    6: 2,
    7: 1
    return(“muy arriba o abajo”)

    #.get(x,8) ## 8 is used as default
    #print f(‘a’)
    def coordToText(coor):
    text =””
    if coor[1] == 8:
    text+=” Esta muy arriba o muy abajo”
    ##dasllkda coordenada y no f
    text += str(x(coor[0]))
    text+=” ”
    return text
    def hablar(texto):
    hablador = win32com.client.Dispatch(“SAPI.SpVoice”)
    def pieceColorToText(color): #w(hite) or b(lack)
    return {
    ‘w’: ‘blanco’,
    ‘b’: ‘negro’,
    def pieceTypeToText(piece):
    return {
    ‘R’: ‘Torre’,
    ‘T’: ‘Caballo’,
    ‘B’: ‘Alfil’,
    ‘Q’: ‘Dama’,
    ‘K’: ‘Rey’,
    ‘P’: ‘Peon’

    #Like my doors

    End Of File:;

    I wanna know if I can upload a public fork to github and share here the link

    1. Cool; sure put it up on git if you want.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: