Animal game v.2 with gui

import tkinter as tk
from tkinter import simpledialog, messagebox
import pickle
import os

class Node:
    def __init__(self, question=None, animal=None):
        self.question = question
        self.animal = animal
        self.yes = None
        self.no = None

    def is_leaf(self):
        return self.animal is not None

class AnimalGuesserApp:
    def __init__(self, master):
        self.master = master
        self.master.title(“Animal Guesser”)
        self.master.geometry(“500×300”)
        self.master.option_add(“*Font”, “Arial 16”)

        self.label = tk.Message(master, text=””, width=460)
        self.label.pack(pady=30)

        btn_frame = tk.Frame(master)
        btn_frame.pack()

        self.yes_button = tk.Button(btn_frame, text=”Yes”, width=10, command=self.handle_yes)
        self.no_button = tk.Button(btn_frame, text=”No”, width=10, command=self.handle_no)

        self.yes_button.pack(side=”left”, padx=20)
        self.no_button.pack(side=”right”, padx=20)

        self.tree = self.load_tree()
        self.current_node = self.tree
        self.parent_stack = []  # Track the path for updating
        self.mode = “ask”  # ask / learn / done

        self.display_current()

    def display_current(self):
        if self.current_node.is_leaf():
            self.label.config(text=f”Is it a {self.current_node.animal}?”)
            self.mode = “guess”
        else:
            self.label.config(text=self.current_node.question)
            self.mode = “ask”

    def handle_yes(self):
        if self.mode == “ask”:
            self.parent_stack.append((self.current_node, True))
            self.current_node = self.current_node.yes
            self.display_current()

        elif self.mode == “guess”:
            self.label.config(text=”Yay! I guessed it!\nPlay again?”)
            self.mode = “done”

        elif self.mode == “done”:
            self.reset_game()

        elif self.mode == “learn_step2”:
            # user answered yes to: “for the new animal, what’s the answer?”
            self.insert_new_knowledge(True)

    def handle_no(self):
        if self.mode == “ask”:
            self.parent_stack.append((self.current_node, False))
            self.current_node = self.current_node.no
            self.display_current()

        elif self.mode == “guess”:
            self.start_learning()

        elif self.mode == “done”:
            self.master.quit()

        elif self.mode == “learn_step2”:
            # user answered no to: “for the new animal, what’s the answer?”
            self.insert_new_knowledge(False)

    def start_learning(self):
        self.new_animal = simpledialog.askstring(“Teach me”, “I give up! What animal were you thinking of?”)
        if not self.new_animal:
            self.label.config(text=”Okay, I’ll try better next time.\nPlay again?”)
            self.mode = “done”
            return

        self.new_question = simpledialog.askstring(“Help me learn”, f”Give me a yes/no question to tell a {self.new_animal} from a {self.current_node.animal}”)
        if not self.new_question:
            self.label.config(text=”No worries. Want to play again?”)
            self.mode = “done”
            return

        self.label.config(text=f”For a {self.new_animal}, what is the answer to your question?”)
        self.mode = “learn_step2”

    def insert_new_knowledge(self, new_animal_answer_yes):
        new_node = Node(question=self.new_question)
        if new_animal_answer_yes:
            new_node.yes = Node(animal=self.new_animal)
            new_node.no = self.current_node
        else:
            new_node.no = Node(animal=self.new_animal)
            new_node.yes = self.current_node

        # Attach new node to parent
        if self.parent_stack:
            parent, went_yes = self.parent_stack[-1]
            if went_yes:
                parent.yes = new_node
            else:
                parent.no = new_node
        else:
            self.tree = new_node  # Root replaced

        self.save_tree()
        self.label.config(text=”Thanks! I’ve learned something new.\nPlay again?”)
        self.mode = “done”

    def reset_game(self):
        self.current_node = self.tree
        self.parent_stack = []
        self.display_current()

    def save_tree(self, filename=”animal_tree.pkl”):
        with open(filename, “wb”) as f:
            pickle.dump(self.tree, f)

    def load_tree(self, filename=”animal_tree.pkl”):
        if os.path.exists(filename):
            with open(filename, “rb”) as f:
                return pickle.load(f)
        else:
            return Node(animal=”cat”)

if __name__ == “__main__”:
    root = tk.Tk()
    app = AnimalGuesserApp(root)
    root.mainloop()

Animal game (using pickle) in pydroid

import pickle
import os

class Node:
    def __init__(self, question=None, animal=None):
        self.question = question
        self.animal = animal
        self.yes = None
        self.no = None

    def is_leaf(self):
        return self.animal is not None

def ask_yes_no(prompt):
    while True:
        ans = input(prompt + ” (y/n): “).strip().lower()
        if ans in [‘y’, ‘yes’]:
            return True
        elif ans in [‘n’, ‘no’]:
            return False
        print(“Please enter y or n.”)

def play(node):
    if node.is_leaf():
        if ask_yes_no(f”Is it a {node.animal}?”):
            print(“Yay! I guessed it!”)
            return node
        else:
            return learn(node)
    else:
        if ask_yes_no(node.question):
            node.yes = play(node.yes)
        else:
            node.no = play(node.no)
        return node

def learn(old_node):
    new_animal = input(“I give up! What animal were you thinking of? “).strip()
    question = input(f”Give me a yes/no question to tell a {new_animal} from a {old_node.animal}: “).strip()
    if ask_yes_no(f”For a {new_animal}, what is the answer to your question?”):
        new_node = Node(question=question)
        new_node.yes = Node(animal=new_animal)
        new_node.no = old_node
    else:
        new_node = Node(question=question)
        new_node.no = Node(animal=new_animal)
        new_node.yes = old_node
    print(“Thanks! I’ll remember that.”)
    return new_node

def save_tree(tree, filename=”animal_tree.pkl”):
    with open(filename, “wb”) as f:
        pickle.dump(tree, f)

def load_tree(filename=”animal_tree.pkl”):
    if os.path.exists(filename):
        with open(filename, “rb”) as f:
            return pickle.load(f)
    else:
        # Start with a default animal
        return Node(animal=”cat”)

def main():
    print(“Think of an animal, and I’ll try to guess it!”)
    tree = load_tree()
    tree = play(tree)
    save_tree(tree)

if __name__ == “__main__”:
    while True:
        main()
        if not ask_yes_no(“Play again?”):
            break

Bat flying test pydroid

import pygame
import math
import sys

# Initialize Pygame
pygame.init()

# Set screen size
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(“Flying Bat”)

clock = pygame.time.Clock()

# Bat position
x = 0
y = HEIGHT // 2

# Wing flap variables
wing_angle = 0
flap_speed = 0.15

# Colors
BLACK = (0, 0, 0)
DARK_GREY = (50, 50, 50)
WHITE = (255, 255, 255)

def draw_bat(surface, x, y, angle):
    body_width = 40
    body_height = 20

    # Draw bat body
    pygame.draw.ellipse(surface, DARK_GREY, (x, y, body_width, body_height))

    # Left wing
    left_points = [
        (x + 10, y + 10),
        (x – 30, y – 10 – int(math.sin(angle) * 20)),
        (x – 10, y + 10),
    ]
    pygame.draw.polygon(surface, DARK_GREY, left_points)

    # Right wing
    right_points = [
        (x + 30, y + 10),
        (x + 70, y – 10 – int(math.sin(angle) * 20)),
        (x + 50, y + 10),
    ]
    pygame.draw.polygon(surface, DARK_GREY, right_points)

# Main loop
running = True
while running:
    screen.fill(BLACK)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Animate
    wing_angle += flap_speed
    x += 3
    if x > WIDTH:
        x = -60  # Reset when offscreen

    draw_bat(screen, x, y + int(math.sin(wing_angle) * 10), wing_angle)

    pygame.display.flip()
    clock.tick(60)

pygame.quit()
sys.exit()

20635

August 2nd — morning washed past unnoticed, the alarm dismissed or never heard, sunlight already pooling golden across the floorboards when I finally stirred. No rush to remedy it. No guilt, either. Just the soft stretch of limbs and the rumble of a hungry cat beside me, kneading the blanket like she was trying to start a fire.

Stayed in, mostly. Let the outside world whirl on without me. It can do that sometimes — spin its errands and alerts, calls and clicks — while I remain in sanctuary. A thick book in hand, the one with the creased spine and the smell of old paper. Stories folded in like origami secrets, each page a quiet hour.

Cat got her zoomies around noon. Dashed from one end of the apartment to the other like a tiny lion with invisible prey. He’s learned how to open cabinet doors, now. Keeps trying to break into the snacks — smart paws, soft menace.

Shared a little tuna as a peace offering. Sge forgave the late breakfast.

No mail worth mentioning. No visitors. Just the wind at the window and the occasional creak of a settling building. Sometimes, the best days don’t go anywhere. They just hold still and let you breathe.