Moved Python code to its directory
This commit is contained in:
parent
926cbda034
commit
48b579d152
2 changed files with 0 additions and 0 deletions
70
python/motives.py
Normal file
70
python/motives.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Aside from a few item fixes, this is all generated by AI
|
||||
import random
|
||||
import time
|
||||
|
||||
class Sim:
|
||||
# Define the initial values for the motives
|
||||
MOODS = {
|
||||
'Hunger': 1.0, # Normal hunger decay per minute
|
||||
'Bladder': 1.0, # Normal bladder decay per minute
|
||||
'Energy': 1.0, # Normal energy decay per minute
|
||||
'Social': 0.5, # Social needs build up slower
|
||||
'Hygiene': 1.0, # Normal hygiene decay per minute
|
||||
'Fun': 0.5 # Fun needs build up slower
|
||||
}
|
||||
|
||||
# Define the items in the environment and their effects on the Sim's motives
|
||||
ITEMS = {
|
||||
'Bed': {'Energy': 3.0, 'Bladder': -0.2}, # Restores energy but slightly increases bladder pressure
|
||||
'Toilet': {'Bladder': 3.0, 'Hygiene': -0.5}, # Reduces bladder pressure but needs a bit of cleaning
|
||||
'Fridge': {'Hunger': 2.0, 'Hygiene': 0.1}, # Reduces hunger but slightly impacts hygiene
|
||||
'Laptop': {'Social': 2.0, 'Fun': 2.0}, # Reduces social need and provides fun
|
||||
'Shower': {'Hygiene': 3.0}, # Increases hygiene significantly
|
||||
'Gym': {'Hygiene': 0.5, 'Energy': -1.5, 'Fun': 2.0} # Increases hygiene, drains energy but provides fun
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
# Initialize motives to full
|
||||
self.motives = {motive: random.randint(50,90) for motive in self.MOODS}
|
||||
|
||||
def simulate_minute(self):
|
||||
# Update motives based on natural decay
|
||||
for motive, decay in self.MOODS.items():
|
||||
self.motives[motive] -= decay
|
||||
|
||||
# Choose an item to affect the Sim's motives
|
||||
self.use_item()
|
||||
|
||||
# Enforce motive limits
|
||||
for motive in self.motives:
|
||||
self.motives[motive] = max(self.motives[motive], 0.0)
|
||||
self.motives[motive] = min(self.motives[motive], 100.0)
|
||||
|
||||
def use_item(self):
|
||||
item = random.choice(list(self.ITEMS.keys()))
|
||||
print(f"Time passes, Sim uses: {item}")
|
||||
for motive, effect in self.ITEMS[item].items():
|
||||
self.motives[motive] += effect
|
||||
print(f" {motive}: {'+' if effect > 0 else ''}{effect}")
|
||||
|
||||
def show_motives(self):
|
||||
# Display the current state of the Sim's motives
|
||||
print("Sim's Motives:")
|
||||
for motive, value in self.motives.items():
|
||||
print(f" {motive}: {value:.2f}")
|
||||
|
||||
def simulate_time(sim, total_minutes):
|
||||
# Simulate over the given number of minutes
|
||||
for minute in range(1, total_minutes + 1):
|
||||
print(f"\nMinute {minute}:")
|
||||
sim.show_motives()
|
||||
sim.simulate_minute()
|
||||
# Simulate a short delay between each minute
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Starting Sim Motive Simulation...")
|
||||
sim = Sim()
|
||||
simulate_time(sim, 10) # Simulate 10 minutes
|
||||
sim.show_motives()
|
||||
print("Simulation completed.")
|
112
python/snake.py
Normal file
112
python/snake.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
# Generated by AI
|
||||
import pygame
|
||||
import random
|
||||
import sys
|
||||
|
||||
# Initialize pygame
|
||||
pygame.init()
|
||||
|
||||
# Constants for the game
|
||||
SCREEN_WIDTH, SCREEN_HEIGHT = 640, 480
|
||||
CELL_SIZE = 20
|
||||
GRID_WIDTH, GRID_HEIGHT = SCREEN_WIDTH // CELL_SIZE, SCREEN_HEIGHT // CELL_SIZE
|
||||
FPS = 10 # Game speed
|
||||
|
||||
# Colors
|
||||
BLACK = (0, 0, 0)
|
||||
WHITE = (255, 255, 255)
|
||||
GREEN = (0, 255, 0)
|
||||
RED = (255, 0, 0)
|
||||
|
||||
# Directions
|
||||
UP = (0, -1)
|
||||
DOWN = (0, 1)
|
||||
LEFT = (-1, 0)
|
||||
RIGHT = (1, 0)
|
||||
|
||||
class SnakeGame:
|
||||
def __init__(self):
|
||||
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
pygame.display.set_caption('Snake Game')
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
self.snake = [(GRID_WIDTH // 2, GRID_HEIGHT // 2)]
|
||||
self.snake_direction = RIGHT
|
||||
self.grow = False # Flag for growing the snake
|
||||
self.place_food()
|
||||
|
||||
def place_food(self):
|
||||
"""Place the food at a random position on the grid."""
|
||||
self.food = (random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1))
|
||||
while self.food in self.snake: # Ensure food is not placed on the snake
|
||||
self.food = (random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1))
|
||||
|
||||
def move_snake(self):
|
||||
"""Move the snake one cell in the current direction."""
|
||||
head_x, head_y = self.snake[0]
|
||||
new_head = (head_x + self.snake_direction[0], head_y + self.snake_direction[1])
|
||||
if self.grow:
|
||||
self.snake.insert(0, new_head) # Grow the snake
|
||||
else:
|
||||
self.snake.insert(0, new_head) # Move the head
|
||||
self.snake.pop() # Remove the tail
|
||||
self.grow = False
|
||||
|
||||
# Detect collisions with the walls
|
||||
if not (0 <= new_head[0] < GRID_WIDTH) or not (0 <= new_head[1] < GRID_HEIGHT):
|
||||
self.game_over()
|
||||
|
||||
# Detect collisions with the snake itself
|
||||
if new_head in self.snake[1:]:
|
||||
self.game_over()
|
||||
|
||||
def check_food_collision(self):
|
||||
"""Check if the snake has eaten the food."""
|
||||
if self.snake[0] == self.food:
|
||||
self.place_food()
|
||||
self.grow = True
|
||||
|
||||
def draw(self):
|
||||
"""Draw the game state to the screen."""
|
||||
self.screen.fill(BLACK)
|
||||
for segment in self.snake:
|
||||
pygame.draw.rect(self.screen, GREEN, (segment[0] * CELL_SIZE, segment[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
|
||||
pygame.draw.rect(self.screen, RED, (self.food[0] * CELL_SIZE, self.food[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
|
||||
pygame.display.flip()
|
||||
|
||||
def game_over(self):
|
||||
"""Handle the game over scenario."""
|
||||
self.screen.fill(BLACK)
|
||||
font = pygame.font.SysFont(None, 72)
|
||||
text = font.render("Game Over", True, WHITE)
|
||||
text_rect = text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
|
||||
self.screen.blit(text, text_rect)
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(2000)
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
def run(self):
|
||||
"""Main game loop."""
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.game_over()
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_UP and self.snake_direction != DOWN:
|
||||
self.snake_direction = UP
|
||||
elif event.key == pygame.K_DOWN and self.snake_direction != UP:
|
||||
self.snake_direction = DOWN
|
||||
elif event.key == pygame.K_LEFT and self.snake_direction != RIGHT:
|
||||
self.snake_direction = LEFT
|
||||
elif event.key == pygame.K_RIGHT and self.snake_direction != LEFT:
|
||||
self.snake_direction = RIGHT
|
||||
|
||||
self.move_snake()
|
||||
self.check_food_collision()
|
||||
self.draw()
|
||||
self.clock.tick(FPS)
|
||||
|
||||
if __name__ == '__main__':
|
||||
game = SnakeGame()
|
||||
game.run()
|
Loading…
Add table
Add a link
Reference in a new issue