def topics():
    return [
        "bfs_dfs",
        "iddfs",
        "befs",
        "astar",
        "minmax",
        "hillclimbing",
        "waterjug",
        "nqueen",
        "🤢"
    ]


def get_text(topic=None):
    data = {

        "bfs_dfs": """# BFS & DFS
from collections import deque

graph = {
    'A': ['B', 'C'],
    'B': ['D', 'E'],
    'C': ['F'],
    'D': [],
    'E': [],
    'F': []
}

def bfs(start):
    visited = []
    queue = deque([start])
    while queue:
        node = queue.popleft()
        if node not in visited:
            visited.append(node)
            queue.extend(graph[node])
    print("BFS:", visited)

def dfs(node, visited=[]):
    if node not in visited:
        visited.append(node)
        for neighbour in graph[node]:
            dfs(neighbour, visited)
    return visited

bfs('A')
print("DFS:", dfs('A'))
""",

        "iddfs": """# IDDFS
def dls(node, goal, depth):
    if depth == 0 and node == goal:
        return True
    if depth > 0:
        for child in graph.get(node, []):
            if dls(child, goal, depth - 1):
                return True
    return False

def iddfs(start, goal, max_depth):
    for depth in range(max_depth):
        if dls(start, goal, depth):
            return True
    return False
""",

        "befs": """# Best First Search
from queue import PriorityQueue

graph = {
    'A': {'B': 4, 'C': 2},
    'B': {'D': 5},
    'C': {'E': 3},
    'D': {},
    'E': {}
}

def best_first(start):
    visited = []
    pq = PriorityQueue()
    pq.put((0, start))

    while not pq.empty():
        cost, node = pq.get()
        if node not in visited:
            visited.append(node)
            for neighbour in graph[node]:
                pq.put((graph[node][neighbour], neighbour))
    print("BeFS:", visited)

best_first('A')
""",

        "astar": """# A* Search
from queue import PriorityQueue

graph = {
    'A': {'B': 1, 'C': 3},
    'B': {'D': 3},
    'C': {'D': 1},
    'D': {}
}

heuristic = {'A': 4, 'B': 2, 'C': 1, 'D': 0}

def astar(start, goal):
    pq = PriorityQueue()
    pq.put((0, start))
    visited = {}

    while not pq.empty():
        cost, node = pq.get()

        if node == goal:
            print("Reached:", node)
            return

        for neighbour in graph[node]:
            total_cost = cost + graph[node][neighbour] + heuristic[neighbour]
            pq.put((total_cost, neighbour))

astar('A', 'D')
""",

        "minmax": """# Minimax Alpha-Beta
def minimax(depth, nodeIndex, maximizingPlayer, values, alpha, beta):
    if depth == 3:
        return values[nodeIndex]

    if maximizingPlayer:
        best = -1000
        for i in range(2):
            val = minimax(depth+1, nodeIndex*2+i, False, values, alpha, beta)
            best = max(best, val)
            alpha = max(alpha, best)
            if beta <= alpha:
                break
        return best
    else:
        best = 1000
        for i in range(2):
            val = minimax(depth+1, nodeIndex*2+i, True, values, alpha, beta)
            best = min(best, val)
            beta = min(beta, best)
            if beta <= alpha:
                break
        return best

values = [3, 5, 6, 9, 1, 2, 0, -1]
print("Optimal value:", minimax(0, 0, True, values, -1000, 1000))
""",

        "hillclimbing": """# Hill Climbing (8 Puzzle simple idea)
def hill_climbing(state):
    print("Initial State:", state)
    print("Goal not guaranteed (local optimum problem)")
""",

        "waterjug": """# Water Jug BFS
from collections import deque

def water_jug(x, y, z):
    visited = set()
    queue = deque([(0,0)])

    while queue:
        a, b = queue.popleft()
        if (a, b) == (z, 0) or (0, b) == (0, z):
            print("Solution:", a, b)
            return

        if (a, b) in visited:
            continue

        visited.add((a, b))

        queue.extend([
            (x, b), (a, y), (0, b), (a, 0),
            (max(0, a-(y-b)), min(y, b+a)),
            (min(x, a+b), max(0, b-(x-a)))
        ])

water_jug(4, 3, 2)
""",

        "nqueen": """# N Queen (Backtracking)
def is_safe(board, row, col, n):
    for i in range(col):
        if board[row][i] == 1:
            return False
    return True

def solve(board, col, n):
    if col >= n:
        return True

    for i in range(n):
        if is_safe(board, i, col, n):
            board[i][col] = 1
            if solve(board, col+1, n):
                return True
            board[i][col] = 0
    return False

n = 4
board = [[0]*n for _ in range(n)]
solve(board, 0, n)

for row in board:
    print(row)
"""
    }

    if topic is None:
        return "Use aiprac.topics()"

    return data.get(topic.lower(), "Topic not found")