Update app.py
Browse files
app.py
CHANGED
|
@@ -35,15 +35,13 @@ def start_game():
|
|
| 35 |
# Initialize game state
|
| 36 |
questions_asked = 0
|
| 37 |
possible_objects = list(objects_and_questions.keys()) # Start with all objects
|
| 38 |
-
current_questions = {} #
|
| 39 |
|
| 40 |
while questions_asked < 10 and len(possible_objects) > 1:
|
| 41 |
question = None
|
| 42 |
for obj in possible_objects:
|
| 43 |
-
|
| 44 |
-
current_questions[obj] = 0 # Start with the first question for this object
|
| 45 |
if current_questions[obj] < len(objects_and_questions[obj]):
|
| 46 |
-
# Get the next unanswered question for the object
|
| 47 |
question = objects_and_questions[obj][current_questions[obj]]
|
| 48 |
break
|
| 49 |
|
|
@@ -53,13 +51,13 @@ def start_game():
|
|
| 53 |
# Ask the question
|
| 54 |
answer = st.radio(question, ('Yes', 'No'), key=questions_asked)
|
| 55 |
|
| 56 |
-
#
|
| 57 |
if answer == 'Yes':
|
| 58 |
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] == question]
|
| 59 |
else:
|
| 60 |
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] != question]
|
| 61 |
|
| 62 |
-
# Move to the next question for the
|
| 63 |
for obj in possible_objects:
|
| 64 |
current_questions[obj] += 1
|
| 65 |
|
|
|
|
| 35 |
# Initialize game state
|
| 36 |
questions_asked = 0
|
| 37 |
possible_objects = list(objects_and_questions.keys()) # Start with all objects
|
| 38 |
+
current_questions = {obj: 0 for obj in possible_objects} # Initialize the index for each object
|
| 39 |
|
| 40 |
while questions_asked < 10 and len(possible_objects) > 1:
|
| 41 |
question = None
|
| 42 |
for obj in possible_objects:
|
| 43 |
+
# Make sure we have not exhausted all questions for the object
|
|
|
|
| 44 |
if current_questions[obj] < len(objects_and_questions[obj]):
|
|
|
|
| 45 |
question = objects_and_questions[obj][current_questions[obj]]
|
| 46 |
break
|
| 47 |
|
|
|
|
| 51 |
# Ask the question
|
| 52 |
answer = st.radio(question, ('Yes', 'No'), key=questions_asked)
|
| 53 |
|
| 54 |
+
# Filter objects based on the answer
|
| 55 |
if answer == 'Yes':
|
| 56 |
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] == question]
|
| 57 |
else:
|
| 58 |
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] != question]
|
| 59 |
|
| 60 |
+
# Move to the next question for the filtered objects
|
| 61 |
for obj in possible_objects:
|
| 62 |
current_questions[obj] += 1
|
| 63 |
|