niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.4k stars 522 forks source link

squares between two given squares #576

Closed bautoff closed 4 years ago

bautoff commented 4 years ago

Is there a way to find all squares between two given squares on the diagonal/file/rank? E.g. there are [c3, d3, f3] between b3 and g3; [d4, c5] between e3 and b6 etc.

niklasf commented 4 years ago
>>> import chess
>>> chess.between(chess.B3, chess.G3) # bitboard
3932160
>>> print(chess.SquareSet(chess.between(chess.B3, chess.G3)))
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . 1 1 1 1 . .
. . . . . . . .
. . . . . . . .

So far this feature isn't documented anywhere. Will do.

bautoff commented 4 years ago

Thank you! I think it would be very useful if you also wrapped this feature into a separate function.