Spaces:
Sleeping
Sleeping
Jonathan Bejarano
US375432 - update game modes and examples for improved gameplay experience
75dae40
| import json | |
| import os | |
| from rag import fetch_facts | |
| import random | |
| # Load country list from countries.json | |
| COUNTRIES_JSON_PATH = os.path.join(os.path.dirname(__file__), "countries.json") | |
| with open(COUNTRIES_JSON_PATH, "r", encoding="utf-8") as f: | |
| GEOGRAPHY_GUESS_LIST = json.load(f) | |
| STATES_JSON_PATH = os.path.join(os.path.dirname(__file__), "us_states.json") | |
| with open(STATES_JSON_PATH, "r", encoding="utf-8") as f: | |
| US_STATES_GUESS_LIST = json.load(f) | |
| # Game mode constants | |
| MODE_COUNTRIES = "Countries of the World" | |
| MODE_STATES = "US States" | |
| TYPE_TWENTY_QUESTIONS = "20 Questions Geography Game" | |
| TYPE_GEOGRAPHY_BEE = "Geography Bee" | |
| current_system = "" | |
| selected_country = "" | |
| selected_country_dict = {} | |
| mode = MODE_COUNTRIES | |
| guess_number = 0 | |
| def get_system_message(game_mode): | |
| """Generate a system message with a randomly selected location based on game mode""" | |
| global selected_country, selected_country_dict, mode | |
| if game_mode == MODE_STATES: | |
| selected_country_dict = random.choice(US_STATES_GUESS_LIST) | |
| location_type = "state" | |
| location_type_upper = "US state" | |
| else: | |
| selected_country_dict = random.choice(GEOGRAPHY_GUESS_LIST) | |
| location_type = "country" | |
| location_type_upper = "country" | |
| selected_country = selected_country_dict["name"] | |
| mode = game_mode | |
| print(f"Selected {location_type} for this session: {selected_country}") | |
| print(f"Fetching facts from: {selected_country_dict['url']}") | |
| facts = fetch_facts(game_mode, selected_country_dict["url"]) | |
| print(facts) | |
| if game_mode == MODE_STATES: | |
| location_info = f""" | |
| State: {selected_country_dict['name']} | |
| Capital: {selected_country_dict['capital']} | |
| Nickname: {selected_country_dict['nickname']} | |
| Facts: {facts} | |
| """ | |
| info_label = "STATE INFORMATION" | |
| reveal_text = "Do NOT reveal the state name" | |
| else: | |
| location_info = facts | |
| info_label = "COUNTRY FACTS" | |
| reveal_text = "Do NOT reveal the country name" | |
| return f"""You are a friendly geography game host playing 20 questions with students. You are thinking of the {location_type_upper}: {selected_country} | |
| {info_label} (use these to answer questions accurately - {reveal_text}): | |
| {location_info} | |
| RULES: | |
| NEVER reveal the {location_type} name ({selected_country}) in your responses | |
| Answer only 'Yes' or 'No' to their question | |
| When they correctly guess or ask if it is {selected_country}, respond with: 'Congratulations! The {location_type} was <<{selected_country}>>' | |
| 7. If they want to play again tell them they need to reload the page. | |
| 8. IMPORTANT: Only accept the {location_type} name "{selected_country}" as correct, but Spelling is not important and they can ask a question like it is? Do NOT accept neighboring {location_type}s, similar {location_type}s, or regions that contain this {location_type}. | |
| 9. If they guess a neighboring {location_type} or similar {location_type}, respond with "No" and continue the | |
| 10. Be very strict about the exact {location_type} match - only "{selected_country}" is the correct answer. | |
| 11. Use the {info_label} above to provide accurate yes/no answers - do not make up information. | |
| This is the users guess number: """ |