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:
% python setup.py install
or
% python setup.py install --home=mypath
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
% 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.
% 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).