PChess/CGIskak

About

PChess is a chess engine, which I originally wrote as part of my MSc thesis. The engine performs "brute force" search, with a minimum of chess specific knowledge to speed up the search. The search is extended iteratively until a certain depth is reached and/or a certain number of positions have been investigated.

The engine respects the usual termination rules:
  1. Check mate
  2. Stale mate (draw)
  3. Draw by three times repetition
  4. Draw by the 50 move rule

Requirements

Download

The software is released under an open source license (MIT)
Here is a zip archive (50kb)

Installation

Unpack the zip archive, and install the module using the distutils script in the top-level dir:
        
   % python setup.py install
      
or

        
   % python setup.py install --home=mypath
      

Running the engine

PChess is a chess engine - it implements the search component in a chess game, but does not come with a polished user interface in the form of a GUI. The engine can be used in different configurations:
  1. Autoplay in a terminal window
  2. interactive HTML interface through a web browser
  3. network turnaments

Autoplay from a terminal window

PChess.py is the script which implements the API for controlling the engine. If the script is started as a main -- rather than being imported into another script -- it will enter an "autoplay" mode - with character output to stdout:

        
    % python PChess.py
    8 rnbqkbnr
    7 pppppppp
    6 ........
    5 ........
    4 ........
    3 .P......
    2 P.PPPPPP
    1 RNBQKBNR
      ABCDEFGH
    0 white Move: B2 B3 Value: 101 #searched: 195360 / 195360 / 500413 nodes/s; depth: 5

    8 rnbqkbnr
    7 pp.ppppp
    6 ..p.....
    5 ........
    4 ........
    3 .P......
    2 P.PPPPPP
    1 RNBQKBNR
      ABCDEFGH
    1 black Move: C7 C6 Value: -95 #searched: 135963 / 331323 / 443556 nodes/s; depth: 5
    
      

Interactive HTML interface (AJAX)

Alternatively, the cgi script cgiskak.py - based on PChess.py - allows interactive play through a normal web browser. The application requires cookies, Javascript and makes use of XmlHttpRequest() calls for getting updates from the server. cgiskak.py has to run on a web server -
like this. If you don't already have a running webserver, you can setup one up:
        
   % python SimpleHTTPChessServer.py
   Serving HTTP on 0.0.0.0 port 8000 ...
    
      
SimpleHTTPChessServer.py functions as a normal web server, except that the engine is preloaded - which in principle makes the game more CPU efficient, since the normal CGI overhead is bypassed.

Network tournaments

Finally the ClientServerChess.py script can be used used for playing chess tournaments over a TCP socket connection. First the server is launched:
        
   % python ClientServerChess.py --server --port 50001
   initialising Chess Server
   ServerSocket: listening at 50001
    
      
And then a client can be connected - here the client plays three games with the server; the client plays white.
        
   % python ClientServerChess.py -client -white -p50001 -n 3
      
The server terminal window summarises the tournament status:
        
   Connection from: 127.0.0.1 45082
   1 black Move: E7 E5 Value: 0 #searched: 0 / 0 / 0 nodes/s Depth: 0
   3 black Move: D7 D6 Value: 0 #searched: 0 / 0 / 0 nodes/s Depth: 0
   5 black Move: E5 D4 Value: 0 #searched: 0 / 0 / 0 nodes/s Depth: 0
   7 black Move: B8 C6 Value: 120 #searched: 128867 / 128867 / 11528600 nodes/s Depth: 4
   9 black Move: H7 H6 Value: 109 #searched: 154832 / 283699 / 1147806 nodes/s Depth: 4
   ...
   Tournament Status Status:
   3 Black is check mate.
   Total #moves: 155
   White time: 67.094304 sec / 0.865733 sec per move
   Black time: 70.646834 sec / 0.911572 sec per move
   
      
The purpose of the tournament is here to let two engines play against each other (benchmarking).