Spaces:
Runtime error
Runtime error
| # puzzle_generator.py | |
| import random | |
| from typing import Dict, List, Tuple | |
| class CulturalPuzzleEngine: | |
| """Generador de acertijos basados en cultura argentina""" | |
| def __init__(self): | |
| self.puzzle_db = self._load_cultural_database() | |
| self.quantum_entanglements = {} | |
| def _load_cultural_database(self) -> Dict[str, dict]: | |
| return { | |
| 'refranes': { | |
| 'source': 'Dichos populares argentinos', | |
| 'data': [ | |
| ('Más perdido que', 'un perro en una cancha de bochas'), | |
| ('Al que madruga...', 'Dios lo ayuda'), | |
| ('Cuando el río suena...', 'piedras trae') | |
| ] | |
| }, | |
| 'historia': { | |
| 'source': 'Eventos históricos clave', | |
| 'data': [ | |
| ('Año de la Revolución de Mayo', '1810'), | |
| ('Batalla de Tucumán', '1812'), | |
| ('Ley de Educación Común', '1884') | |
| ] | |
| }, | |
| 'geografia': { | |
| 'source': 'Geografía argentina', | |
| 'data': [ | |
| ('Provincia del fin del mundo', 'Tierra del Fuego'), | |
| ('Río que separa Buenos Aires de Uruguay', 'Uruguay'), | |
| ('Cumbre más alta de América', 'Aconcagua') | |
| ] | |
| } | |
| } | |
| def generate_dynamic_puzzle(self, puzzle_type: str) -> Tuple[str, str]: | |
| """Genera un acertijo cultural con solución entrelazada""" | |
| category = self.puzzle_db.get(puzzle_type) | |
| if not category: | |
| raise ValueError("Categoría de acertijo no válida") | |
| puzzle, solution = random.choice(category['data']) | |
| puzzle_id = f"{puzzle_type}_{hash(puzzle)}" | |
| self.quantum_entanglements[puzzle_id] = solution | |
| return ( | |
| f"{puzzle} (Responde con la solución culturalmente apropiada)", | |
| puzzle_id | |
| ) | |
| def verify_solution(self, puzzle_id: str, attempt: str) -> bool: | |
| """Verifica la solución usando entrelazamiento cuántico""" | |
| return self.quantum_entanglements.get(puzzle_id, "").lower() == attempt.lower() | |
| class DynamicWorldPuzzle: | |
| """Sistema de acertijos integrados en el mundo del juego""" | |
| def __init__(self): | |
| self.puzzle_engine = CulturalPuzzleEngine() | |
| self.active_puzzles = {} | |
| def spawn_puzzle(self, biome: str, difficulty: int) -> dict: | |
| """Genera un acertijo contextual al bioma actual""" | |
| puzzle_types = { | |
| 'pampa': ['refranes', 'historia'], | |
| 'patagonia': ['geografia', 'historia'], | |
| 'quebrada': ['refranes', 'geografia'] | |
| } | |
| selected_type = random.choice(puzzle_types[biome]) | |
| puzzle_text, puzzle_id = self.puzzle_engine.generate_dynamic_puzzle(selected_type) | |
| self.active_puzzles[puzzle_id] = { | |
| 'biome': biome, | |
| 'difficulty': difficulty, | |
| 'solved': False, | |
| 'timestamp': time.time() | |
| } | |
| return { | |
| 'puzzle_id': puzzle_id, | |
| 'text': puzzle_text, | |
| 'hints': self._generate_hints(selected_type, puzzle_id) | |
| } | |
| def _generate_hints(self, category: str, puzzle_id: str) -> List[str]: | |
| """Genera pistas contextuales basadas en cultura argentina""" | |
| hints = [] | |
| solution = self.puzzle_engine.quantum_entanglements[puzzle_id] | |
| if category == 'refranes': | |
| hints.append("Piensa en sabiduría popular transmitida oralmente") | |
| elif category == 'historia': | |
| hints.append("Consulta fechas clave de la historia argentina") | |
| return hints[:2] | |