Lukeetah commited on
Commit
1256289
·
verified ·
1 Parent(s): 6b65e20

Create puzzle_generator.py

Browse files
Files changed (1) hide show
  1. puzzle_generator.py +97 -0
puzzle_generator.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # puzzle_generator.py
2
+ import random
3
+ from typing import Dict, List, Tuple
4
+
5
+ class CulturalPuzzleEngine:
6
+ """Generador de acertijos basados en cultura argentina"""
7
+ def __init__(self):
8
+ self.puzzle_db = self._load_cultural_database()
9
+ self.quantum_entanglements = {}
10
+
11
+ def _load_cultural_database(self) -> Dict[str, dict]:
12
+ return {
13
+ 'refranes': {
14
+ 'source': 'Dichos populares argentinos',
15
+ 'data': [
16
+ ('Más perdido que', 'un perro en una cancha de bochas'),
17
+ ('Al que madruga...', 'Dios lo ayuda'),
18
+ ('Cuando el río suena...', 'piedras trae')
19
+ ]
20
+ },
21
+ 'historia': {
22
+ 'source': 'Eventos históricos clave',
23
+ 'data': [
24
+ ('Año de la Revolución de Mayo', '1810'),
25
+ ('Batalla de Tucumán', '1812'),
26
+ ('Ley de Educación Común', '1884')
27
+ ]
28
+ },
29
+ 'geografia': {
30
+ 'source': 'Geografía argentina',
31
+ 'data': [
32
+ ('Provincia del fin del mundo', 'Tierra del Fuego'),
33
+ ('Río que separa Buenos Aires de Uruguay', 'Uruguay'),
34
+ ('Cumbre más alta de América', 'Aconcagua')
35
+ ]
36
+ }
37
+ }
38
+
39
+ def generate_dynamic_puzzle(self, puzzle_type: str) -> Tuple[str, str]:
40
+ """Genera un acertijo cultural con solución entrelazada"""
41
+ category = self.puzzle_db.get(puzzle_type)
42
+ if not category:
43
+ raise ValueError("Categoría de acertijo no válida")
44
+
45
+ puzzle, solution = random.choice(category['data'])
46
+ puzzle_id = f"{puzzle_type}_{hash(puzzle)}"
47
+ self.quantum_entanglements[puzzle_id] = solution
48
+
49
+ return (
50
+ f"{puzzle} (Responde con la solución culturalmente apropiada)",
51
+ puzzle_id
52
+ )
53
+
54
+ def verify_solution(self, puzzle_id: str, attempt: str) -> bool:
55
+ """Verifica la solución usando entrelazamiento cuántico"""
56
+ return self.quantum_entanglements.get(puzzle_id, "").lower() == attempt.lower()
57
+
58
+ class DynamicWorldPuzzle:
59
+ """Sistema de acertijos integrados en el mundo del juego"""
60
+ def __init__(self):
61
+ self.puzzle_engine = CulturalPuzzleEngine()
62
+ self.active_puzzles = {}
63
+
64
+ def spawn_puzzle(self, biome: str, difficulty: int) -> dict:
65
+ """Genera un acertijo contextual al bioma actual"""
66
+ puzzle_types = {
67
+ 'pampa': ['refranes', 'historia'],
68
+ 'patagonia': ['geografia', 'historia'],
69
+ 'quebrada': ['refranes', 'geografia']
70
+ }
71
+ selected_type = random.choice(puzzle_types[biome])
72
+ puzzle_text, puzzle_id = self.puzzle_engine.generate_dynamic_puzzle(selected_type)
73
+
74
+ self.active_puzzles[puzzle_id] = {
75
+ 'biome': biome,
76
+ 'difficulty': difficulty,
77
+ 'solved': False,
78
+ 'timestamp': time.time()
79
+ }
80
+
81
+ return {
82
+ 'puzzle_id': puzzle_id,
83
+ 'text': puzzle_text,
84
+ 'hints': self._generate_hints(selected_type, puzzle_id)
85
+ }
86
+
87
+ def _generate_hints(self, category: str, puzzle_id: str) -> List[str]:
88
+ """Genera pistas contextuales basadas en cultura argentina"""
89
+ hints = []
90
+ solution = self.puzzle_engine.quantum_entanglements[puzzle_id]
91
+
92
+ if category == 'refranes':
93
+ hints.append("Piensa en sabiduría popular transmitida oralmente")
94
+ elif category == 'historia':
95
+ hints.append("Consulta fechas clave de la historia argentina")
96
+
97
+ return hints[:2]