def discovered_attack(puzzle: Puzzle) -> bool: if discovered_check(puzzle): return True for node in puzzle.mainline[1::2][1:]: if util.is_capture(node): between = SquareSet.between(node.move.from_square, node.move.to_square) assert isinstance(node.parent, ChildNode) if node.parent.move.to_square == node.move.to_square: return False prev = node.parent.parent assert isinstance(prev, ChildNode) if (prev.move.from_square in between and node.move.to_square != prev.move.to_square and node.move.from_square != prev.move.to_square and not util.is_castling(prev)): return True return False
def castling(puzzle: Puzzle) -> bool: for node in puzzle.mainline[1::2]: if util.is_castling(node): return True return False