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
import chess
board =chess.Board()
cfile = 3 #file is the A in A1 (0-7) to be done with buttons later
rank = 1 #rank is the 1 in A1 (0-7)
print(board) #print ascii version of current board state
spot = chess.square(cfile, rank)
legalMoves = (list(board.generate_legal_moves(chess.square(cfile,rank))))
print(chess.square_name(spot)) #converts from file and rank to name like A1 B5
print("has legal moves")
print(legalMoves)
It gives an output like
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R
d2
has legal moves
[Move.from_uci('b1c3'), Move.from_uci('b1a3')]
It is giving me moves from b1 but giving the proper square d2 this happens with other squares as well. Its probally a simple fix but I have been stuck on this for hours
generate_legal_moves(from_mask=...) takes a bitboard (i.e. a set of squares), not a single square. generate_legal_moves(from_mask=chess.BB_SQUARE[spot]) should work.
Hello I am having trouble with the following code
It gives an output like
It is giving me moves from b1 but giving the proper square d2 this happens with other squares as well. Its probally a simple fix but I have been stuck on this for hours
Thanks