ChessPy
A while ago I wrote a chess module for Python. Now this is not a chess-playing module, rather it parses chess moves, stores board positions and works out legal moves. It can also read and write PGN files. I can fairly confidently declare myself as an expert in this kind of thing, having written the PC chess game Chess Commander.
Chess is something that is very well defined, the rules are laid out in black and white, but there are enough juicy problems and gotchas to make it interesting to work on. It was the special case moves such as en passant and castling that were most tricky. I made extensive use of Python's generators extensively which did simplify things a great deal.
There was already a python chess module in existence, by Eric Max Francis, but this version supports stalemate / draw rules and FEN output. It was originally written just for the hell of it, but I have since decided to dust it off and use it to create an AJAX chess website - which is why I present it here for feedback.
I'd be interested in help with optimization. It was designed to be flexible (ie possibly support chess variations) and speed was a secondary considerations. But if my AJAX chess site is successful it could be doing a lot of processing, so any tips would be appreciated! Although they may be moot since Psyco gives a significant speed boost.
Download Python Chess Module
While I can't offer any development help I am currently looking for exactly what you've proposed: an AJAX chess application. Everything that is similar on sourceforge is dead or just junk.
PS. The ChessPy you've developed; what licensing terms are you releasing it under?
I'm afraid I've only just begun the AJAX chess project, and I'll be working on it in my spare time. So it may be a while before a release.
For non-commercial use it is free in return for a credit. I'm not sure about commerical use yet, but I may end up just releasing it on some liberal open source license. I'll need to give it some thought!
Hi Will,
Thanks for writing the module. I am willing to help development of the module. I wrote a full PGN parser and database program in the past, so I can extend the module so that it can handle variations as well. Just let me know if you are interested.
How's work on the AJAX chess website? There is a site, www.lutanho.net, that contains a javascript chess library. Maybe you could use that as well. I am planning on including it on the website of my chessclub, so that people can setup chess diagrams through the web.
Regards,
Hans
Hi Hans,
Please do extend it as you see fit. I don't have time to do much work on it, but any improvements will be gratefully received! I deliberately made provision for exotics flavors of chess - the board width and height are parameters and not hard coded as 8 - so hopefuly it wont be too painful to adapt. Not sure how well I stuck to that through the entire module though.
I'm afraid I've abandoned the AJAX chess idea. Just for lack of time, but I may pick it up again at some point in the future...
Email me if you need more information - my email address is in the About page.
Regards,
Will
Hi Will,
Okay thanks.
I have already started adding support for variations and moving though them. Is it okay to release the whole of the module under an Open Source license?
Hans
I used your python chess module to make a small chessbot for fun. It was very helpful, but there are a couple of errors I've found in the is_check() method (line 1246).
1) lines 1259-1265 (testing if Knights put the King in check) do not work. I don't know what you were trying to accomplish with the code you had written so I changed it to:
2) The method does not test if the enemy king can attack the current side's king. This leads to a bug in which the white King (for example) can take a pawn being protected by the black King, leaving the two Kings adjacent which is (of course) illegal.
Once again, thanks for writing this code. It has been very helpful to me.
Not elegant by any means, but it seems to have done the trick.
Any ideas on how should I adjust your module to suit my needs?
There's no functionality for that, but you could certainly build upon ChessPy…
Will
Hi, It seems that the download link does not work.
Is there any other place from where I can download it?
Thanks