Is it possible to get a piece location by its name and color? #1069
-
Hello @niklasf and community, I want to know if there is a built-in function to get the location in (x, y) format of a given piece name and color. Use-case, I've tackled the en-passent and both side castling cases for the normal chess variant but the real problem arises with the chess960 variant. How, am I going to get the position of the rooks and King? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
import chess
board = chess.Board()
for sq in board.pieces(chess.ROOK, chess.WHITE):
print(chess.square_name(sq), chess.square_file(sq), 7 - chess.square_rank(sq)) Would print:
|
Beta Was this translation helpful? Give feedback.
Would print:
7 - chess.square_rank(sq)
because ranks increase as you go up the board, whereas the coordinates you mention in your question are flipped.