For graph exploration: frontier collection with configurable pop order, BFS/DFS/random via strategy change.
Maintain a frontier collection; how you pop determines traversal order.
from collections import deque
def explore(start, neighbors, pop_strategy=deque.pop):
"""Explore graph with configurable traversal order.
pop_strategy:
deque.pop -> DFS (depth-first, LIFO)
deque.popleft -> BFS (breadth-first, FIFO)
lambda d: d.pop(random.randrange(len(d))) -> Random
"""
visited = set()
frontier = deque([start])
while frontier:
current = pop_strategy(frontier)
if current in visited:
continue
visited.add(current)
yield current # Process node
for neighbor in neighbors(current):
if neighbor not in visited:
frontier.append(neighbor)
from collections import deque
import random
def random_tree(nodes, neighbors, pop=deque.pop):
"""Build spanning tree with configurable exploration.
Different pop strategies create different tree shapes:
- deque.pop (DFS): long winding paths
- deque.popleft (BFS): short bushy branches
- random pop: mixed/natural looking
"""
tree = set()
nodes = set(nodes)
root = nodes.pop()
frontier = deque([root])
while nodes:
current = pop(frontier)
unvisited = [n for n in neighbors(current) if n in nodes]
if unvisited:
chosen = random.choice(unvisited)
tree.add((current, chosen))
nodes.remove(chosen)
frontier.append(current)
frontier.append(chosen)
return tree
# Generate different maze styles
def dfs_maze(width, height):
"""Long, winding corridors."""
return random_tree(all_cells(width, height), grid_neighbors, deque.pop)
def bfs_maze(width, height):
"""Short, branching paths."""
return random_tree(all_cells(width, height), grid_neighbors, deque.popleft)
def random_maze(width, height):
"""Natural-looking structure."""
def random_pop(d):
i = random.randrange(len(d))
d[i], d[-1] = d[-1], d[i]
return d.pop()
return random_tree(all_cells(width, height), grid_neighbors, random_pop)
npx skills add jimmc414/frontier-based-explore下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer