Skip to main content

A chess library.

Project description

Introduction

This is the scholars mate in python-chess:

pos = chess.Position()
pos.make_move_from_san("e4")
pos.make_move_from_san("e5")
pos.make_move_from_san("Qh5")
pos.make_move_from_san("Nc6")
pos.make_move_from_san("Bc4")
pos.make_move_from_san("Nf6")
pos.make_move_from_san("Qxf7")
assert pos.is_checkmate()

Features

  • Legal move generator and move validation. This includes all castling rules and en-passant captures.

    assert not chess.Move.from_uci("a8a1") in pos.get_legal_moves()
  • Detects checkmates, stalemates and draws by insufficient material. Has a half-move clock.

    assert not pos.is_stalemate()
    assert not pos.is_insufficient_material()
    assert pos.is_game_over()
  • Detects checks and can enumerate attackers and defenders of a square.

    assert pos.is_check()
    assert chess.Square("f7") in pos.get_attackers("w", chess.Square("e8"))
  • Parses and creates SAN representation of moves.

    pos = chess.Position()
    assert "e4" == pos.make_move(chess.Move("e2e4")).san
  • Parses and creates FENs.

    assert pos.fen == "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
    pos = chess.Position("8/8/8/2k5/4K3/8/8/8 w - - 4 45")
    assert pos["c5"] == chess.Piece("k")
  • Read Polyglot opening books.

    book = chess.PolyglotOpeningBook("data/opening-books/performance.bin")
    pos = chess.Position()
    # for entry in book.get_entries_for_position(pos):
    #    assert chess.Move.from_uci("e2e4") == entry["move"]
    #    break

Peformance

python-chess is not intended to be used by chess engines where performance is critical. The goal is rather to create a simple and highlevel library.

However parts like move generation are in C++ (see the libchess directory) to improve the performance over pure Python code.

Building

libboost-regex-dev and libboost-python-dev are required.

python setup.py build
sudo python.setup.py install

License

python-chess is licensed under the GPL3. See the LICENSE file for the full copyright and license information.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-chess-0.0.3.tar.gz (45.9 kB view details)

Uploaded Source

File details

Details for the file python-chess-0.0.3.tar.gz.

File metadata

  • Download URL: python-chess-0.0.3.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-chess-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6a07642d16c37b7cd289323a2b2d48eb167b117e6e7a7c05ff4d21b612ea2e4f
MD5 2ee998167c4b4af45669efe7efb65914
BLAKE2b-256 002a3c0a30cd383bc3bd5d8c551d79d8536f941a641fa17e2837c0aff85fd6c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page