Spaces:
Sleeping
Sleeping
Upload game_engine.py
Browse files- game_engine.py +19 -25
game_engine.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# ==========================================
|
| 2 |
-
# game_engine.py - Calcul OCR v3.0 CLEAN (
|
| 3 |
# ==========================================
|
| 4 |
|
| 5 |
"""
|
|
@@ -374,13 +374,12 @@ class MathGame:
|
|
| 374 |
self.current_operation = operation_str
|
| 375 |
self.correct_answer = answer
|
| 376 |
|
| 377 |
-
#
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
a, op_char, b = int(parts[0]), operation_str.split()[1], int(parts[2])
|
| 384 |
self.operations_history.append((a, b, op_char, answer))
|
| 385 |
|
| 386 |
# Affichage adapté selon l'opération
|
|
@@ -420,13 +419,12 @@ class MathGame:
|
|
| 420 |
self.user_images.append(image_data)
|
| 421 |
self.expected_answers.append(self.correct_answer)
|
| 422 |
|
|
|
|
| 423 |
# Parser l'opération actuelle pour le traitement
|
| 424 |
-
parts = self.current_operation.
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
self.current_operation.replace(' ', '').split('÷')
|
| 428 |
|
| 429 |
-
a, op_char, b = int(parts[0]), self.current_operation.split()[1], int(parts[2])
|
| 430 |
current_operation_data = (a, b, op_char, self.correct_answer)
|
| 431 |
|
| 432 |
# Lancer le traitement en parallèle de l'image qu'on vient de recevoir
|
|
@@ -439,13 +437,12 @@ class MathGame:
|
|
| 439 |
self.current_operation = operation_str
|
| 440 |
self.correct_answer = answer
|
| 441 |
|
|
|
|
| 442 |
# Parser pour l'historique
|
| 443 |
-
parts = operation_str.
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
a, op_char, b = int(parts[0]), operation_str.split()[1], int(parts[2])
|
| 449 |
self.operations_history.append((a, b, op_char, answer))
|
| 450 |
|
| 451 |
time_remaining = max(0, self.duration - int(elapsed_time))
|
|
@@ -487,12 +484,9 @@ class MathGame:
|
|
| 487 |
# Traitement de la dernière image si elle n'a pas été ajoutée
|
| 488 |
if len(self.operations_history) < len(self.user_images):
|
| 489 |
# Cela signifie que la dernière question n'a pas encore été historisée
|
| 490 |
-
#
|
| 491 |
-
parts = self.current_operation.
|
| 492 |
-
|
| 493 |
-
self.current_operation.replace(' ', '').split('-') if '-' in self.current_operation else \
|
| 494 |
-
self.current_operation.replace(' ', '').split('÷')
|
| 495 |
-
a, op_char, b = int(parts[0]), self.current_operation.split()[1], int(parts[2])
|
| 496 |
self.operations_history.append((a, b, op_char, self.correct_answer))
|
| 497 |
|
| 498 |
# Assurer que la dernière image est traitée si ce n'est pas déjà fait
|
|
|
|
| 1 |
# ==========================================
|
| 2 |
+
# game_engine.py - Calcul OCR v3.0 CLEAN (Corrigé parsing opérations)
|
| 3 |
# ==========================================
|
| 4 |
|
| 5 |
"""
|
|
|
|
| 374 |
self.current_operation = operation_str
|
| 375 |
self.correct_answer = answer
|
| 376 |
|
| 377 |
+
# ====== RETOUR À LA LOGIQUE DE PARSING ORIGINALE ET QUI FONCTIONNE ======
|
| 378 |
+
# Parser l'opération pour l'historique (ex: "10 + 5" -> ["10", "+", "5"])
|
| 379 |
+
parts = operation_str.split()
|
| 380 |
+
a, op_char, b = int(parts[0]), parts[1], int(parts[2])
|
| 381 |
+
# =======================================================================
|
| 382 |
+
|
|
|
|
| 383 |
self.operations_history.append((a, b, op_char, answer))
|
| 384 |
|
| 385 |
# Affichage adapté selon l'opération
|
|
|
|
| 419 |
self.user_images.append(image_data)
|
| 420 |
self.expected_answers.append(self.correct_answer)
|
| 421 |
|
| 422 |
+
# ====== RETOUR À LA LOGIQUE DE PARSING ORIGINALE ET QUI FONCTIONNE ======
|
| 423 |
# Parser l'opération actuelle pour le traitement
|
| 424 |
+
parts = self.current_operation.split()
|
| 425 |
+
a, op_char, b = int(parts[0]), parts[1], int(parts[2])
|
| 426 |
+
# =======================================================================
|
|
|
|
| 427 |
|
|
|
|
| 428 |
current_operation_data = (a, b, op_char, self.correct_answer)
|
| 429 |
|
| 430 |
# Lancer le traitement en parallèle de l'image qu'on vient de recevoir
|
|
|
|
| 437 |
self.current_operation = operation_str
|
| 438 |
self.correct_answer = answer
|
| 439 |
|
| 440 |
+
# ====== RETOUR À LA LOGIQUE DE PARSING ORIGINALE ET QUI FONCTIONNE ======
|
| 441 |
# Parser pour l'historique
|
| 442 |
+
parts = operation_str.split()
|
| 443 |
+
a, op_char, b = int(parts[0]), parts[1], int(parts[2])
|
| 444 |
+
# =======================================================================
|
| 445 |
+
|
|
|
|
|
|
|
| 446 |
self.operations_history.append((a, b, op_char, answer))
|
| 447 |
|
| 448 |
time_remaining = max(0, self.duration - int(elapsed_time))
|
|
|
|
| 484 |
# Traitement de la dernière image si elle n'a pas été ajoutée
|
| 485 |
if len(self.operations_history) < len(self.user_images):
|
| 486 |
# Cela signifie que la dernière question n'a pas encore été historisée
|
| 487 |
+
# Parser la dernière opération affichée
|
| 488 |
+
parts = self.current_operation.split()
|
| 489 |
+
a, op_char, b = int(parts[0]), parts[1], int(parts[2])
|
|
|
|
|
|
|
|
|
|
| 490 |
self.operations_history.append((a, b, op_char, self.correct_answer))
|
| 491 |
|
| 492 |
# Assurer que la dernière image est traitée si ce n'est pas déjà fait
|