Files
timmy-config/training-data/code-patterns-evennia-&-tower.jsonl

1001 lines
800 KiB
Plaintext
Raw Normal View History

{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 0\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0000"}
{"problem": "Implement a function that manage multiple user sessions in a thread-safe session manager. with full docstrings.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0001"}
{"problem": "Create a class which create a Tower floor dataclass that groups rooms by theme. and expose it as a command.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0002"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0003"}
{"problem": "Design a Tower component to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with type hints.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0004"}
{"problem": "How would you evennia event dict when a player joins the game, including account and character names. that persists to JSON.", "solution": "# Generated variation 5\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0005"}
{"problem": "In an Evennia MUD, how do you evennia command that records a new topic into the current room's Memory Palace index. with lock checks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0006"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player joins the game, including account and character names. that broadcasts to all occupants.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0007"}
{"problem": "Using Evennia's API, create a Tower floor dataclass that groups rooms by theme. supporting async callbacks.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0008"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0009"}
{"problem": "Write Python code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. including error handling.", "solution": "# Generated variation 10\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0010"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0011"}
{"problem": "Create a class which evennia NPC that answers questions by searching a memory palace index. and expose it as a command.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0012"}
{"problem": "Build an Evennia typeclass that nPC that wanders between connected rooms on a timed interval. using dataclasses.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0013"}
{"problem": "Design a Tower component to track a user session in a multi-user bridge with join time and active status. with type hints.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0014"}
{"problem": "How would you evennia NPC that answers questions by searching a memory palace index. that persists to JSON.", "solution": "# Generated variation 15\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0015"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0016"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0017"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0018"}
{"problem": "Construct a spatial-memory system that serialize a TowerMap to JSON for persistence or transmission. with logging.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0019"}
{"problem": "Write Python code to parse room output text from Evennia into structured data (description, exits, contents). including error handling.", "solution": "# Generated variation 20\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0020"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n item = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n item[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n item[\"description\"] += line + \" \"\n elif section == \"exits\":\n item[\"exits\"].append(line)\n elif section == \"contents\":\n item[\"contents\"].append(line)\n return item", "imports": "", "domain": "MUD world", "id": "evennia-tower-0021"}
{"problem": "Create a class which create a room that broadcasts a message to all occupants when a player enters or leaves. and expose it as a command.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0022"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0023"}
{"problem": "Design a Tower component to nPC with a mood state machine that affects its dialogue responses. with type hints.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0024"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 25\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0025"}
{"problem": "In an Evennia MUD, how do you evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with lock checks.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0026"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0027"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0028"}
{"problem": "Construct a spatial-memory system that find all rooms on a specific floor of The Tower. with logging.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0029"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 30\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0030"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0031"}
{"problem": "Create a class which nPC with a mood state machine that affects its dialogue responses. and expose it as a command.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0032"}
{"problem": "Build an Evennia typeclass that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. using dataclasses.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0033"}
{"problem": "Design a Tower component to find all rooms on a specific floor of The Tower. with type hints.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0034"}
{"problem": "How would you create a room that broadcasts a message to all occupants when a player enters or leaves. that persists to JSON.", "solution": "# Generated variation 35\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0035"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0036"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0037"}
{"problem": "Using Evennia's API, nPC with a mood state machine that affects its dialogue responses. supporting async callbacks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0038"}
{"problem": "Construct a spatial-memory system that serialize a TowerMap to JSON for persistence or transmission. with logging.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0039"}
{"problem": "Write Python code to create a Tower floor dataclass that groups rooms by theme. including error handling.", "solution": "# Generated variation 40\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0040"}
{"problem": "Implement a function that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with full docstrings.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0041"}
{"problem": "Create a class which evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. and expose it as a command.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n outputs = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n outputs.append({\"room\": room, \"score\": score, \"topic\": query})\n outputs.sort(key=lambda x: x[\"score\"], reverse=True)\n return outputs[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0042"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0043"}
{"problem": "Design a Tower component to find the shortest path between two Tower rooms by name using BFS. with type hints.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0044"}
{"problem": "How would you evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that persists to JSON.", "solution": "# Generated variation 45\nclass CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n items = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n items.append({\"room\": room, \"score\": score, \"topic\": query})\n items.sort(key=lambda x: x[\"score\"], reverse=True)\n return items[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0045"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0046"}
{"problem": "For The Tower architecture, write code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that broadcasts to all occupants.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0047"}
{"problem": "Using Evennia's API, evennia event dict when a player joins the game, including account and character names. supporting async callbacks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0048"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0049"}
{"problem": "Write Python code to nPC that wanders between connected rooms on a timed interval. including error handling.", "solution": "# Generated variation 50\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0050"}
{"problem": "Implement a function that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with full docstrings.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0051"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0052"}
{"problem": "Build an Evennia typeclass that create a room that broadcasts a message to all occupants when a player enters or leaves. using dataclasses.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0053"}
{"problem": "Design a Tower component to nPC that wanders between connected rooms on a timed interval. with type hints.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0054"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 55\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0055"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0056"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player moves from one room to another. that broadcasts to all occupants.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0057"}
{"problem": "Using Evennia's API, evennia event dict when a player moves from one room to another. supporting async callbacks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0058"}
{"problem": "Construct a spatial-memory system that evennia NPC that answers questions by searching a memory palace index. with logging.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0059"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 60\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0060"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0061"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0062"}
{"problem": "Build an Evennia typeclass that parse room output text from Evennia into structured data (description, exits, contents). using dataclasses.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entity = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entity[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entity[\"description\"] += line + \" \"\n elif section == \"exits\":\n entity[\"exits\"].append(line)\n elif section == \"contents\":\n entity[\"contents\"].append(line)\n return entity", "imports": "", "domain": "MUD world", "id": "evennia-tower-0063"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0064"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 65\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0065"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0066"}
{"problem": "For The Tower architecture, write code to evennia command that records a new topic into the current room's Memory Palace index. that broadcasts to all occupants.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0067"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0068"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0069"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 70\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0070"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0071"}
{"problem": "Create a class which manage multiple user sessions in a thread-safe session manager. and expose it as a command.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0072"}
{"problem": "Build an Evennia typeclass that evennia command that lets players move between rooms by name instead of using exits. using dataclasses.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0073"}
{"problem": "Design a Tower component to create a Tower floor dataclass that groups rooms by theme. with type hints.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0074"}
{"problem": "How would you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that persists to JSON.", "solution": "# Generated variation 75\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0075"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0076"}
{"problem": "For The Tower architecture, write code to create a room that broadcasts a message to all occupants when a player enters or leaves. that broadcasts to all occupants.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0077"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0078"}
{"problem": "Construct a spatial-memory system that parse room output text from Evennia into structured data (description, exits, contents). with logging.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0079"}
{"problem": "Write Python code to evennia NPC that answers questions by searching a memory palace index. including error handling.", "solution": "# Generated variation 80\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0080"}
{"problem": "Implement a function that manage multiple user sessions in a thread-safe session manager. with full docstrings.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0081"}
{"problem": "Create a class which evennia event dict when a player joins the game, including account and character names. and expose it as a command.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0082"}
{"problem": "Build an Evennia typeclass that evennia event dict when a player moves from one room to another. using dataclasses.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0083"}
{"problem": "Design a Tower component to parse room output text from Evennia into structured data (description, exits, contents). with type hints.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entry = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entry[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entry[\"description\"] += line + \" \"\n elif section == \"exits\":\n entry[\"exits\"].append(line)\n elif section == \"contents\":\n entry[\"contents\"].append(line)\n return entry", "imports": "", "domain": "MUD world", "id": "evennia-tower-0084"}
{"problem": "How would you generate a command_executed event dict for tracking player actions in Evennia. that persists to JSON.", "solution": "# Generated variation 85\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0085"}
{"problem": "In an Evennia MUD, how do you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with lock checks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0086"}
{"problem": "For The Tower architecture, write code to track a user session in a multi-user bridge with join time and active status. that broadcasts to all occupants.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0087"}
{"problem": "Using Evennia's API, evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. supporting async callbacks.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0088"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0089"}
{"problem": "Write Python code to generate a command_executed event dict for tracking player actions in Evennia. including error handling.", "solution": "# Generated variation 90\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0090"}
{"problem": "Implement a function that evennia event dict when a player moves from one room to another. with full docstrings.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0091"}
{"problem": "Create a class which evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. and expose it as a command.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0092"}
{"problem": "Build an Evennia typeclass that manage multiple user sessions in a thread-safe session manager. using dataclasses.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0093"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0094"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 95\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0095"}
{"problem": "In an Evennia MUD, how do you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with lock checks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0096"}
{"problem": "For The Tower architecture, write code to serialize a TowerMap to JSON for persistence or transmission. that broadcasts to all occupants.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0097"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0098"}
{"problem": "Construct a spatial-memory system that evennia command that records a new topic into the current room's Memory Palace index. with logging.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0099"}
{"problem": "Write Python code to evennia command that records a new topic into the current room's Memory Palace index. including error handling.", "solution": "# Generated variation 100\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0100"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0101"}
{"problem": "Create a class which strip ANSI escape codes from Evennia terminal output for clean log processing. and expose it as a command.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0102"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0103"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0104"}
{"problem": "How would you evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. that persists to JSON.", "solution": "# Generated variation 105\nclass DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0105"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0106"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player joins the game, including account and character names. that broadcasts to all occupants.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0107"}
{"problem": "Using Evennia's API, find the shortest path between two Tower rooms by name using BFS. supporting async callbacks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0108"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0109"}
{"problem": "Write Python code to evennia event dict when a player joins the game, including account and character names. including error handling.", "solution": "# Generated variation 110\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0110"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0111"}
{"problem": "Create a class which evennia command that records a new topic into the current room's Memory Palace index. and expose it as a command.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0112"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0113"}
{"problem": "Design a Tower component to evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with type hints.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0114"}
{"problem": "How would you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that persists to JSON.", "solution": "# Generated variation 115\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0115"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0116"}
{"problem": "For The Tower architecture, write code to manage multiple user sessions in a thread-safe session manager. that broadcasts to all occupants.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0117"}
{"problem": "Using Evennia's API, evennia command that records a new topic into the current room's Memory Palace index. supporting async callbacks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0118"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0119"}
{"problem": "Write Python code to serialize a TowerMap to JSON for persistence or transmission. including error handling.", "solution": "# Generated variation 120\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0120"}
{"problem": "Implement a function that evennia NPC that answers questions by searching a memory palace index. with full docstrings.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0121"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0122"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0123"}
{"problem": "Design a Tower component to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with type hints.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0124"}
{"problem": "How would you find all rooms on a specific floor of The Tower. that persists to JSON.", "solution": "# Generated variation 125\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0125"}
{"problem": "In an Evennia MUD, how do you evennia command that lets players move between rooms by name instead of using exits. with lock checks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0126"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0127"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0128"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0129"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 130\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0130"}
{"problem": "Implement a function that strip ANSI escape codes from Evennia terminal output for clean log processing. with full docstrings.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0131"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0132"}
{"problem": "Build an Evennia typeclass that track a user session in a multi-user bridge with join time and active status. using dataclasses.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0133"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0134"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 135\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0135"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0136"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player moves from one room to another. that broadcasts to all occupants.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0137"}
{"problem": "Using Evennia's API, build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. supporting async callbacks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0138"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0139"}
{"problem": "Write Python code to find all rooms on a specific floor of The Tower. including error handling.", "solution": "# Generated variation 140\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0140"}
{"problem": "Implement a function that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with full docstrings.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0141"}
{"problem": "Create a class which evennia event dict when a player joins the game, including account and character names. and expose it as a command.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0142"}
{"problem": "Build an Evennia typeclass that parse room output text from Evennia into structured data (description, exits, contents). using dataclasses.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0143"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0144"}
{"problem": "How would you evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. that persists to JSON.", "solution": "# Generated variation 145\nclass DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0145"}
{"problem": "In an Evennia MUD, how do you evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with lock checks.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0146"}
{"problem": "For The Tower architecture, write code to nPC with a mood state machine that affects its dialogue responses. that broadcasts to all occupants.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0147"}
{"problem": "Using Evennia's API, evennia command that lets players move between rooms by name instead of using exits. supporting async callbacks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0148"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0149"}
{"problem": "Write Python code to evennia command that lets players move between rooms by name instead of using exits. including error handling.", "solution": "# Generated variation 150\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0150"}
{"problem": "Implement a function that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with full docstrings.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0151"}
{"problem": "Create a class which create a Tower floor dataclass that groups rooms by theme. and expose it as a command.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0152"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0153"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0154"}
{"problem": "How would you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that persists to JSON.", "solution": "# Generated variation 155\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0155"}
{"problem": "In an Evennia MUD, how do you find the shortest path between two Tower rooms by name using BFS. with lock checks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0156"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0157"}
{"problem": "Using Evennia's API, evennia event dict when a player joins the game, including account and character names. supporting async callbacks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0158"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0159"}
{"problem": "Write Python code to find the shortest path between two Tower rooms by name using BFS. including error handling.", "solution": "# Generated variation 160\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0160"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0161"}
{"problem": "Create a class which evennia NPC that answers questions by searching a memory palace index. and expose it as a command.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0162"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0163"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0164"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 165\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n item = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n item[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n item[\"description\"] += line + \" \"\n elif section == \"exits\":\n item[\"exits\"].append(line)\n elif section == \"contents\":\n item[\"contents\"].append(line)\n return item", "imports": "", "domain": "MUD world", "id": "evennia-tower-0165"}
{"problem": "In an Evennia MUD, how do you track a user session in a multi-user bridge with join time and active status. with lock checks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0166"}
{"problem": "For The Tower architecture, write code to evennia command that lets players move between rooms by name instead of using exits. that broadcasts to all occupants.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0167"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0168"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0169"}
{"problem": "Write Python code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. including error handling.", "solution": "# Generated variation 170\nclass CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0170"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0171"}
{"problem": "Create a class which nPC with a mood state machine that affects its dialogue responses. and expose it as a command.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0172"}
{"problem": "Build an Evennia typeclass that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. using dataclasses.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0173"}
{"problem": "Design a Tower component to evennia command that lets players move between rooms by name instead of using exits. with type hints.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0174"}
{"problem": "How would you evennia event dict when a player joins the game, including account and character names. that persists to JSON.", "solution": "# Generated variation 175\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0175"}
{"problem": "In an Evennia MUD, how do you evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with lock checks.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0176"}
{"problem": "For The Tower architecture, write code to serialize a TowerMap to JSON for persistence or transmission. that broadcasts to all occupants.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0177"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0178"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0179"}
{"problem": "Write Python code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. including error handling.", "solution": "# Generated variation 180\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0180"}
{"problem": "Implement a function that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with full docstrings.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0181"}
{"problem": "Create a class which evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. and expose it as a command.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0182"}
{"problem": "Build an Evennia typeclass that parse room output text from Evennia into structured data (description, exits, contents). using dataclasses.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entity = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entity[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entity[\"description\"] += line + \" \"\n elif section == \"exits\":\n entity[\"exits\"].append(line)\n elif section == \"contents\":\n entity[\"contents\"].append(line)\n return entity", "imports": "", "domain": "MUD world", "id": "evennia-tower-0183"}
{"problem": "Design a Tower component to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with type hints.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0184"}
{"problem": "How would you find all rooms on a specific floor of The Tower. that persists to JSON.", "solution": "# Generated variation 185\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0185"}
{"problem": "In an Evennia MUD, how do you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with lock checks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0186"}
{"problem": "For The Tower architecture, write code to evennia command that records a new topic into the current room's Memory Palace index. that broadcasts to all occupants.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0187"}
{"problem": "Using Evennia's API, nPC that wanders between connected rooms on a timed interval. supporting async callbacks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0188"}
{"problem": "Construct a spatial-memory system that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with logging.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0189"}
{"problem": "Write Python code to evennia command that records a new topic into the current room's Memory Palace index. including error handling.", "solution": "# Generated variation 190\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0190"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0191"}
{"problem": "Create a class which evennia command that records a new topic into the current room's Memory Palace index. and expose it as a command.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0192"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0193"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0194"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 195\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0195"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0196"}
{"problem": "For The Tower architecture, write code to generate a command_executed event dict for tracking player actions in Evennia. that broadcasts to all occupants.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0197"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0198"}
{"problem": "Construct a spatial-memory system that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with logging.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0199"}
{"problem": "Write Python code to nPC with a mood state machine that affects its dialogue responses. including error handling.", "solution": "# Generated variation 200\nclass MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0200"}
{"problem": "Implement a function that track a user session in a multi-user bridge with join time and active status. with full docstrings.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0201"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0202"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0203"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0204"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 205\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0205"}
{"problem": "In an Evennia MUD, how do you nPC with a mood state machine that affects its dialogue responses. with lock checks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0206"}
{"problem": "For The Tower architecture, write code to track a user session in a multi-user bridge with join time and active status. that broadcasts to all occupants.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0207"}
{"problem": "Using Evennia's API, create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. supporting async callbacks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0208"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0209"}
{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 210\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0210"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0211"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0212"}
{"problem": "Build an Evennia typeclass that evennia command that lets players move between rooms by name instead of using exits. using dataclasses.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0213"}
{"problem": "Design a Tower component to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with type hints.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0214"}
{"problem": "How would you strip ANSI escape codes from Evennia terminal output for clean log processing. that persists to JSON.", "solution": "# Generated variation 215\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0215"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player moves from one room to another. with lock checks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0216"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0217"}
{"problem": "Using Evennia's API, generate a command_executed event dict for tracking player actions in Evennia. supporting async callbacks.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0218"}
{"problem": "Construct a spatial-memory system that evennia NPC that answers questions by searching a memory palace index. with logging.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0219"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 220\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0220"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0221"}
{"problem": "Create a class which manage multiple user sessions in a thread-safe session manager. and expose it as a command.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0222"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0223"}
{"problem": "Design a Tower component to track a user session in a multi-user bridge with join time and active status. with type hints.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0224"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 225\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0225"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0226"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0227"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entry = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entry[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entry[\"description\"] += line + \" \"\n elif section == \"exits\":\n entry[\"exits\"].append(line)\n elif section == \"contents\":\n entry[\"contents\"].append(line)\n return entry", "imports": "", "domain": "MUD world", "id": "evennia-tower-0228"}
{"problem": "Construct a spatial-memory system that parse room output text from Evennia into structured data (description, exits, contents). with logging.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0229"}
{"problem": "Write Python code to evennia command that lets players move between rooms by name instead of using exits. including error handling.", "solution": "# Generated variation 230\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0230"}
{"problem": "Implement a function that manage multiple user sessions in a thread-safe session manager. with full docstrings.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0231"}
{"problem": "Create a class which build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. and expose it as a command.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0232"}
{"problem": "Build an Evennia typeclass that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. using dataclasses.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0233"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0234"}
{"problem": "How would you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that persists to JSON.", "solution": "# Generated variation 235\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0235"}
{"problem": "In an Evennia MUD, how do you evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with lock checks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0236"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n item = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n item[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n item[\"description\"] += line + \" \"\n elif section == \"exits\":\n item[\"exits\"].append(line)\n elif section == \"contents\":\n item[\"contents\"].append(line)\n return item", "imports": "", "domain": "MUD world", "id": "evennia-tower-0237"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0238"}
{"problem": "Construct a spatial-memory system that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with logging.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0239"}
{"problem": "Write Python code to serialize a TowerMap to JSON for persistence or transmission. including error handling.", "solution": "# Generated variation 240\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0240"}
{"problem": "Implement a function that strip ANSI escape codes from Evennia terminal output for clean log processing. with full docstrings.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0241"}
{"problem": "Create a class which evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. and expose it as a command.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0242"}
{"problem": "Build an Evennia typeclass that track a user session in a multi-user bridge with join time and active status. using dataclasses.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0243"}
{"problem": "Design a Tower component to create a Tower floor dataclass that groups rooms by theme. with type hints.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0244"}
{"problem": "How would you evennia event dict when a player moves from one room to another. that persists to JSON.", "solution": "# Generated variation 245\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0245"}
{"problem": "In an Evennia MUD, how do you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with lock checks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0246"}
{"problem": "For The Tower architecture, write code to create a room that broadcasts a message to all occupants when a player enters or leaves. that broadcasts to all occupants.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0247"}
{"problem": "Using Evennia's API, evennia NPC that answers questions by searching a memory palace index. supporting async callbacks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0248"}
{"problem": "Construct a spatial-memory system that evennia NPC that answers questions by searching a memory palace index. with logging.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0249"}
{"problem": "Write Python code to nPC that wanders between connected rooms on a timed interval. including error handling.", "solution": "# Generated variation 250\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0250"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0251"}
{"problem": "Create a class which create a Tower floor dataclass that groups rooms by theme. and expose it as a command.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0252"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0253"}
{"problem": "Design a Tower component to track a user session in a multi-user bridge with join time and active status. with type hints.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0254"}
{"problem": "How would you strip ANSI escape codes from Evennia terminal output for clean log processing. that persists to JSON.", "solution": "# Generated variation 255\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0255"}
{"problem": "In an Evennia MUD, how do you find the shortest path between two Tower rooms by name using BFS. with lock checks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0256"}
{"problem": "For The Tower architecture, write code to nPC that wanders between connected rooms on a timed interval. that broadcasts to all occupants.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0257"}
{"problem": "Using Evennia's API, evennia command that records a new topic into the current room's Memory Palace index. supporting async callbacks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0258"}
{"problem": "Construct a spatial-memory system that evennia event dict when a player moves from one room to another. with logging.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0259"}
{"problem": "Write Python code to evennia command that lets players move between rooms by name instead of using exits. including error handling.", "solution": "# Generated variation 260\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0260"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0261"}
{"problem": "Create a class which find the shortest path between two Tower rooms by name using BFS. and expose it as a command.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0262"}
{"problem": "Build an Evennia typeclass that create a Tower floor dataclass that groups rooms by theme. using dataclasses.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0263"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0264"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 265\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0265"}
{"problem": "In an Evennia MUD, how do you evennia command that records a new topic into the current room's Memory Palace index. with lock checks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0266"}
{"problem": "For The Tower architecture, write code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0267"}
{"problem": "Using Evennia's API, build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. supporting async callbacks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0268"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0269"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 270\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0270"}
{"problem": "Implement a function that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with full docstrings.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0271"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0272"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0273"}
{"problem": "Design a Tower component to strip ANSI escape codes from Evennia terminal output for clean log processing. with type hints.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0274"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 275\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0275"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0276"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0277"}
{"problem": "Using Evennia's API, normalize an Evennia bridge event by ensuring all required fields exist with defaults. supporting async callbacks.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0278"}
{"problem": "Construct a spatial-memory system that nPC with a mood state machine that affects its dialogue responses. with logging.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0279"}
{"problem": "Write Python code to find all rooms on a specific floor of The Tower. including error handling.", "solution": "# Generated variation 280\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0280"}
{"problem": "Implement a function that nPC that wanders between connected rooms on a timed interval. with full docstrings.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0281"}
{"problem": "Create a class which evennia NPC that answers questions by searching a memory palace index. and expose it as a command.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0282"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0283"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0284"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 285\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0285"}
{"problem": "In an Evennia MUD, how do you evennia command that lets players move between rooms by name instead of using exits. with lock checks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0286"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0287"}
{"problem": "Using Evennia's API, generate a command_executed event dict for tracking player actions in Evennia. supporting async callbacks.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0288"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0289"}
{"problem": "Write Python code to create a room that broadcasts a message to all occupants when a player enters or leaves. including error handling.", "solution": "# Generated variation 290\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0290"}
{"problem": "Implement a function that find the shortest path between two Tower rooms by name using BFS. with full docstrings.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0291"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0292"}
{"problem": "Build an Evennia typeclass that track a user session in a multi-user bridge with join time and active status. using dataclasses.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0293"}
{"problem": "Design a Tower component to find the shortest path between two Tower rooms by name using BFS. with type hints.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0294"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 295\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0295"}
{"problem": "In an Evennia MUD, how do you nPC that wanders between connected rooms on a timed interval. with lock checks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0296"}
{"problem": "For The Tower architecture, write code to evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. that broadcasts to all occupants.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0297"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0298"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0299"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 300\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0300"}
{"problem": "Implement a function that evennia event dict when a player moves from one room to another. with full docstrings.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0301"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0302"}
{"problem": "Build an Evennia typeclass that nPC that wanders between connected rooms on a timed interval. using dataclasses.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0303"}
{"problem": "Design a Tower component to evennia command that lets players move between rooms by name instead of using exits. with type hints.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0304"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 305\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0305"}
{"problem": "In an Evennia MUD, how do you create a room that broadcasts a message to all occupants when a player enters or leaves. with lock checks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0306"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0307"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0308"}
{"problem": "Construct a spatial-memory system that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with logging.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0309"}
{"problem": "Write Python code to generate a command_executed event dict for tracking player actions in Evennia. including error handling.", "solution": "# Generated variation 310\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0310"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0311"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0312"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0313"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0314"}
{"problem": "How would you manage multiple user sessions in a thread-safe session manager. that persists to JSON.", "solution": "# Generated variation 315\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0315"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0316"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0317"}
{"problem": "Using Evennia's API, build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. supporting async callbacks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0318"}
{"problem": "Construct a spatial-memory system that track a user session in a multi-user bridge with join time and active status. with logging.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0319"}
{"problem": "Write Python code to evennia command that lets players move between rooms by name instead of using exits. including error handling.", "solution": "# Generated variation 320\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0320"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0321"}
{"problem": "Create a class which define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. and expose it as a command.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0322"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0323"}
{"problem": "Design a Tower component to nPC that wanders between connected rooms on a timed interval. with type hints.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0324"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 325\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0325"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player joins the game, including account and character names. with lock checks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0326"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0327"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0328"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0329"}
{"problem": "Write Python code to find the shortest path between two Tower rooms by name using BFS. including error handling.", "solution": "# Generated variation 330\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0330"}
{"problem": "Implement a function that find the shortest path between two Tower rooms by name using BFS. with full docstrings.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0331"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0332"}
{"problem": "Build an Evennia typeclass that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. using dataclasses.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0333"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0334"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 335\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0335"}
{"problem": "In an Evennia MUD, how do you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with lock checks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0336"}
{"problem": "For The Tower architecture, write code to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. that broadcasts to all occupants.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0337"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0338"}
{"problem": "Construct a spatial-memory system that evennia NPC that answers questions by searching a memory palace index. with logging.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0339"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 340\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0340"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0341"}
{"problem": "Create a class which evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. and expose it as a command.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n nodes = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n nodes.append({\"room\": room, \"score\": score, \"topic\": query})\n nodes.sort(key=lambda x: x[\"score\"], reverse=True)\n return nodes[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0342"}
{"problem": "Build an Evennia typeclass that create a Tower floor dataclass that groups rooms by theme. using dataclasses.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0343"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0344"}
{"problem": "How would you evennia NPC that answers questions by searching a memory palace index. that persists to JSON.", "solution": "# Generated variation 345\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0345"}
{"problem": "In an Evennia MUD, how do you evennia command that records a new topic into the current room's Memory Palace index. with lock checks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0346"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0347"}
{"problem": "Using Evennia's API, evennia command that records a new topic into the current room's Memory Palace index. supporting async callbacks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0348"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0349"}
{"problem": "Write Python code to find the shortest path between two Tower rooms by name using BFS. including error handling.", "solution": "# Generated variation 350\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0350"}
{"problem": "Implement a function that evennia NPC that answers questions by searching a memory palace index. with full docstrings.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0351"}
{"problem": "Create a class which create a room that broadcasts a message to all occupants when a player enters or leaves. and expose it as a command.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0352"}
{"problem": "Build an Evennia typeclass that manage multiple user sessions in a thread-safe session manager. using dataclasses.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0353"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0354"}
{"problem": "How would you manage multiple user sessions in a thread-safe session manager. that persists to JSON.", "solution": "# Generated variation 355\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0355"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0356"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0357"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0358"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0359"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 360\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0360"}
{"problem": "Implement a function that find the shortest path between two Tower rooms by name using BFS. with full docstrings.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0361"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0362"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0363"}
{"problem": "Design a Tower component to nPC with a mood state machine that affects its dialogue responses. with type hints.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0364"}
{"problem": "How would you evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. that persists to JSON.", "solution": "# Generated variation 365\nclass MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0365"}
{"problem": "In an Evennia MUD, how do you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with lock checks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0366"}
{"problem": "For The Tower architecture, write code to evennia NPC that answers questions by searching a memory palace index. that broadcasts to all occupants.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0367"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0368"}
{"problem": "Construct a spatial-memory system that evennia event dict when a player joins the game, including account and character names. with logging.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0369"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 370\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0370"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0371"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0372"}
{"problem": "Build an Evennia typeclass that parse room output text from Evennia into structured data (description, exits, contents). using dataclasses.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0373"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0374"}
{"problem": "How would you nPC that wanders between connected rooms on a timed interval. that persists to JSON.", "solution": "# Generated variation 375\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0375"}
{"problem": "In an Evennia MUD, how do you parse room output text from Evennia into structured data (description, exits, contents). with lock checks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0376"}
{"problem": "For The Tower architecture, write code to generate a command_executed event dict for tracking player actions in Evennia. that broadcasts to all occupants.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0377"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0378"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0379"}
{"problem": "Write Python code to evennia event dict when a player joins the game, including account and character names. including error handling.", "solution": "# Generated variation 380\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0380"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n item = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n item[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n item[\"description\"] += line + \" \"\n elif section == \"exits\":\n item[\"exits\"].append(line)\n elif section == \"contents\":\n item[\"contents\"].append(line)\n return item", "imports": "", "domain": "MUD world", "id": "evennia-tower-0381"}
{"problem": "Create a class which nPC with a mood state machine that affects its dialogue responses. and expose it as a command.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0382"}
{"problem": "Build an Evennia typeclass that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. using dataclasses.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0383"}
{"problem": "Design a Tower component to evennia event dict when a player moves from one room to another. with type hints.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0384"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 385\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0385"}
{"problem": "In an Evennia MUD, how do you create a Tower floor dataclass that groups rooms by theme. with lock checks.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0386"}
{"problem": "For The Tower architecture, write code to create a room that broadcasts a message to all occupants when a player enters or leaves. that broadcasts to all occupants.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0387"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0388"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0389"}
{"problem": "Write Python code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. including error handling.", "solution": "# Generated variation 390\nclass CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n nodes = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n nodes.append({\"room\": room, \"score\": score, \"topic\": query})\n nodes.sort(key=lambda x: x[\"score\"], reverse=True)\n return nodes[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0390"}
{"problem": "Implement a function that find the shortest path between two Tower rooms by name using BFS. with full docstrings.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0391"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0392"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0393"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0394"}
{"problem": "How would you create a room that broadcasts a message to all occupants when a player enters or leaves. that persists to JSON.", "solution": "# Generated variation 395\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0395"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player moves from one room to another. with lock checks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0396"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player joins the game, including account and character names. that broadcasts to all occupants.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0397"}
{"problem": "Using Evennia's API, evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. supporting async callbacks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0398"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0399"}
{"problem": "Write Python code to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. including error handling.", "solution": "# Generated variation 400\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0400"}
{"problem": "Implement a function that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with full docstrings.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0401"}
{"problem": "Create a class which nPC that wanders between connected rooms on a timed interval. and expose it as a command.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0402"}
{"problem": "Build an Evennia typeclass that nPC with a mood state machine that affects its dialogue responses. using dataclasses.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0403"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0404"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 405\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0405"}
{"problem": "In an Evennia MUD, how do you track a user session in a multi-user bridge with join time and active status. with lock checks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0406"}
{"problem": "For The Tower architecture, write code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that broadcasts to all occupants.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0407"}
{"problem": "Using Evennia's API, find all rooms on a specific floor of The Tower. supporting async callbacks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0408"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0409"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 410\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0410"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n record = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n record[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n record[\"description\"] += line + \" \"\n elif section == \"exits\":\n record[\"exits\"].append(line)\n elif section == \"contents\":\n record[\"contents\"].append(line)\n return record", "imports": "", "domain": "MUD world", "id": "evennia-tower-0411"}
{"problem": "Create a class which parse a raw Evennia log line into a structured event dict, extracting timestamp and message. and expose it as a command.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0412"}
{"problem": "Build an Evennia typeclass that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. using dataclasses.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0413"}
{"problem": "Design a Tower component to evennia event dict when a player moves from one room to another. with type hints.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0414"}
{"problem": "How would you create a room that broadcasts a message to all occupants when a player enters or leaves. that persists to JSON.", "solution": "# Generated variation 415\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0415"}
{"problem": "In an Evennia MUD, how do you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with lock checks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0416"}
{"problem": "For The Tower architecture, write code to evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. that broadcasts to all occupants.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0417"}
{"problem": "Using Evennia's API, evennia NPC that answers questions by searching a memory palace index. supporting async callbacks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0418"}
{"problem": "Construct a spatial-memory system that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with logging.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0419"}
{"problem": "Write Python code to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. including error handling.", "solution": "# Generated variation 420\nclass MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0420"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0421"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0422"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0423"}
{"problem": "Design a Tower component to find all rooms on a specific floor of The Tower. with type hints.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0424"}
{"problem": "How would you create a room that broadcasts a message to all occupants when a player enters or leaves. that persists to JSON.", "solution": "# Generated variation 425\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0425"}
{"problem": "In an Evennia MUD, how do you create a room that broadcasts a message to all occupants when a player enters or leaves. with lock checks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0426"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0427"}
{"problem": "Using Evennia's API, manage multiple user sessions in a thread-safe session manager. supporting async callbacks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0428"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0429"}
{"problem": "Write Python code to parse room output text from Evennia into structured data (description, exits, contents). including error handling.", "solution": "# Generated variation 430\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0430"}
{"problem": "Implement a function that create a room that broadcasts a message to all occupants when a player enters or leaves. with full docstrings.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0431"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0432"}
{"problem": "Build an Evennia typeclass that evennia event dict when a player joins the game, including account and character names. using dataclasses.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0433"}
{"problem": "Design a Tower component to create a Tower floor dataclass that groups rooms by theme. with type hints.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0434"}
{"problem": "How would you strip ANSI escape codes from Evennia terminal output for clean log processing. that persists to JSON.", "solution": "# Generated variation 435\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0435"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0436"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0437"}
{"problem": "Using Evennia's API, evennia event dict when a player moves from one room to another. supporting async callbacks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0438"}
{"problem": "Construct a spatial-memory system that evennia event dict when a player joins the game, including account and character names. with logging.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0439"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 440\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0440"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0441"}
{"problem": "Create a class which build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. and expose it as a command.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0442"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0443"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0444"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 445\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0445"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0446"}
{"problem": "For The Tower architecture, write code to create a room that broadcasts a message to all occupants when a player enters or leaves. that broadcasts to all occupants.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0447"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0448"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0449"}
{"problem": "Write Python code to find the shortest path between two Tower rooms by name using BFS. including error handling.", "solution": "# Generated variation 450\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0450"}
{"problem": "Implement a function that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with full docstrings.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0451"}
{"problem": "Create a class which create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. and expose it as a command.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0452"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0453"}
{"problem": "Design a Tower component to evennia event dict when a player moves from one room to another. with type hints.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0454"}
{"problem": "How would you serialize a TowerMap to JSON for persistence or transmission. that persists to JSON.", "solution": "# Generated variation 455\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0455"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0456"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0457"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0458"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0459"}
{"problem": "Write Python code to create a Tower floor dataclass that groups rooms by theme. including error handling.", "solution": "# Generated variation 460\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0460"}
{"problem": "Implement a function that generate a command_executed event dict for tracking player actions in Evennia. with full docstrings.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0461"}
{"problem": "Create a class which create a Tower floor dataclass that groups rooms by theme. and expose it as a command.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0462"}
{"problem": "Build an Evennia typeclass that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. using dataclasses.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0463"}
{"problem": "Design a Tower component to find the shortest path between two Tower rooms by name using BFS. with type hints.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0464"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 465\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0465"}
{"problem": "In an Evennia MUD, how do you create a room that broadcasts a message to all occupants when a player enters or leaves. with lock checks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0466"}
{"problem": "For The Tower architecture, write code to manage multiple user sessions in a thread-safe session manager. that broadcasts to all occupants.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0467"}
{"problem": "Using Evennia's API, evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. supporting async callbacks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0468"}
{"problem": "Construct a spatial-memory system that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with logging.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0469"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 470\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0470"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0471"}
{"problem": "Create a class which nPC that wanders between connected rooms on a timed interval. and expose it as a command.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0472"}
{"problem": "Build an Evennia typeclass that nPC that wanders between connected rooms on a timed interval. using dataclasses.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0473"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0474"}
{"problem": "How would you generate a command_executed event dict for tracking player actions in Evennia. that persists to JSON.", "solution": "# Generated variation 475\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0475"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0476"}
{"problem": "For The Tower architecture, write code to serialize a TowerMap to JSON for persistence or transmission. that broadcasts to all occupants.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0477"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0478"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0479"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 480\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0480"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0481"}
{"problem": "Create a class which create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. and expose it as a command.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0482"}
{"problem": "Build an Evennia typeclass that find the shortest path between two Tower rooms by name using BFS. using dataclasses.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0483"}
{"problem": "Design a Tower component to create a room that broadcasts a message to all occupants when a player enters or leaves. with type hints.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0484"}
{"problem": "How would you serialize a TowerMap to JSON for persistence or transmission. that persists to JSON.", "solution": "# Generated variation 485\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0485"}
{"problem": "In an Evennia MUD, how do you track a user session in a multi-user bridge with join time and active status. with lock checks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0486"}
{"problem": "For The Tower architecture, write code to track a user session in a multi-user bridge with join time and active status. that broadcasts to all occupants.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0487"}
{"problem": "Using Evennia's API, find all rooms on a specific floor of The Tower. supporting async callbacks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0488"}
{"problem": "Construct a spatial-memory system that track a user session in a multi-user bridge with join time and active status. with logging.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0489"}
{"problem": "Write Python code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. including error handling.", "solution": "# Generated variation 490\nclass CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0490"}
{"problem": "Implement a function that track a user session in a multi-user bridge with join time and active status. with full docstrings.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0491"}
{"problem": "Create a class which track a user session in a multi-user bridge with join time and active status. and expose it as a command.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0492"}
{"problem": "Build an Evennia typeclass that serialize a TowerMap to JSON for persistence or transmission. using dataclasses.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0493"}
{"problem": "Design a Tower component to evennia NPC that answers questions by searching a memory palace index. with type hints.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0494"}
{"problem": "How would you manage multiple user sessions in a thread-safe session manager. that persists to JSON.", "solution": "# Generated variation 495\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0495"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0496"}
{"problem": "For The Tower architecture, write code to generate a command_executed event dict for tracking player actions in Evennia. that broadcasts to all occupants.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0497"}
{"problem": "Using Evennia's API, evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. supporting async callbacks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n outputs = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n outputs.append({\"room\": room, \"score\": score, \"topic\": query})\n outputs.sort(key=lambda x: x[\"score\"], reverse=True)\n return outputs[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0498"}
{"problem": "Construct a spatial-memory system that nPC that wanders between connected rooms on a timed interval. with logging.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0499"}
{"problem": "Write Python code to evennia NPC that answers questions by searching a memory palace index. including error handling.", "solution": "# Generated variation 500\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0500"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0501"}
{"problem": "Create a class which evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. and expose it as a command.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0502"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0503"}
{"problem": "Design a Tower component to find the shortest path between two Tower rooms by name using BFS. with type hints.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0504"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 505\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0505"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0506"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0507"}
{"problem": "Using Evennia's API, manage multiple user sessions in a thread-safe session manager. supporting async callbacks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0508"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0509"}
{"problem": "Write Python code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. including error handling.", "solution": "# Generated variation 510\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0510"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0511"}
{"problem": "Create a class which evennia event dict when a player joins the game, including account and character names. and expose it as a command.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0512"}
{"problem": "Build an Evennia typeclass that nPC that wanders between connected rooms on a timed interval. using dataclasses.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0513"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0514"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 515\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0515"}
{"problem": "In an Evennia MUD, how do you generate a command_executed event dict for tracking player actions in Evennia. with lock checks.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0516"}
{"problem": "For The Tower architecture, write code to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. that broadcasts to all occupants.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0517"}
{"problem": "Using Evennia's API, manage multiple user sessions in a thread-safe session manager. supporting async callbacks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0518"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0519"}
{"problem": "Write Python code to generate a command_executed event dict for tracking player actions in Evennia. including error handling.", "solution": "# Generated variation 520\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0520"}
{"problem": "Implement a function that evennia command that records a new topic into the current room's Memory Palace index. with full docstrings.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0521"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0522"}
{"problem": "Build an Evennia typeclass that serialize a TowerMap to JSON for persistence or transmission. using dataclasses.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0523"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0524"}
{"problem": "How would you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that persists to JSON.", "solution": "# Generated variation 525\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0525"}
{"problem": "In an Evennia MUD, how do you evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with lock checks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0526"}
{"problem": "For The Tower architecture, write code to generate a command_executed event dict for tracking player actions in Evennia. that broadcasts to all occupants.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0527"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0528"}
{"problem": "Construct a spatial-memory system that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with logging.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0529"}
{"problem": "Write Python code to nPC that wanders between connected rooms on a timed interval. including error handling.", "solution": "# Generated variation 530\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0530"}
{"problem": "Implement a function that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with full docstrings.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n records = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n records.append({\"room\": room, \"score\": score, \"topic\": query})\n records.sort(key=lambda x: x[\"score\"], reverse=True)\n return records[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0531"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0532"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0533"}
{"problem": "Design a Tower component to manage multiple user sessions in a thread-safe session manager. with type hints.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0534"}
{"problem": "How would you strip ANSI escape codes from Evennia terminal output for clean log processing. that persists to JSON.", "solution": "# Generated variation 535\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0535"}
{"problem": "In an Evennia MUD, how do you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with lock checks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0536"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0537"}
{"problem": "Using Evennia's API, evennia command that lets players move between rooms by name instead of using exits. supporting async callbacks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0538"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0539"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 540\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0540"}
{"problem": "Implement a function that nPC with a mood state machine that affects its dialogue responses. with full docstrings.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0541"}
{"problem": "Create a class which evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. and expose it as a command.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0542"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0543"}
{"problem": "Design a Tower component to find all rooms on a specific floor of The Tower. with type hints.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0544"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 545\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0545"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0546"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0547"}
{"problem": "Using Evennia's API, create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. supporting async callbacks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0548"}
{"problem": "Construct a spatial-memory system that create a room that broadcasts a message to all occupants when a player enters or leaves. with logging.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0549"}
{"problem": "Write Python code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. including error handling.", "solution": "# Generated variation 550\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0550"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0551"}
{"problem": "Create a class which strip ANSI escape codes from Evennia terminal output for clean log processing. and expose it as a command.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0552"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0553"}
{"problem": "Design a Tower component to evennia command that lets players move between rooms by name instead of using exits. with type hints.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0554"}
{"problem": "How would you evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. that persists to JSON.", "solution": "# Generated variation 555\nclass MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0555"}
{"problem": "In an Evennia MUD, how do you find the shortest path between two Tower rooms by name using BFS. with lock checks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0556"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player joins the game, including account and character names. that broadcasts to all occupants.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0557"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0558"}
{"problem": "Construct a spatial-memory system that find all rooms on a specific floor of The Tower. with logging.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0559"}
{"problem": "Write Python code to evennia command that lets players move between rooms by name instead of using exits. including error handling.", "solution": "# Generated variation 560\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0560"}
{"problem": "Implement a function that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with full docstrings.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0561"}
{"problem": "Create a class which evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. and expose it as a command.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0562"}
{"problem": "Build an Evennia typeclass that serialize a TowerMap to JSON for persistence or transmission. using dataclasses.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0563"}
{"problem": "Design a Tower component to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with type hints.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n entrys = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n entrys.append({\"room\": room, \"score\": score, \"topic\": query})\n entrys.sort(key=lambda x: x[\"score\"], reverse=True)\n return entrys[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0564"}
{"problem": "How would you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that persists to JSON.", "solution": "# Generated variation 565\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0565"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0566"}
{"problem": "For The Tower architecture, write code to evennia NPC that answers questions by searching a memory palace index. that broadcasts to all occupants.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0567"}
{"problem": "Using Evennia's API, create a Tower floor dataclass that groups rooms by theme. supporting async callbacks.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0568"}
{"problem": "Construct a spatial-memory system that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with logging.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0569"}
{"problem": "Write Python code to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. including error handling.", "solution": "# Generated variation 570\nclass MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0570"}
{"problem": "Implement a function that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with full docstrings.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0571"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0572"}
{"problem": "Build an Evennia typeclass that serialize a TowerMap to JSON for persistence or transmission. using dataclasses.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0573"}
{"problem": "Design a Tower component to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with type hints.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0574"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 575\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0575"}
{"problem": "In an Evennia MUD, how do you evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with lock checks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0576"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0577"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0578"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0579"}
{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 580\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0580"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0581"}
{"problem": "Create a class which evennia NPC that answers questions by searching a memory palace index. and expose it as a command.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0582"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0583"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0584"}
{"problem": "How would you evennia NPC that answers questions by searching a memory palace index. that persists to JSON.", "solution": "# Generated variation 585\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0585"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0586"}
{"problem": "For The Tower architecture, write code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0587"}
{"problem": "Using Evennia's API, nPC with a mood state machine that affects its dialogue responses. supporting async callbacks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0588"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0589"}
{"problem": "Write Python code to manage multiple user sessions in a thread-safe session manager. including error handling.", "solution": "# Generated variation 590\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0590"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0591"}
{"problem": "Create a class which evennia event dict when a player joins the game, including account and character names. and expose it as a command.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0592"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0593"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0594"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 595\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0595"}
{"problem": "In an Evennia MUD, how do you create a Tower floor dataclass that groups rooms by theme. with lock checks.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0596"}
{"problem": "For The Tower architecture, write code to serialize a TowerMap to JSON for persistence or transmission. that broadcasts to all occupants.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0597"}
{"problem": "Using Evennia's API, track a user session in a multi-user bridge with join time and active status. supporting async callbacks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0598"}
{"problem": "Construct a spatial-memory system that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with logging.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0599"}
{"problem": "Write Python code to serialize a TowerMap to JSON for persistence or transmission. including error handling.", "solution": "# Generated variation 600\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0600"}
{"problem": "Implement a function that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with full docstrings.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0601"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0602"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0603"}
{"problem": "Design a Tower component to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with type hints.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0604"}
{"problem": "How would you normalize an Evennia bridge event by ensuring all required fields exist with defaults. that persists to JSON.", "solution": "# Generated variation 605\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0605"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0606"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0607"}
{"problem": "Using Evennia's API, nPC that wanders between connected rooms on a timed interval. supporting async callbacks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0608"}
{"problem": "Construct a spatial-memory system that nPC with a mood state machine that affects its dialogue responses. with logging.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0609"}
{"problem": "Write Python code to generate a command_executed event dict for tracking player actions in Evennia. including error handling.", "solution": "# Generated variation 610\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0610"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0611"}
{"problem": "Create a class which find the shortest path between two Tower rooms by name using BFS. and expose it as a command.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0612"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0613"}
{"problem": "Design a Tower component to track a user session in a multi-user bridge with join time and active status. with type hints.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0614"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 615\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0615"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player joins the game, including account and character names. with lock checks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0616"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0617"}
{"problem": "Using Evennia's API, evennia NPC that answers questions by searching a memory palace index. supporting async callbacks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0618"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0619"}
{"problem": "Write Python code to generate a command_executed event dict for tracking player actions in Evennia. including error handling.", "solution": "# Generated variation 620\ndef command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0620"}
{"problem": "Implement a function that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with full docstrings.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0621"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0622"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0623"}
{"problem": "Design a Tower component to strip ANSI escape codes from Evennia terminal output for clean log processing. with type hints.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0624"}
{"problem": "How would you evennia event dict when a player joins the game, including account and character names. that persists to JSON.", "solution": "# Generated variation 625\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0625"}
{"problem": "In an Evennia MUD, how do you nPC that wanders between connected rooms on a timed interval. with lock checks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0626"}
{"problem": "For The Tower architecture, write code to nPC that wanders between connected rooms on a timed interval. that broadcasts to all occupants.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0627"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0628"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0629"}
{"problem": "Write Python code to find the shortest path between two Tower rooms by name using BFS. including error handling.", "solution": "# Generated variation 630\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0630"}
{"problem": "Implement a function that serialize a TowerMap to JSON for persistence or transmission. with full docstrings.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0631"}
{"problem": "Create a class which manage multiple user sessions in a thread-safe session manager. and expose it as a command.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0632"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0633"}
{"problem": "Design a Tower component to parse room output text from Evennia into structured data (description, exits, contents). with type hints.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0634"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 635\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0635"}
{"problem": "In an Evennia MUD, how do you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with lock checks.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0636"}
{"problem": "For The Tower architecture, write code to create a room that broadcasts a message to all occupants when a player enters or leaves. that broadcasts to all occupants.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0637"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0638"}
{"problem": "Construct a spatial-memory system that parse room output text from Evennia into structured data (description, exits, contents). with logging.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entity = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entity[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entity[\"description\"] += line + \" \"\n elif section == \"exits\":\n entity[\"exits\"].append(line)\n elif section == \"contents\":\n entity[\"contents\"].append(line)\n return entity", "imports": "", "domain": "MUD world", "id": "evennia-tower-0639"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 640\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0640"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0641"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0642"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0643"}
{"problem": "Design a Tower component to strip ANSI escape codes from Evennia terminal output for clean log processing. with type hints.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0644"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 645\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0645"}
{"problem": "In an Evennia MUD, how do you nPC with a mood state machine that affects its dialogue responses. with lock checks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0646"}
{"problem": "For The Tower architecture, write code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0647"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0648"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0649"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 650\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0650"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n record = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n record[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n record[\"description\"] += line + \" \"\n elif section == \"exits\":\n record[\"exits\"].append(line)\n elif section == \"contents\":\n record[\"contents\"].append(line)\n return record", "imports": "", "domain": "MUD world", "id": "evennia-tower-0651"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0652"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0653"}
{"problem": "Design a Tower component to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with type hints.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0654"}
{"problem": "How would you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that persists to JSON.", "solution": "# Generated variation 655\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0655"}
{"problem": "In an Evennia MUD, how do you normalize an Evennia bridge event by ensuring all required fields exist with defaults. with lock checks.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0656"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0657"}
{"problem": "Using Evennia's API, evennia command that lets players move between rooms by name instead of using exits. supporting async callbacks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0658"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0659"}
{"problem": "Write Python code to evennia event dict when a player joins the game, including account and character names. including error handling.", "solution": "# Generated variation 660\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0660"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0661"}
{"problem": "Create a class which build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. and expose it as a command.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0662"}
{"problem": "Build an Evennia typeclass that evennia command that lets players move between rooms by name instead of using exits. using dataclasses.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0663"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0664"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 665\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0665"}
{"problem": "In an Evennia MUD, how do you find the shortest path between two Tower rooms by name using BFS. with lock checks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0666"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0667"}
{"problem": "Using Evennia's API, manage multiple user sessions in a thread-safe session manager. supporting async callbacks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0668"}
{"problem": "Construct a spatial-memory system that strip ANSI escape codes from Evennia terminal output for clean log processing. with logging.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0669"}
{"problem": "Write Python code to manage multiple user sessions in a thread-safe session manager. including error handling.", "solution": "# Generated variation 670\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0670"}
{"problem": "Implement a function that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with full docstrings.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0671"}
{"problem": "Create a class which evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. and expose it as a command.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0672"}
{"problem": "Build an Evennia typeclass that evennia event dict when a player moves from one room to another. using dataclasses.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0673"}
{"problem": "Design a Tower component to create a Tower floor dataclass that groups rooms by theme. with type hints.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0674"}
{"problem": "How would you normalize an Evennia bridge event by ensuring all required fields exist with defaults. that persists to JSON.", "solution": "# Generated variation 675\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0675"}
{"problem": "In an Evennia MUD, how do you nPC with a mood state machine that affects its dialogue responses. with lock checks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0676"}
{"problem": "For The Tower architecture, write code to evennia event dict when a player joins the game, including account and character names. that broadcasts to all occupants.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0677"}
{"problem": "Using Evennia's API, create a room that broadcasts a message to all occupants when a player enters or leaves. supporting async callbacks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0678"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0679"}
{"problem": "Write Python code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. including error handling.", "solution": "# Generated variation 680\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0680"}
{"problem": "Implement a function that track a user session in a multi-user bridge with join time and active status. with full docstrings.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0681"}
{"problem": "Create a class which evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. and expose it as a command.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0682"}
{"problem": "Build an Evennia typeclass that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. using dataclasses.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0683"}
{"problem": "Design a Tower component to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with type hints.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n entrys = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n entrys.append({\"room\": room, \"score\": score, \"topic\": query})\n entrys.sort(key=lambda x: x[\"score\"], reverse=True)\n return entrys[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0684"}
{"problem": "How would you manage multiple user sessions in a thread-safe session manager. that persists to JSON.", "solution": "# Generated variation 685\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0685"}
{"problem": "In an Evennia MUD, how do you parse room output text from Evennia into structured data (description, exits, contents). with lock checks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0686"}
{"problem": "For The Tower architecture, write code to evennia NPC that answers questions by searching a memory palace index. that broadcasts to all occupants.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0687"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0688"}
{"problem": "Construct a spatial-memory system that find all rooms on a specific floor of The Tower. with logging.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0689"}
{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 690\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0690"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0691"}
{"problem": "Create a class which strip ANSI escape codes from Evennia terminal output for clean log processing. and expose it as a command.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0692"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0693"}
{"problem": "Design a Tower component to find all rooms on a specific floor of The Tower. with type hints.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0694"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 695\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0695"}
{"problem": "In an Evennia MUD, how do you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with lock checks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0696"}
{"problem": "For The Tower architecture, write code to track a user session in a multi-user bridge with join time and active status. that broadcasts to all occupants.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0697"}
{"problem": "Using Evennia's API, parse a raw Evennia log line into a structured event dict, extracting timestamp and message. supporting async callbacks.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0698"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0699"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 700\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0700"}
{"problem": "Implement a function that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with full docstrings.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0701"}
{"problem": "Create a class which evennia NPC that answers questions by searching a memory palace index. and expose it as a command.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0702"}
{"problem": "Build an Evennia typeclass that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. using dataclasses.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0703"}
{"problem": "Design a Tower component to nPC with a mood state machine that affects its dialogue responses. with type hints.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0704"}
{"problem": "How would you manage multiple user sessions in a thread-safe session manager. that persists to JSON.", "solution": "# Generated variation 705\nclass SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0705"}
{"problem": "In an Evennia MUD, how do you evennia command that lets players move between rooms by name instead of using exits. with lock checks.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0706"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0707"}
{"problem": "Using Evennia's API, manage multiple user sessions in a thread-safe session manager. supporting async callbacks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0708"}
{"problem": "Construct a spatial-memory system that evennia command that records a new topic into the current room's Memory Palace index. with logging.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0709"}
{"problem": "Write Python code to serialize a TowerMap to JSON for persistence or transmission. including error handling.", "solution": "# Generated variation 710\ndef serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0710"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0711"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0712"}
{"problem": "Build an Evennia typeclass that track a user session in a multi-user bridge with join time and active status. using dataclasses.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0713"}
{"problem": "Design a Tower component to manage multiple user sessions in a thread-safe session manager. with type hints.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0714"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 715\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0715"}
{"problem": "In an Evennia MUD, how do you serialize a TowerMap to JSON for persistence or transmission. with lock checks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0716"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n items = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n items.append({\"room\": room, \"score\": score, \"topic\": query})\n items.sort(key=lambda x: x[\"score\"], reverse=True)\n return items[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0717"}
{"problem": "Using Evennia's API, create a Tower floor dataclass that groups rooms by theme. supporting async callbacks.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0718"}
{"problem": "Construct a spatial-memory system that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with logging.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0719"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 720\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0720"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0721"}
{"problem": "Create a class which create a Tower floor dataclass that groups rooms by theme. and expose it as a command.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0722"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0723"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0724"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 725\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0725"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0726"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0727"}
{"problem": "Using Evennia's API, evennia command that records a new topic into the current room's Memory Palace index. supporting async callbacks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0728"}
{"problem": "Construct a spatial-memory system that evennia command that records a new topic into the current room's Memory Palace index. with logging.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0729"}
{"problem": "Write Python code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. including error handling.", "solution": "# Generated variation 730\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0730"}
{"problem": "Implement a function that find the shortest path between two Tower rooms by name using BFS. with full docstrings.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0731"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0732"}
{"problem": "Build an Evennia typeclass that manage multiple user sessions in a thread-safe session manager. using dataclasses.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0733"}
{"problem": "Design a Tower component to track a user session in a multi-user bridge with join time and active status. with type hints.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0734"}
{"problem": "How would you evennia event dict when a player joins the game, including account and character names. that persists to JSON.", "solution": "# Generated variation 735\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0735"}
{"problem": "In an Evennia MUD, how do you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with lock checks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0736"}
{"problem": "For The Tower architecture, write code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that broadcasts to all occupants.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0737"}
{"problem": "Using Evennia's API, nPC that wanders between connected rooms on a timed interval. supporting async callbacks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0738"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0739"}
{"problem": "Write Python code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. including error handling.", "solution": "# Generated variation 740\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0740"}
{"problem": "Implement a function that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with full docstrings.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0741"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0742"}
{"problem": "Build an Evennia typeclass that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. using dataclasses.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0743"}
{"problem": "Design a Tower component to parse room output text from Evennia into structured data (description, exits, contents). with type hints.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n data = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n data[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n data[\"description\"] += line + \" \"\n elif section == \"exits\":\n data[\"exits\"].append(line)\n elif section == \"contents\":\n data[\"contents\"].append(line)\n return data", "imports": "", "domain": "MUD world", "id": "evennia-tower-0744"}
{"problem": "How would you evennia event dict when a player moves from one room to another. that persists to JSON.", "solution": "# Generated variation 745\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0745"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player moves from one room to another. with lock checks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0746"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0747"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0748"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0749"}
{"problem": "Write Python code to evennia event dict when a player joins the game, including account and character names. including error handling.", "solution": "# Generated variation 750\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0750"}
{"problem": "Implement a function that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with full docstrings.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0751"}
{"problem": "Create a class which evennia command that lets players move between rooms by name instead of using exits. and expose it as a command.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0752"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0753"}
{"problem": "Design a Tower component to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with type hints.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0754"}
{"problem": "How would you parse room output text from Evennia into structured data (description, exits, contents). that persists to JSON.", "solution": "# Generated variation 755\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0755"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player joins the game, including account and character names. with lock checks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0756"}
{"problem": "For The Tower architecture, write code to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0757"}
{"problem": "Using Evennia's API, nPC that wanders between connected rooms on a timed interval. supporting async callbacks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0758"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0759"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 760\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0760"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0761"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0762"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0763"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0764"}
{"problem": "How would you evennia command that records a new topic into the current room's Memory Palace index. that persists to JSON.", "solution": "# Generated variation 765\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0765"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0766"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0767"}
{"problem": "Using Evennia's API, evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. supporting async callbacks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0768"}
{"problem": "Construct a spatial-memory system that find all rooms on a specific floor of The Tower. with logging.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0769"}
{"problem": "Write Python code to find all rooms on a specific floor of The Tower. including error handling.", "solution": "# Generated variation 770\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0770"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0771"}
{"problem": "Create a class which parse room output text from Evennia into structured data (description, exits, contents). and expose it as a command.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0772"}
{"problem": "Build an Evennia typeclass that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. using dataclasses.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0773"}
{"problem": "Design a Tower component to parse room output text from Evennia into structured data (description, exits, contents). with type hints.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n node = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n node[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n node[\"description\"] += line + \" \"\n elif section == \"exits\":\n node[\"exits\"].append(line)\n elif section == \"contents\":\n node[\"contents\"].append(line)\n return node", "imports": "", "domain": "MUD world", "id": "evennia-tower-0774"}
{"problem": "How would you find all rooms on a specific floor of The Tower. that persists to JSON.", "solution": "# Generated variation 775\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0775"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0776"}
{"problem": "For The Tower architecture, write code to create a Tower floor dataclass that groups rooms by theme. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0777"}
{"problem": "Using Evennia's API, evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. supporting async callbacks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0778"}
{"problem": "Construct a spatial-memory system that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with logging.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0779"}
{"problem": "Write Python code to track a user session in a multi-user bridge with join time and active status. including error handling.", "solution": "# Generated variation 780\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0780"}
{"problem": "Implement a function that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with full docstrings.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0781"}
{"problem": "Create a class which create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. and expose it as a command.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0782"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0783"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0784"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 785\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0785"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player joins the game, including account and character names. with lock checks.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0786"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0787"}
{"problem": "Using Evennia's API, normalize an Evennia bridge event by ensuring all required fields exist with defaults. supporting async callbacks.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0788"}
{"problem": "Construct a spatial-memory system that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with logging.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0789"}
{"problem": "Write Python code to evennia NPC that answers questions by searching a memory palace index. including error handling.", "solution": "# Generated variation 790\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0790"}
{"problem": "Implement a function that parse room output text from Evennia into structured data (description, exits, contents). with full docstrings.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0791"}
{"problem": "Create a class which strip ANSI escape codes from Evennia terminal output for clean log processing. and expose it as a command.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0792"}
{"problem": "Build an Evennia typeclass that nPC with a mood state machine that affects its dialogue responses. using dataclasses.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0793"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0794"}
{"problem": "How would you find the shortest path between two Tower rooms by name using BFS. that persists to JSON.", "solution": "# Generated variation 795\nfrom collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0795"}
{"problem": "In an Evennia MUD, how do you create a room that broadcasts a message to all occupants when a player enters or leaves. with lock checks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0796"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0797"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n node = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n node[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n node[\"description\"] += line + \" \"\n elif section == \"exits\":\n node[\"exits\"].append(line)\n elif section == \"contents\":\n node[\"contents\"].append(line)\n return node", "imports": "", "domain": "MUD world", "id": "evennia-tower-0798"}
{"problem": "Construct a spatial-memory system that find the shortest path between two Tower rooms by name using BFS. with logging.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0799"}
{"problem": "Write Python code to find all rooms on a specific floor of The Tower. including error handling.", "solution": "# Generated variation 800\ndef rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0800"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0801"}
{"problem": "Create a class which nPC that wanders between connected rooms on a timed interval. and expose it as a command.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0802"}
{"problem": "Build an Evennia typeclass that normalize an Evennia bridge event by ensuring all required fields exist with defaults. using dataclasses.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0803"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0804"}
{"problem": "How would you evennia event dict when a player moves from one room to another. that persists to JSON.", "solution": "# Generated variation 805\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0805"}
{"problem": "In an Evennia MUD, how do you evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with lock checks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0806"}
{"problem": "For The Tower architecture, write code to nPC that wanders between connected rooms on a timed interval. that broadcasts to all occupants.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0807"}
{"problem": "Using Evennia's API, evennia event dict when a player moves from one room to another. supporting async callbacks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0808"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0809"}
{"problem": "Write Python code to nPC that wanders between connected rooms on a timed interval. including error handling.", "solution": "# Generated variation 810\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0810"}
{"problem": "Implement a function that evennia command that lets players move between rooms by name instead of using exits. with full docstrings.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0811"}
{"problem": "Create a class which create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. and expose it as a command.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0812"}
{"problem": "Build an Evennia typeclass that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. using dataclasses.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0813"}
{"problem": "Design a Tower component to find the shortest path between two Tower rooms by name using BFS. with type hints.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0814"}
{"problem": "How would you normalize an Evennia bridge event by ensuring all required fields exist with defaults. that persists to JSON.", "solution": "# Generated variation 815\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0815"}
{"problem": "In an Evennia MUD, how do you evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with lock checks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n datas = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n datas.append({\"room\": room, \"score\": score, \"topic\": query})\n datas.sort(key=lambda x: x[\"score\"], reverse=True)\n return datas[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0816"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0817"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0818"}
{"problem": "Construct a spatial-memory system that serialize a TowerMap to JSON for persistence or transmission. with logging.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0819"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 820\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0820"}
{"problem": "Implement a function that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with full docstrings.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0821"}
{"problem": "Create a class which find the shortest path between two Tower rooms by name using BFS. and expose it as a command.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0822"}
{"problem": "Build an Evennia typeclass that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. using dataclasses.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0823"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0824"}
{"problem": "How would you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that persists to JSON.", "solution": "# Generated variation 825\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0825"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player moves from one room to another. with lock checks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0826"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0827"}
{"problem": "Using Evennia's API, evennia event dict when a player moves from one room to another. supporting async callbacks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0828"}
{"problem": "Construct a spatial-memory system that parse room output text from Evennia into structured data (description, exits, contents). with logging.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0829"}
{"problem": "Write Python code to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. including error handling.", "solution": "# Generated variation 830\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0830"}
{"problem": "Implement a function that create a room that broadcasts a message to all occupants when a player enters or leaves. with full docstrings.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0831"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0832"}
{"problem": "Build an Evennia typeclass that create a Tower floor dataclass that groups rooms by theme. using dataclasses.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0833"}
{"problem": "Design a Tower component to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with type hints.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0834"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 835\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0835"}
{"problem": "In an Evennia MUD, how do you evennia command that records a new topic into the current room's Memory Palace index. with lock checks.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0836"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n items = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n items.append({\"room\": room, \"score\": score, \"topic\": query})\n items.sort(key=lambda x: x[\"score\"], reverse=True)\n return items[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0837"}
{"problem": "Using Evennia's API, nPC that wanders between connected rooms on a timed interval. supporting async callbacks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0838"}
{"problem": "Construct a spatial-memory system that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with logging.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0839"}
{"problem": "Write Python code to nPC that wanders between connected rooms on a timed interval. including error handling.", "solution": "# Generated variation 840\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0840"}
{"problem": "Implement a function that evennia event dict when a player moves from one room to another. with full docstrings.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0841"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0842"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0843"}
{"problem": "Design a Tower component to evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with type hints.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0844"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 845\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0845"}
{"problem": "In an Evennia MUD, how do you evennia NPC that answers questions by searching a memory palace index. with lock checks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0846"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0847"}
{"problem": "Using Evennia's API, evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. supporting async callbacks.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0848"}
{"problem": "Construct a spatial-memory system that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with logging.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0849"}
{"problem": "Write Python code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. including error handling.", "solution": "# Generated variation 850\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0850"}
{"problem": "Implement a function that evennia room that tracks dynamic state (light level, temperature) and updates its description based on that state. with full docstrings.", "solution": "class DynamicRoom(DefaultRoom):\n \"\"\"A room whose description changes with environmental state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.light_level = 100 # 0-100\n self.db.temperature = 20 # celsius\n self.db.base_desc = \"A plain chamber.\"\n\n def return_appearance(self, looker, **kwargs):\n desc = self.db.base_desc\n light = self.db.light_level\n if light < 20:\n desc += \" It is nearly pitch black.\"\n elif light < 50:\n desc += \" Shadows dance in the dim light.\"\n else:\n desc += \" The room is well lit.\"\n temp = self.db.temperature\n if temp > 30:\n desc += \" Heat shimmers in the air.\"\n elif temp < 10:\n desc += \" Frost coats the walls.\"\n return desc + \"\n\" + super().return_appearance(looker, **kwargs).split(\"\n\", 1)[-1]", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0851"}
{"problem": "Create a class which serialize a TowerMap to JSON for persistence or transmission. and expose it as a command.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0852"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0853"}
{"problem": "Design a Tower component to evennia command that lets players move between rooms by name instead of using exits. with type hints.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0854"}
{"problem": "How would you create a room that broadcasts a message to all occupants when a player enters or leaves. that persists to JSON.", "solution": "# Generated variation 855\nclass BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0855"}
{"problem": "In an Evennia MUD, how do you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with lock checks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0856"}
{"problem": "For The Tower architecture, write code to track a user session in a multi-user bridge with join time and active status. that broadcasts to all occupants.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0857"}
{"problem": "Using Evennia's API, generate a command_executed event dict for tracking player actions in Evennia. supporting async callbacks.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0858"}
{"problem": "Construct a spatial-memory system that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with logging.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0859"}
{"problem": "Write Python code to evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. including error handling.", "solution": "# Generated variation 860\nclass MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0860"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0861"}
{"problem": "Create a class which evennia command that records a new topic into the current room's Memory Palace index. and expose it as a command.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0862"}
{"problem": "Build an Evennia typeclass that find all rooms on a specific floor of The Tower. using dataclasses.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0863"}
{"problem": "Design a Tower component to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with type hints.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0864"}
{"problem": "How would you evennia event dict when a player moves from one room to another. that persists to JSON.", "solution": "# Generated variation 865\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0865"}
{"problem": "In an Evennia MUD, how do you find all rooms on a specific floor of The Tower. with lock checks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0866"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0867"}
{"problem": "Using Evennia's API, evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. supporting async callbacks.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0868"}
{"problem": "Construct a spatial-memory system that evennia command that records a new topic into the current room's Memory Palace index. with logging.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0869"}
{"problem": "Write Python code to nPC with a mood state machine that affects its dialogue responses. including error handling.", "solution": "# Generated variation 870\nclass MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0870"}
{"problem": "Implement a function that define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with full docstrings.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0871"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0872"}
{"problem": "Build an Evennia typeclass that evennia command that records a new topic into the current room's Memory Palace index. using dataclasses.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0873"}
{"problem": "Design a Tower component to parse room output text from Evennia into structured data (description, exits, contents). with type hints.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0874"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 875\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0875"}
{"problem": "In an Evennia MUD, how do you nPC that wanders between connected rooms on a timed interval. with lock checks.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0876"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0877"}
{"problem": "Using Evennia's API, nPC with a mood state machine that affects its dialogue responses. supporting async callbacks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0878"}
{"problem": "Construct a spatial-memory system that create a Tower floor dataclass that groups rooms by theme. with logging.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0879"}
{"problem": "Write Python code to evennia NPC that answers questions by searching a memory palace index. including error handling.", "solution": "# Generated variation 880\nclass StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0880"}
{"problem": "Implement a function that nPC that wanders between connected rooms on a timed interval. with full docstrings.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0881"}
{"problem": "Create a class which generate a command_executed event dict for tracking player actions in Evennia. and expose it as a command.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0882"}
{"problem": "Build an Evennia typeclass that evennia event dict when a player joins the game, including account and character names. using dataclasses.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0883"}
{"problem": "Design a Tower component to evennia command that records a new topic into the current room's Memory Palace index. with type hints.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0884"}
{"problem": "How would you parse a raw Evennia log line into a structured event dict, extracting timestamp and message. that persists to JSON.", "solution": "# Generated variation 885\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0885"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0886"}
{"problem": "For The Tower architecture, write code to evennia NPC that answers questions by searching a memory palace index. that broadcasts to all occupants.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0887"}
{"problem": "Using Evennia's API, evennia NPC that answers questions by searching a memory palace index. supporting async callbacks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0888"}
{"problem": "Construct a spatial-memory system that track a user session in a multi-user bridge with join time and active status. with logging.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0889"}
{"problem": "Write Python code to evennia command that records a new topic into the current room's Memory Palace index. including error handling.", "solution": "# Generated variation 890\nclass CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0890"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0891"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0892"}
{"problem": "Build an Evennia typeclass that create a Tower floor dataclass that groups rooms by theme. using dataclasses.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0893"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0894"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 895\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0895"}
{"problem": "In an Evennia MUD, how do you create a room that broadcasts a message to all occupants when a player enters or leaves. with lock checks.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0896"}
{"problem": "For The Tower architecture, write code to find the shortest path between two Tower rooms by name using BFS. that broadcasts to all occupants.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0897"}
{"problem": "Using Evennia's API, evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. supporting async callbacks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0898"}
{"problem": "Construct a spatial-memory system that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. with logging.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0899"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 900\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0900"}
{"problem": "Implement a function that normalize an Evennia bridge event by ensuring all required fields exist with defaults. with full docstrings.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0901"}
{"problem": "Create a class which track a user session in a multi-user bridge with join time and active status. and expose it as a command.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0902"}
{"problem": "Build an Evennia typeclass that nPC with a mood state machine that affects its dialogue responses. using dataclasses.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0903"}
{"problem": "Design a Tower component to strip ANSI escape codes from Evennia terminal output for clean log processing. with type hints.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0904"}
{"problem": "How would you track a user session in a multi-user bridge with join time and active status. that persists to JSON.", "solution": "# Generated variation 905\nclass UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0905"}
{"problem": "In an Evennia MUD, how do you evennia event dict when a player moves from one room to another. with lock checks.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0906"}
{"problem": "For The Tower architecture, write code to serialize a TowerMap to JSON for persistence or transmission. that broadcasts to all occupants.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0907"}
{"problem": "Using Evennia's API, nPC with a mood state machine that affects its dialogue responses. supporting async callbacks.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0908"}
{"problem": "Construct a spatial-memory system that evennia event dict when a player joins the game, including account and character names. with logging.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0909"}
{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 910\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0910"}
{"problem": "Implement a function that nPC that wanders between connected rooms on a timed interval. with full docstrings.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0911"}
{"problem": "Create a class which evennia event dict when a player moves from one room to another. and expose it as a command.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0912"}
{"problem": "Build an Evennia typeclass that create a room that broadcasts a message to all occupants when a player enters or leaves. using dataclasses.", "solution": "class BroadcastingRoom(DefaultRoom):\n \"\"\"Announces arrivals and departures to all occupants.\"\"\"\n\n def at_object_receive(self, moved_obj, source_location, **kwargs):\n super().at_object_receive(moved_obj, source_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} arrives from {{source_location}}.|n\",\n exclude=moved_obj,\n )\n\n def at_object_leave(self, moved_obj, target_location, **kwargs):\n super().at_object_leave(moved_obj, target_location, **kwargs)\n if moved_obj.has_account:\n self.msg_contents(\n \"|y{{moved_obj.name}} departs to {{target_location}}.|n\",\n exclude=moved_obj,\n )", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0913"}
{"problem": "Design a Tower component to nPC with a mood state machine that affects its dialogue responses. with type hints.", "solution": "class MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0914"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 915\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0915"}
{"problem": "In an Evennia MUD, how do you normalize an Evennia bridge event by ensuring all required fields exist with defaults. with lock checks.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0916"}
{"problem": "For The Tower architecture, write code to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that broadcasts to all occupants.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0917"}
{"problem": "Using Evennia's API, find the shortest path between two Tower rooms by name using BFS. supporting async callbacks.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0918"}
{"problem": "Construct a spatial-memory system that serialize a TowerMap to JSON for persistence or transmission. with logging.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0919"}
{"problem": "Write Python code to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. including error handling.", "solution": "# Generated variation 920\ndef parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0920"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0921"}
{"problem": "Create a class which strip ANSI escape codes from Evennia terminal output for clean log processing. and expose it as a command.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0922"}
{"problem": "Build an Evennia typeclass that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. using dataclasses.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0923"}
{"problem": "Design a Tower component to serialize a TowerMap to JSON for persistence or transmission. with type hints.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0924"}
{"problem": "How would you normalize an Evennia bridge event by ensuring all required fields exist with defaults. that persists to JSON.", "solution": "# Generated variation 925\ndef normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0925"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0926"}
{"problem": "For The Tower architecture, write code to evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. that broadcasts to all occupants.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n entitys = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n entitys.append({\"room\": room, \"score\": score, \"topic\": query})\n entitys.sort(key=lambda x: x[\"score\"], reverse=True)\n return entitys[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0927"}
{"problem": "Using Evennia's API, find all rooms on a specific floor of The Tower. supporting async callbacks.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0928"}
{"problem": "Construct a spatial-memory system that evennia command that records a new topic into the current room's Memory Palace index. with logging.", "solution": "class CmdRecord(Command):\n \"\"\"\n Record a topic into the current room's memory index.\n\n Usage:\n record <topic> = <summary>\n \"\"\"\n key = \"record\"\n locks = \"cmd:all()\"\n\n def func(self):\n if \"=\" not in self.args:\n self.caller.msg(\"Usage: record <topic> = <summary>\")\n return\n topic, summary = self.args.split(\"=\", 1)\n topic = topic.strip()\n summary = summary.strip()\n loc = self.caller.location\n if not loc:\n self.caller.msg(\"You are nowhere.\")\n return\n topics = loc.db.topics or []\n if topic not in topics:\n topics.append(topic)\n loc.db.topics = topics\n palace = loc.db.palace_index or {}\n palace[topic] = {\"summary\": summary, \"author\": self.caller.name}\n loc.db.palace_index = palace\n self.caller.msg(f\"Recorded '{topic}' into {{loc.name}}.\")", "imports": "from evennia import Command", "domain": "spatial memory", "id": "evennia-tower-0929"}
{"problem": "Write Python code to parse room output text from Evennia into structured data (description, exits, contents). including error handling.", "solution": "# Generated variation 930\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n output = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n output[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n output[\"description\"] += line + \" \"\n elif section == \"exits\":\n output[\"exits\"].append(line)\n elif section == \"contents\":\n output[\"contents\"].append(line)\n return output", "imports": "", "domain": "MUD world", "id": "evennia-tower-0930"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0931"}
{"problem": "Create a class which evennia command that lets players move between rooms by name instead of using exits. and expose it as a command.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0932"}
{"problem": "Build an Evennia typeclass that manage multiple user sessions in a thread-safe session manager. using dataclasses.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0933"}
{"problem": "Design a Tower component to define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with type hints.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0934"}
{"problem": "How would you evennia command that lets players move between rooms by name instead of using exits. that persists to JSON.", "solution": "# Generated variation 935\nclass CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0935"}
{"problem": "In an Evennia MUD, how do you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. with lock checks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0936"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0937"}
{"problem": "Using Evennia's API, serialize a TowerMap to JSON for persistence or transmission. supporting async callbacks.", "solution": "def serialize_tower_map(tower_map: TowerMap) -> str:\n return json.dumps(asdict(tower_map), indent=2, default=str)", "imports": "import json\nfrom dataclasses import asdict", "domain": "Tower architecture", "id": "evennia-tower-0938"}
{"problem": "Construct a spatial-memory system that evennia command that lets players move between rooms by name instead of using exits. with logging.", "solution": "class CmdEnterRoom(Command):\n \"\"\"\n Teleport directly to a known room by name.\n\n Usage:\n enter <room name>\n \"\"\"\n key = \"enter\"\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Enter which room?\")\n return\n target_name = self.args.strip().lower()\n matches = [\n r for r in DefaultRoom.objects.all()\n if target_name in r.name.lower()\n ]\n if not matches:\n self.caller.msg(f\"No room matching '{target_name}'.\")\n return\n if len(matches) > 1:\n names = \", \".join(r.name for r in matches[:5])\n self.caller.msg(f\"Be more specific: {{names}}\")\n return\n target = matches[0]\n self.caller.move_to(target)\n self.caller.msg(f\"You enter {{target.name}}.\")", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0939"}
{"problem": "Write Python code to evennia event dict when a player moves from one room to another. including error handling.", "solution": "# Generated variation 940\ndef player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0940"}
{"problem": "Implement a function that generate a command_executed event dict for tracking player actions in Evennia. with full docstrings.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0941"}
{"problem": "Create a class which normalize an Evennia bridge event by ensuring all required fields exist with defaults. and expose it as a command.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0942"}
{"problem": "Build an Evennia typeclass that create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. using dataclasses.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0943"}
{"problem": "Design a Tower component to evennia event dict when a player joins the game, including account and character names. with type hints.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0944"}
{"problem": "How would you define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. that persists to JSON.", "solution": "# Generated variation 945\n@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0945"}
{"problem": "In an Evennia MUD, how do you evennia NPC that answers questions by searching a memory palace index. with lock checks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0946"}
{"problem": "For The Tower architecture, write code to manage multiple user sessions in a thread-safe session manager. that broadcasts to all occupants.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0947"}
{"problem": "Using Evennia's API, parse room output text from Evennia into structured data (description, exits, contents). supporting async callbacks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entry = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entry[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entry[\"description\"] += line + \" \"\n elif section == \"exits\":\n entry[\"exits\"].append(line)\n elif section == \"contents\":\n entry[\"contents\"].append(line)\n return entry", "imports": "", "domain": "MUD world", "id": "evennia-tower-0948"}
{"problem": "Construct a spatial-memory system that parse room output text from Evennia into structured data (description, exits, contents). with logging.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0949"}
{"problem": "Write Python code to parse room output text from Evennia into structured data (description, exits, contents). including error handling.", "solution": "# Generated variation 950\ndef parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0950"}
{"problem": "Implement a function that build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with full docstrings.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0951"}
{"problem": "Create a class which manage multiple user sessions in a thread-safe session manager. and expose it as a command.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0952"}
{"problem": "Build an Evennia typeclass that parse room output text from Evennia into structured data (description, exits, contents). using dataclasses.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0953"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0954"}
{"problem": "How would you create a Tower floor dataclass that groups rooms by theme. that persists to JSON.", "solution": "# Generated variation 955\n@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0955"}
{"problem": "In an Evennia MUD, how do you strip ANSI escape codes from Evennia terminal output for clean log processing. with lock checks.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0956"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0957"}
{"problem": "Using Evennia's API, create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. supporting async callbacks.", "solution": "def room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0958"}
{"problem": "Construct a spatial-memory system that evennia NPC that answers questions by searching a memory palace index. with logging.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0959"}
{"problem": "Write Python code to strip ANSI escape codes from Evennia terminal output for clean log processing. including error handling.", "solution": "# Generated variation 960\ndef strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0960"}
{"problem": "Implement a function that evennia event dict when a player moves from one room to another. with full docstrings.", "solution": "def player_move(character: str, from_room: str, to_room: str, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_move\",\n \"character\": character,\n \"from_room\": from_room,\n \"to_room\": to_room,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0961"}
{"problem": "Create a class which find all rooms on a specific floor of The Tower. and expose it as a command.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0962"}
{"problem": "Build an Evennia typeclass that parse a raw Evennia log line into a structured event dict, extracting timestamp and message. using dataclasses.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0963"}
{"problem": "Design a Tower component to generate a command_executed event dict for tracking player actions in Evennia. with type hints.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0964"}
{"problem": "How would you build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. that persists to JSON.", "solution": "# Generated variation 965\n@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0965"}
{"problem": "In an Evennia MUD, how do you track a user session in a multi-user bridge with join time and active status. with lock checks.", "solution": "class UserSession:\n def __init__(self, user_id: str, connection_id: str):\n self.user_id = user_id\n self.connection_id = connection_id\n self.joined_at = time.time()\n self.last_active = time.time()\n self.active = True\n\n def ping(self):\n self.last_active = time.time()\n\n def is_stale(self, timeout: float = 300.0) -> bool:\n return (time.time() - self.last_active) > timeout", "imports": "import time", "domain": "multi-user bridge", "id": "evennia-tower-0966"}
{"problem": "For The Tower architecture, write code to generate a command_executed event dict for tracking player actions in Evennia. that broadcasts to all occupants.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0967"}
{"problem": "Using Evennia's API, evennia NPC that answers questions by searching a memory palace index. supporting async callbacks.", "solution": "class StewardNPC(DefaultCharacter):\n \"\"\"An NPC steward who serves as a living interface to the Memory Palace.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.palace_index = {}\n self.db.welcome_msg = \"I am the Steward. Ask me of the Palace.\"\n\n def at_heard(self, speaker, message):\n topic = _extract_topic(message)\n if topic in self.db.palace_index:\n entry = self.db.palace_index[topic]\n speaker.msg(f\"|c{{self.name}}|n says: '{{entry[\\'summary\\']}}'\")\n else:\n speaker.msg(f\"|c{{self.name}}|n says: 'I know nothing of {{topic}}.'\")\n\ndef _extract_topic(question: str) -> str:\n q = question.lower().strip(\"?\")\n for prefix in (\"what is\", \"tell me about\", \"do you know\", \"where is\"):\n if q.startswith(prefix):\n return q[len(prefix):].strip()\n return q", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0968"}
{"problem": "Construct a spatial-memory system that evennia room typeclass that stores a memory-palace wing reference and exposes it as an attribute. with logging.", "solution": "class MemPalaceRoom(DefaultRoom):\n \"\"\"A room linked to a Memory Palace wing for spatial recall.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wing = \"default\"\n self.db.room_index = 0\n self.db.topics = []\n\n def get_display_name(self, looker, **kwargs):\n name = super().get_display_name(looker, **kwargs)\n wing = self.db.wing or \"unknown\"\n return f\"{{name}} ({{wing}})\"\n\n def return_appearance(self, looker, **kwargs):\n appearance = super().return_appearance(looker, **kwargs)\n topics = self.db.topics or []\n if topics:\n appearance += \"\n|wTopics:|n \" + \", \".join(topics)\n return appearance", "imports": "from evennia import DefaultRoom", "domain": "room state", "id": "evennia-tower-0969"}
{"problem": "Write Python code to nPC with a mood state machine that affects its dialogue responses. including error handling.", "solution": "# Generated variation 970\nclass MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0970"}
{"problem": "Implement a function that find all rooms on a specific floor of The Tower. with full docstrings.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0971"}
{"problem": "Create a class which parse room output text from Evennia into structured data (description, exits, contents). and expose it as a command.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n entry = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n entry[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n entry[\"description\"] += line + \" \"\n elif section == \"exits\":\n entry[\"exits\"].append(line)\n elif section == \"contents\":\n entry[\"contents\"].append(line)\n return entry", "imports": "", "domain": "MUD world", "id": "evennia-tower-0972"}
{"problem": "Build an Evennia typeclass that generate a command_executed event dict for tracking player actions in Evennia. using dataclasses.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0973"}
{"problem": "Design a Tower component to build a TowerMap dataclass that holds the complete holographic map with rooms, floors, and NPCs. with type hints.", "solution": "@dataclass\nclass TowerMap:\n \"\"\"Complete holographic map of The Tower.\"\"\"\n name: str = \"The Tower\"\n description: str = \"The persistent world of the Timmy Foundation\"\n floors: list[TowerFloor] = field(default_factory=list)\n rooms: list[TowerRoom] = field(default_factory=list)\n npcs: list[TowerNPC] = field(default_factory=list)\n connections: list[dict] = field(default_factory=list)\n sources_scanned: list[str] = field(default_factory=list)\n map_version: str = \"1.0\"", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0974"}
{"problem": "How would you create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. that persists to JSON.", "solution": "# Generated variation 975\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0975"}
{"problem": "In an Evennia MUD, how do you parse room output text from Evennia into structured data (description, exits, contents). with lock checks.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0976"}
{"problem": "For The Tower architecture, write code to parse room output text from Evennia into structured data (description, exits, contents). that broadcasts to all occupants.", "solution": "def parse_room_output(text: str) -> dict:\n lines = text.strip().split(\"\\n\")\n result = {\"title\": \"\", \"description\": \"\", \"exits\": [], \"contents\": []}\n section = \"title\"\n for line in lines:\n line = line.strip()\n if not line:\n continue\n if line.startswith(\"Obvious exits:\"):\n section = \"exits\"\n continue\n if line.startswith(\"You see:\"):\n section = \"contents\"\n continue\n if section == \"title\":\n result[\"title\"] = line\n section = \"description\"\n elif section == \"description\":\n result[\"description\"] += line + \" \"\n elif section == \"exits\":\n result[\"exits\"].append(line)\n elif section == \"contents\":\n result[\"contents\"].append(line)\n return result", "imports": "", "domain": "MUD world", "id": "evennia-tower-0977"}
{"problem": "Using Evennia's API, define a dataclass for a Tower room that maps to an Evennia room and a Memory Palace room. supporting async callbacks.", "solution": "@dataclass\nclass TowerRoom:\n \"\"\"A room in The Tower — maps to a Memory Palace room or Evennia room.\"\"\"\n name: str\n floor: int = 0\n description: str = \"\"\n category: str = \"\" # origin, philosophy, mission, architecture, operations\n connections: list[str] = field(default_factory=list)\n occupants: list[str] = field(default_factory=list)\n artifacts: list[str] = field(default_factory=list)\n source: str = \"\"\n coordinates: tuple = (0, 0)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0978"}
{"problem": "Construct a spatial-memory system that evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with logging.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0979"}
{"problem": "Write Python code to nPC with a mood state machine that affects its dialogue responses. including error handling.", "solution": "# Generated variation 980\nclass MoodyNPC(DefaultCharacter):\n \"\"\"NPC whose dialogue changes based on mood state.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.mood = \"neutral\" # neutral, happy, angry, sad\n self.db.dialogue = {\n \"neutral\": [\"Hello.\", \"What do you need?\"],\n \"happy\": [\"A fine day!\", \"Welcome, friend!\"],\n \"angry\": [\"Leave me be!\", \"I have no patience today.\"],\n \"sad\": [\"*sigh*\", \"The world weighs heavy...\"],\n }\n\n def respond(self, speaker, message):\n pool = self.db.dialogue.get(self.db.mood, self.db.dialogue[\"neutral\"])\n reply = random.choice(pool)\n speaker.msg(f\"|c{{self.name}}|n says: '{{reply}}'\")\n\n def set_mood(self, mood):\n if mood in self.db.dialogue:\n self.db.mood = mood\n self.msg_contents(f\"|y{{self.name}} seems {{mood}} now.|n\")", "imports": "from evennia import DefaultCharacter", "domain": "NPC behavior", "id": "evennia-tower-0980"}
{"problem": "Implement a function that evennia event dict when a player joins the game, including account and character names. with full docstrings.", "solution": "def player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0981"}
{"problem": "Create a class which nPC that wanders between connected rooms on a timed interval. and expose it as a command.", "solution": "class WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0982"}
{"problem": "Build an Evennia typeclass that strip ANSI escape codes from Evennia terminal output for clean log processing. using dataclasses.", "solution": "def strip_ansi(text: str) -> str:\n ansi_pattern = re.compile(r\"\\x1b\\[[0-9;]*m\")\n return ansi_pattern.sub(\"\", text)", "imports": "import re", "domain": "MUD world", "id": "evennia-tower-0983"}
{"problem": "Design a Tower component to parse a raw Evennia log line into a structured event dict, extracting timestamp and message. with type hints.", "solution": "def parse_log_line(line: str) -> Optional[dict]:\n # Format: 2026-04-12 14:23:01 [evennia] Message here\n match = re.match(\n r\"^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (.*)$\",\n line.strip(),\n )\n if not match:\n return None\n return {\n \"timestamp\": match.group(1),\n \"channel\": match.group(2),\n \"message\": match.group(3),\n }", "imports": "import re\nfrom typing import Optional", "domain": "MUD world", "id": "evennia-tower-0984"}
{"problem": "How would you nPC that wanders between connected rooms on a timed interval. that persists to JSON.", "solution": "# Generated variation 985\nclass WanderingNPC(DefaultCharacter):\n \"\"\"An NPC that moves between exits automatically.\"\"\"\n\n def at_object_creation(self):\n super().at_object_creation()\n self.db.wander_interval = 30 # seconds\n self.db.home_room = None\n\n def start_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.add(self, self.db.wander_interval)\n\n def at_tick(self):\n exits = [ex for ex in self.location.exits if ex.access(self, \"traverse\")]\n if exits:\n chosen = random.choice(exits)\n self.move_to(chosen.destination)\n\n def stop_wandering(self):\n from evennia import TICKER_HANDLER\n TICKER_HANDLER.remove(self)", "imports": "from evennia import DefaultCharacter, TICKER_HANDLER", "domain": "NPC behavior", "id": "evennia-tower-0985"}
{"problem": "In an Evennia MUD, how do you evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. with lock checks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0986"}
{"problem": "For The Tower architecture, write code to normalize an Evennia bridge event by ensuring all required fields exist with defaults. that broadcasts to all occupants.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0987"}
{"problem": "Using Evennia's API, evennia command that lets a player search the Memory Palace by topic and returns the closest matching room. supporting async callbacks.", "solution": "class CmdRecall(Command):\n \"\"\"\n Recall information from the Memory Palace.\n\n Usage:\n recall <topic>\n recall <topic> in <wing>\n \"\"\"\n key = \"recall\"\n aliases = [\"remember\", \"search\"]\n locks = \"cmd:all()\"\n\n def func(self):\n if not self.args:\n self.caller.msg(\"Recall what topic?\")\n return\n topic = self.args.strip()\n wing = self.caller.location.db.wing if self.caller.location else None\n matches = _search_mempalace(topic, wing=wing)\n if not matches:\n self.caller.msg(f\"No memory of '{topic}' found.\")\n return\n best = matches[0]\n self.caller.msg(f\"|wMemory: {{best['topic']}}|n\n{{best['summary']}}\")\n\ndef _search_mempalace(query, wing=None, n=5):\n results = []\n for room in DefaultRoom.objects.all():\n topics = room.db.topics or []\n score = sum(1 for t in topics if query.lower() in t.lower())\n if score:\n if wing and room.db.wing != wing:\n score *= 0.5\n results.append({\"room\": room, \"score\": score, \"topic\": query})\n results.sort(key=lambda x: x[\"score\"], reverse=True)\n return results[:n]", "imports": "from evennia import Command, DefaultRoom", "domain": "spatial memory", "id": "evennia-tower-0988"}
{"problem": "Construct a spatial-memory system that manage multiple user sessions in a thread-safe session manager. with logging.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0989"}
{"problem": "Write Python code to create a normalized room snapshot event for the Evennia bridge, including exits, objects, and occupants. including error handling.", "solution": "# Generated variation 990\ndef room_snapshot(room_key: str, title: str, desc: str,\n exits: list[dict] | None = None,\n objects: list[dict] | None = None,\n occupants: list[dict] | None = None,\n timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"room_snapshot\",\n \"room_key\": room_key,\n \"title\": title,\n \"description\": desc,\n \"exits\": exits or [],\n \"objects\": objects or [],\n \"occupants\": occupants or [],\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0990"}
{"problem": "Implement a function that create a Tower floor dataclass that groups rooms by theme. with full docstrings.", "solution": "@dataclass\nclass TowerFloor:\n \"\"\"A floor in The Tower — groups rooms by theme.\"\"\"\n number: int\n name: str\n theme: str = \"\"\n rooms: list[str] = field(default_factory=list)", "imports": "from dataclasses import dataclass, field", "domain": "Tower architecture", "id": "evennia-tower-0991"}
{"problem": "Create a class which find the shortest path between two Tower rooms by name using BFS. and expose it as a command.", "solution": "from collections import deque\n\ndef shortest_path(tower_map: TowerMap, start_name: str, end_name: str) -> list[str]:\n graph = {r.name: r.connections for r in tower_map.rooms}\n if start_name not in graph or end_name not in graph:\n return []\n queue = deque([(start_name, [start_name])])\n visited = {start_name}\n while queue:\n current, path = queue.popleft()\n if current == end_name:\n return path\n for neighbor in graph.get(current, []):\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return []", "imports": "from collections import deque", "domain": "Tower architecture", "id": "evennia-tower-0992"}
{"problem": "Build an Evennia typeclass that manage multiple user sessions in a thread-safe session manager. using dataclasses.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0993"}
{"problem": "Design a Tower component to normalize an Evennia bridge event by ensuring all required fields exist with defaults. with type hints.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0994"}
{"problem": "How would you evennia event dict when a player joins the game, including account and character names. that persists to JSON.", "solution": "# Generated variation 995\ndef player_join(account: str, character: str = \"\", ip_address: str = \"\", timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"player_join\",\n \"account\": account,\n \"character\": character,\n \"ip_address\": ip_address,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "from typing import Optional", "domain": "MUD world", "id": "evennia-tower-0995"}
{"problem": "In an Evennia MUD, how do you manage multiple user sessions in a thread-safe session manager. with lock checks.", "solution": "class SessionManager:\n def __init__(self):\n self._sessions: dict[str, UserSession] = {}\n self._lock = threading.Lock()\n\n def add(self, session: UserSession):\n with self._lock:\n self._sessions[session.connection_id] = session\n\n def remove(self, connection_id: str):\n with self._lock:\n self._sessions.pop(connection_id, None)\n\n def get(self, connection_id: str) -> UserSession | None:\n with self._lock:\n return self._sessions.get(connection_id)\n\n def list_active(self) -> list[UserSession]:\n with self._lock:\n return [s for s in self._sessions.values() if s.active]", "imports": "import threading", "domain": "multi-user bridge", "id": "evennia-tower-0996"}
{"problem": "For The Tower architecture, write code to find all rooms on a specific floor of The Tower. that broadcasts to all occupants.", "solution": "def rooms_on_floor(tower_map: TowerMap, floor_num: int) -> list[TowerRoom]:\n return [r for r in tower_map.rooms if r.floor == floor_num]", "imports": "", "domain": "Tower architecture", "id": "evennia-tower-0997"}
{"problem": "Using Evennia's API, normalize an Evennia bridge event by ensuring all required fields exist with defaults. supporting async callbacks.", "solution": "def normalize_event(event: dict) -> dict:\n required = {\n \"event_type\": \"unknown\",\n \"timestamp\": \"\",\n \"character\": \"\",\n \"room_key\": \"\",\n }\n normalized = {**required, **event}\n # Ensure nested dicts\n for key in (\"exits\", \"objects\", \"occupants\"):\n if key not in normalized or normalized[key] is None:\n normalized[key] = []\n return normalized", "imports": "", "domain": "MUD world", "id": "evennia-tower-0998"}
{"problem": "Construct a spatial-memory system that generate a command_executed event dict for tracking player actions in Evennia. with logging.", "solution": "def command_executed(character: str, command: str, args: str = \"\", success: bool = True, timestamp: str | None = None) -> dict:\n return {\n \"event_type\": \"command_executed\",\n \"character\": character,\n \"command\": command,\n \"args\": args,\n \"success\": success,\n \"timestamp\": timestamp or _ts(),\n }", "imports": "", "domain": "MUD world", "id": "evennia-tower-0999"}