From 86e86e76ad5316aa2beac2bec72f9abe805603cd Mon Sep 17 00:00:00 2001 From: black shadow Date: Sun, 20 Oct 2024 00:34:44 +0530 Subject: [PATCH 1/6] Added the morse code --- morse.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 morse.py diff --git a/morse.py b/morse.py new file mode 100644 index 0000000..666ec9d --- /dev/null +++ b/morse.py @@ -0,0 +1,74 @@ +# Morse Code Dictionary +MORSE_CODE_DICT = { + 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', + 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', + 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', + 'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', + '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', ',': '--..--', '.': '.-.-.-', + '?': '..--..', '/': '-..-.', '-': '-....-', '(': '-.--.', ')': '-.--.-', ' ': '/' +} + +# Function to encode a message to Morse code +def encode_to_morse(message): + try: + morse_code = '' + for char in message.upper(): + if char not in MORSE_CODE_DICT: + raise ValueError(f"Character '{char}' cannot be encoded into Morse code.") + morse_code += MORSE_CODE_DICT[char] + ' ' + return morse_code.strip() + except ValueError as ve: + print(ve) + return None + except Exception as e: + print(f"An unexpected error occurred: {e}") + return None + +# Function to decode Morse code to a message +def decode_from_morse(morse_message): + try: + morse_words = morse_message.split(' / ') # Words are separated by '/' + decoded_message = '' + for word in morse_words: + for morse_char in word.split(): + if morse_char not in MORSE_CODE_DICT.values(): + raise ValueError(f"Morse code '{morse_char}' is invalid.") + decoded_message += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(morse_char)] + decoded_message += ' ' + return decoded_message.strip() + except ValueError as ve: + print(ve) + return None + except Exception as e: + print(f"An unexpected error occurred: {e}") + return None + +# Main program loop +if __name__ == "__main__": + while True: + print("\nMorse Code Encoder/Decoder") + print("1. Encode a message to Morse code") + print("2. Decode Morse code to a message") + print("3. Exit") + + try: + choice = int(input("Select an option (1/2/3): ")) + if choice == 1: + message = input("Enter a message to encode: ") + result = encode_to_morse(message) + if result: + print(f"Encoded Morse Code: {result}") + elif choice == 2: + morse_message = input("Enter Morse code to decode (use '/' for space between words): ") + result = decode_from_morse(morse_message) + if result: + print(f"Decoded Message: {result}") + elif choice == 3: + print("Goodbye!") + break + else: + print("Invalid option. Please select 1, 2, or 3.") + except ValueError: + print("Please enter a valid number for selection.") + except Exception as e: + print(f"An unexpected error occurred: {e}") From a51cadbb7eada7956de9a1cdd57748df68419631 Mon Sep 17 00:00:00 2001 From: black shadow Date: Mon, 21 Oct 2024 11:27:48 +0530 Subject: [PATCH 2/6] Added the python codes in a separate folder named python codes --- morse.py => python Codes/morse.py | 2 ++ 1 file changed, 2 insertions(+) rename morse.py => python Codes/morse.py (99%) diff --git a/morse.py b/python Codes/morse.py similarity index 99% rename from morse.py rename to python Codes/morse.py index 666ec9d..91fa298 100644 --- a/morse.py +++ b/python Codes/morse.py @@ -72,3 +72,5 @@ def decode_from_morse(morse_message): print("Please enter a valid number for selection.") except Exception as e: print(f"An unexpected error occurred: {e}") + + From 7c772cbeefafbe0a500f80f58b1f57bcf07657f3 Mon Sep 17 00:00:00 2001 From: black shadow Date: Tue, 22 Oct 2024 15:56:18 +0530 Subject: [PATCH 3/6] Added the python morse code in game-galore folder and deleted the python codes folder --- {python Codes => Game-Galore}/morse.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {python Codes => Game-Galore}/morse.py (100%) diff --git a/python Codes/morse.py b/Game-Galore/morse.py similarity index 100% rename from python Codes/morse.py rename to Game-Galore/morse.py From 511f7697641deac7276f232a23902628ee2ca838 Mon Sep 17 00:00:00 2001 From: black shadow Date: Tue, 22 Oct 2024 18:02:09 +0530 Subject: [PATCH 4/6] Added AI_animal_game and deleted the morse code --- Game-Galore/AI_Guess_Animal.py | 80 ++++++++++++++++++++++++++++++++++ Game-Galore/morse.py | 76 -------------------------------- animals.json | 1 + 3 files changed, 81 insertions(+), 76 deletions(-) create mode 100644 Game-Galore/AI_Guess_Animal.py delete mode 100644 Game-Galore/morse.py create mode 100644 animals.json diff --git a/Game-Galore/AI_Guess_Animal.py b/Game-Galore/AI_Guess_Animal.py new file mode 100644 index 0000000..9c4171e --- /dev/null +++ b/Game-Galore/AI_Guess_Animal.py @@ -0,0 +1,80 @@ +import json + +class AnimalGame: + def __init__(self): + # Load animal data from a JSON file or create a default one if it doesn't exist + self.data_file = 'animals.json' + self.animals = self.load_data() + + def load_data(self): + """Load animal data from a JSON file.""" + try: + with open(self.data_file, 'r') as file: + return json.load(file) + except FileNotFoundError: + return { + 'questions': {}, + 'animals': ['dog', 'cat', 'elephant', 'tiger', 'lion', 'rabbit', 'fish'] + } + + def save_data(self): + """Save animal data to a JSON file.""" + with open(self.data_file, 'w') as file: + json.dump(self.animals, file) + + def play_game(self): + print("Think of an animal, and I will try to guess it!") + self.ask_question('Is it a mammal?', 'mammal') + + def ask_question(self, question, key): + """Ask a question and navigate through the game.""" + answer = input(f"{question} (yes/no): ").strip().lower() + + if answer == 'yes': + if key in self.animals['questions']: + next_question = self.animals['questions'][key] + self.ask_question(next_question, key) + else: + animal = input("What animal did you think of? ") + self.animals['questions'][key] = input("What question would distinguish this animal? ") + self.animals['animals'].append(animal) + self.save_data() + print(f"Got it! I'll remember that a {animal} is a {key}.") + elif answer == 'no': + print("I couldn't guess it. Can you help me learn?") + new_animal = input("What was the animal? ") + new_question = input(f"What question would distinguish a {new_animal} from a {key}? ") + self.animals['questions'][key] = new_question + self.animals['animals'].append(new_animal) + self.save_data() + print(f"Thanks! I'll remember that a {new_animal} is different from a {key}.") + +if __name__ == "__main__": + game = AnimalGame() + game.play_game() + + + + + + +# Game Instructions: + +# 1.) Think of an animal. + +# 2.) The AI will ask you yes/no questions to guess the animal. + +# 3.) If the AI can't guess it, you can teach it by providing the name of the animal and a distinguishing question. + +# 4.) The AI learns from your inputs and will improve its guessing ability over time. + + +# Data Storage: + +# The game stores the questions and animals in a animals.json file. The first time you run the game, it will create this file with default data. + + + + + + diff --git a/Game-Galore/morse.py b/Game-Galore/morse.py deleted file mode 100644 index 91fa298..0000000 --- a/Game-Galore/morse.py +++ /dev/null @@ -1,76 +0,0 @@ -# Morse Code Dictionary -MORSE_CODE_DICT = { - 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', - 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', - 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', - 'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', - '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', ',': '--..--', '.': '.-.-.-', - '?': '..--..', '/': '-..-.', '-': '-....-', '(': '-.--.', ')': '-.--.-', ' ': '/' -} - -# Function to encode a message to Morse code -def encode_to_morse(message): - try: - morse_code = '' - for char in message.upper(): - if char not in MORSE_CODE_DICT: - raise ValueError(f"Character '{char}' cannot be encoded into Morse code.") - morse_code += MORSE_CODE_DICT[char] + ' ' - return morse_code.strip() - except ValueError as ve: - print(ve) - return None - except Exception as e: - print(f"An unexpected error occurred: {e}") - return None - -# Function to decode Morse code to a message -def decode_from_morse(morse_message): - try: - morse_words = morse_message.split(' / ') # Words are separated by '/' - decoded_message = '' - for word in morse_words: - for morse_char in word.split(): - if morse_char not in MORSE_CODE_DICT.values(): - raise ValueError(f"Morse code '{morse_char}' is invalid.") - decoded_message += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(morse_char)] - decoded_message += ' ' - return decoded_message.strip() - except ValueError as ve: - print(ve) - return None - except Exception as e: - print(f"An unexpected error occurred: {e}") - return None - -# Main program loop -if __name__ == "__main__": - while True: - print("\nMorse Code Encoder/Decoder") - print("1. Encode a message to Morse code") - print("2. Decode Morse code to a message") - print("3. Exit") - - try: - choice = int(input("Select an option (1/2/3): ")) - if choice == 1: - message = input("Enter a message to encode: ") - result = encode_to_morse(message) - if result: - print(f"Encoded Morse Code: {result}") - elif choice == 2: - morse_message = input("Enter Morse code to decode (use '/' for space between words): ") - result = decode_from_morse(morse_message) - if result: - print(f"Decoded Message: {result}") - elif choice == 3: - print("Goodbye!") - break - else: - print("Invalid option. Please select 1, 2, or 3.") - except ValueError: - print("Please enter a valid number for selection.") - except Exception as e: - print(f"An unexpected error occurred: {e}") - - diff --git a/animals.json b/animals.json new file mode 100644 index 0000000..1c221e8 --- /dev/null +++ b/animals.json @@ -0,0 +1 @@ +{"questions": {"mammal": "his teeth"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]} \ No newline at end of file From b073d2bf61412bddb3cde4b2434f0577f8d10b52 Mon Sep 17 00:00:00 2001 From: black shadow Date: Tue, 22 Oct 2024 18:21:03 +0530 Subject: [PATCH 5/6] Added AI_animal_game and deleted the morse code --- Game-Galore/AI_Guess_Animal.py | 4 +++- Game-Galore/animals.json | 1 + animals.json | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Game-Galore/animals.json delete mode 100644 animals.json diff --git a/Game-Galore/AI_Guess_Animal.py b/Game-Galore/AI_Guess_Animal.py index 9c4171e..c5e46ab 100644 --- a/Game-Galore/AI_Guess_Animal.py +++ b/Game-Galore/AI_Guess_Animal.py @@ -1,9 +1,11 @@ import json +import os class AnimalGame: def __init__(self): # Load animal data from a JSON file or create a default one if it doesn't exist - self.data_file = 'animals.json' + self.folder_name = 'Game-Galore' + self.data_file = os.path.join(self.folder_name, 'animals.json') self.animals = self.load_data() def load_data(self): diff --git a/Game-Galore/animals.json b/Game-Galore/animals.json new file mode 100644 index 0000000..e0cb57d --- /dev/null +++ b/Game-Galore/animals.json @@ -0,0 +1 @@ +{"questions": {"mammal": "his hairs"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]} \ No newline at end of file diff --git a/animals.json b/animals.json deleted file mode 100644 index 1c221e8..0000000 --- a/animals.json +++ /dev/null @@ -1 +0,0 @@ -{"questions": {"mammal": "his teeth"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]} \ No newline at end of file From c5c9df15ddbf4051532acf9b5e4ac27b78923cff Mon Sep 17 00:00:00 2001 From: black shadow Date: Tue, 22 Oct 2024 20:43:38 +0530 Subject: [PATCH 6/6] Added AI_animal_game and deleted the morse code and also created an seperate folder --- Game-Galore/{ => AI-Animal-Guess}/AI_Guess_Animal.py | 2 +- Game-Galore/AI-Animal-Guess/animals.json | 1 + Game-Galore/animals.json | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) rename Game-Galore/{ => AI-Animal-Guess}/AI_Guess_Animal.py (97%) create mode 100644 Game-Galore/AI-Animal-Guess/animals.json delete mode 100644 Game-Galore/animals.json diff --git a/Game-Galore/AI_Guess_Animal.py b/Game-Galore/AI-Animal-Guess/AI_Guess_Animal.py similarity index 97% rename from Game-Galore/AI_Guess_Animal.py rename to Game-Galore/AI-Animal-Guess/AI_Guess_Animal.py index c5e46ab..e8dffc6 100644 --- a/Game-Galore/AI_Guess_Animal.py +++ b/Game-Galore/AI-Animal-Guess/AI_Guess_Animal.py @@ -4,7 +4,7 @@ class AnimalGame: def __init__(self): # Load animal data from a JSON file or create a default one if it doesn't exist - self.folder_name = 'Game-Galore' + self.folder_name = 'Game-Galore/AI-Animal-Guess' self.data_file = os.path.join(self.folder_name, 'animals.json') self.animals = self.load_data() diff --git a/Game-Galore/AI-Animal-Guess/animals.json b/Game-Galore/AI-Animal-Guess/animals.json new file mode 100644 index 0000000..f49cabe --- /dev/null +++ b/Game-Galore/AI-Animal-Guess/animals.json @@ -0,0 +1 @@ +{"questions": {"mammal": "eyes"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]} \ No newline at end of file diff --git a/Game-Galore/animals.json b/Game-Galore/animals.json deleted file mode 100644 index e0cb57d..0000000 --- a/Game-Galore/animals.json +++ /dev/null @@ -1 +0,0 @@ -{"questions": {"mammal": "his hairs"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]} \ No newline at end of file