Getting started in position-counting by computer I have quite a bit of programming background, and even game programming background, but have never looked at a real chess engine before.

I recently stumbled on this puzzle-question, which asks for the number of four-piece positions where the next move (whosever it is) will be checkmate. The number has to be somewhere between 400 (the count found by the OP) and 381,225,600 (the total count of four-piece positions), so it ought to be easy to enumerate them all by computer.

I'd like to make a quick program like this:

for white_king_pos in [0, 64):
  for black_king_pos in [0, 64):
    for white_piece_pos in [0, 64):
      for black_piece_pos in [0, 64):
        for white_piece_kind in {Q,B,N,R,P}:
          for black_piece_kind in {Q,B,N,R,P}:
            if next_move_wins_for(black) &amp;&amp; next_move_wins_for(white):
              count = count + 1


What library should I use in order to make writing the next_move_wins_for function as painless as possible?

(My program is so simple that I don't care about the library's choice of programming language. But FWIW, my fluent languages are C++, Python, and C.)

Edited to add: Same question for other ways of accomplishing the goal, e.g. tablebases. :)
You can do that easily in Python.


  https://pypi.python.org/pypi/python-chess



Create a FEN position based on your loops
Make it white to move in the FEN
Use the FEN position to create Board (http://python-chess.readthedocs.io/en/latest/core.html#board)
Use the legal_moves function to generate all possible moves
Use the push function to make the move
Use the is_game_over function to check for checkmate
Use the pop function to undo the move
Go back to push until you have tried all legal moves
Now make it black to move in the FEN and repeat step three


PS: If you want to add tablebase support. There're two ways:


Use API provided from https://syzygy-tables.info/apidoc?fen=4k3/8/8/8/8/8/8/4K3%20w%20-%20-%200%201.
If you prefer to do it locally, download Syzygy files from http://kirill-kryukov.com/chess/tablebases-online. Use chess.syzygy for probing.