Skip to content

[Added Morse Code 🚀] : Added the morse code #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions Game-Galore/AI-Animal-Guess/AI_Guess_Animal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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.folder_name = 'Game-Galore/AI-Animal-Guess'
self.data_file = os.path.join(self.folder_name, '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.






1 change: 1 addition & 0 deletions Game-Galore/AI-Animal-Guess/animals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"questions": {"mammal": "eyes"}, "animals": ["dog", "cat", "elephant", "tiger", "lion", "rabbit", "fish", "tiger"]}