The rules of chess say that for castling it is imperative that for the king and rook it was the first move. Calculating only one position of a piece to establish exact rules is possible if castling is not enough, you need to at least make a move counter. The display of the figures I have is as follows: I cycle through a two-dimensional array and if we find a match then draw a sprite:
for y in board: for x in y: if x == 'leftRook' or x == 'rightRook': black_rook() If the first move is with the King and respectively the first with leftRook or rightRook, then we return True. However, is it possible to avoid such redefinition in the names and leave only Rook, that is, from this:
board = ['leftRook', ' ', ' ', ' ', 'King ', ' ', ' ', 'rightRook'] this:
board = ['Rook', ' ', ' ', ' ', 'King', ' ', ' ', 'Rook'] However, in this case, consider the move, because the name is the same, the class is one, and even if you define the parameter "first_move" and transfer it to __init__ along with the values of "x", "y", then such a construction will work only on one of rooks and once, because the names are the same. How to count for each rook its moves separately in the case when the left and right rooks have the same name?
class Figure(object): def __init__(self, x, y): self.x = x self.y = y class black_rook(Figure): "" правила хода "" class white_rook(Figure): "" правила хода ""
None. When moving an object (including castling), we simply write this object in a new place, and in the old one writeNone. A new object is not created. - insolor