def check_click_collision(self, mouse_rect): old_board = self.board for square, piece in enumerate(self.board_squares): if chess.getPiece(square, self.board) and mouse_rect.colliderect( piece) and self.piece_from is None and chess.getColor( chess.getPiece(square, self.board)) == self.turn: self.piece_from = square self.attacking_squares = chess.isValid(square, self.board) return elif mouse_rect.colliderect( piece) and square in self.attacking_squares: self.piece_to = square self.board = chess.movePiece(self.piece_from, self.piece_to, self.board) self.create_board_pieces() self.attacking_squares = [] self.piece_from = None self.piece_to = None if old_board == self.board: return self.change_turn() return elif mouse_rect.colliderect( piece) and not square in self.attacking_squares: self.attacking_squares = [] self.piece_from = None self.piece_to = None return
def get_pieces(board): pieces = [] for i in range(64): piece = chess.getPiece(i, board) if piece: pieces.append((piece, i)) return pieces
def distance_between_kings(board): king1 = 0 for i in range(64): if chess.isKing(chess.getPiece(i, board)): if king1: x = abs(i % 8 - king1 % 8) y = abs(i // 8 - king1 // 8) value = int(math.sqrt(x**2 + y**2)) return 16 - value else: king1 = i return 16
def add_king(board, possible_moves, letter_number, move, openings): for key in possible_moves: if possible_moves[key]: for mov in possible_moves[key]: if mov == (letter_number[move[-2]] + 8 * (int(move[-1]) - 1)) and chess.isKing( chess.getPiece(key, board)): try: openings[board].append((key, mov)) except: openings[board] = [] openings[board].append((key, mov)) return chess.movePiece(key, mov, board), openings