16

Is anyone familiar with any open source chess libraries in any language that can do any of the following:

  • parse PGNs and/or FENs
  • calculate valid chess moves based on position
  • process an entire chess game

EDIT:

Sorry, I should be more clear. I'm not looking for open source software, I'm looking for open source programming libraries.

3 Answers 3

9

Stockfish

Stockfish (website and github) is an open source and very strong UCI engine. As such it can do all you are asking for, but usually requires a GUI in order to do so. You can however access all functionality via a command prompt/shell as well.

11

Crafty

Crafty is a strong chess programm and can be used with Winboard, Xboard and Scid. So it is available for all major operating systems.

Scid

Scid can maintain databases of chess games, you can analyse (end) games.The software is available for all major operating systems.

Xboard

Xboard is a user interface to the Internet Chess Server. It uses the X Windows System, so I assume this runs only under GNU/Linux. Xboard can be used as a viewer and supports all forms of chess.

10

PyChess

Is a chess client built in Python. You can use it's chess logic libraries without much trouble.

Are examples of how you you might use the libraries to control chess engines, but you can also use just the chess logic:

from pychess.Utils.Board import Board
from pychess.Utils.lutils.lmove import toSAN
from pychess.Utils.lutils.lmovegen import genAllMoves
board = Board(setup=True).board
for move in genAllMoves (board):
    print (toSAN (board, move)))

It's very fast, since it's used for the built in engine, and it has many advanced features such as parsing long list of SAN moves, generating check evasions and static exchange evaluation (SEE).

3
  • Thanks for sharing, looks very interesting. What does the above do? Could a similar snippet import a pgn file from disk and print all the moves in a similar loop? Does it have libraries to export html? Is there documentation that would help with doing similar kind of scripting?
    – Joe
    Feb 8, 2013 at 18:41
  • And checking out the link, it seems like the actual tool does not run on Windows - yet. Do you think the above code would run on Windows in headless mode though?
    – Joe
    Feb 8, 2013 at 18:43
  • 2
    The above code prints out all possible moves for white in the default position, using Standard Algebraic Notation. Parsing moves is also easy with the same couple of modules. If your project were GPL, I would just copy out the entire lutils module, which is pure Python and doesn't require any Linux specific process handling. Feb 8, 2013 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.