To create a complex evolution simulator that is visually appealing and includes god mode powers and tooltips, follow these steps:
-
Define Organisms: Create organisms with various attributes determined by their genes, such as size, speed, color, vision range, and energy.
-
Genetics System: Implement a genetics system where each organism has a set of genes that determine its traits. Include mechanisms for mutation during reproduction.
-
Environment: Design an environment where organisms can interact. This could be a 2D grid or a more complex space with resources like food.
-
Simulation Loop: Develop a main loop that updates the state of organisms, handles interactions, and updates the environment. This loop should also manage the reproduction and mutation of organisms.
-
Visualization: Use a graphical library like Pygame to create a visually appealing interface. Ensure that the organisms and their interactions are visually distinct and engaging.
-
God Mode Powers: Implement controls that allow the user to interact with the simulation. This could include adding or removing organisms, changing environmental conditions, and directly editing the genes of organisms.
-
Tooltips: Add tooltips that display detailed information about an organism when it is hovered over or clicked. This information should include genes, senses, and morphology.
Here is a simplified example in Python using Pygame to illustrate these concepts:
import pygame
import random
import math
# Initialize pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Evolution Simulator")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Organism class
class Organism:
def __init__(self, x, y, genes=None):
self.x = x
self.y = y
if genes is None:
# Generate random genes if none provided
self.genes = {
'size': random.randint(5, 20),
'speed': random.randint(1, 5),
'color': (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
'vision_range': random.randint(10, 100),
'energy': 100
}
else:
self.genes = genes
def move(self):
# Simple movement: move in a random direction based on speed
direction = random.uniform(0, 2 * math.pi)
self.x += self.genes['speed'] * math.cos(direction)
self.y += self.genes['speed'] * math.sin(direction)
# Boundary check
self.x = max(0, min(WIDTH, self.x))
self.y = max(0, min(HEIGHT, self.y))
def eat(self, food_list):
# Check if there's food nearby and eat it
for food in food_list[:]:
distance = math.sqrt((self.x - food['x'])**2 + (self.y - food['y'])**2)
if distance < self.genes['vision_range']:
food_list.remove(food)
self.genes['energy'] += 20
break
def reproduce(self):
# If enough energy, reproduce
if self.genes['energy'] > 150:
self.genes['energy'] -= 100
# Create a new organism with slightly mutated genes
new_genes = self.genes.copy()
for key in new_genes:
if key != 'color' and key != 'energy':
new_genes[key] += random.randint(-2, 2) # Simple mutation
if key == 'size':
new_genes[key] = max(5, min(20, new_genes[key]))
elif key == 'speed':
new_genes[key] = max(1, min(5, new_genes[key]))
elif key == 'vision_range':
new_genes[key] = max(10, min(100, new_genes[key]))
return Organism(self.x, self.y, new_genes)
return None
def update(self, food_list):
self.move()
self.eat(food_list)
self.genes['energy'] -= 1 # Energy decreases over time
if self.genes['energy'] <= 0:
return None # Organism dies
return self.reproduce()
def draw(self, screen):
pygame.draw.circle(screen, self.genes['color'], (int(self.x), int(self.y)), self.genes['size'])
# Food class
class Food:
def __init__(self, x, y):
self.x = x
self.y = y
def draw(self, screen):
pygame.draw.circle(screen, GREEN, (int(self.x), int(self.y)), 5)
# Main simulation class
class EvolutionSimulator:
def __init__(self):
self.organisms = [Organism(random.randint(0, WIDTH), random.randint(0, HEIGHT)) for _ in range(10)]
self.food = [Food(random.randint(0, WIDTH), random.randint(0, HEIGHT)) for _ in range(50)]
self.running = True
self.god_mode = False
self.selected_organism = None
def handle_events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_g:
self.god_mode = not self.god_mode
elif event.type == pygame.MOUSEBUTTONDOWN and self.god_mode:
mouse_x, mouse_y = pygame.mouse.get_pos()
# Check if clicked on an organism
for org in self.organisms:
distance = math.sqrt((org.x - mouse_x)**2 + (org.y - mouse_y)**2)
if distance < org.genes['size']:
self.selected_organism = org
break
else:
# If not clicked on an organism, add a new one
self.organisms.append(Organism(mouse_x, mouse_y))
def update(self):
# Update organisms
new_organisms = []
for org in self.organisms[:]:
new_org = org.update(self.food)
if new_org is not None:
new_organisms.append(new_org)
if org.genes['energy'] <= 0:
self.organisms.remove(org)
self.organisms.extend(new_organisms)
# Add new food randomly
if random.random() < 0.1:
self.food.append(Food(random.randint(0, WIDTH), random.randint(0, HEIGHT)))
def draw(self):
screen.fill(WHITE)
for food in self.food:
food.draw(screen)
for org in self.organisms:
org.draw(screen)
# Draw tooltip if organism is selected
if self.selected_organism == org and self.god_mode:
font = pygame.font.SysFont(None, 24)
tooltip = f"Size: {org.genes['size']}, Speed: {org.genes['speed']}, Vision: {org.genes['vision_range']}, Energy: {org.genes['energy']}"
text = font.render(tooltip, True, BLACK)
screen.blit(text, (org.x + 20, org.y + 20))
pygame.display.flip()
def run(self):
clock = pygame.time.Clock()
while self.running:
self.handle_events()
self.update()
self.draw()
clock.tick(30) # 30 FPS
pygame.quit()
# Run the simulation
if __name__ == "__main__":
sim = EvolutionSimulator()
sim.run()
This code provides a basic framework for an evolution simulator with organisms that can move, eat, and reproduce. The god mode allows adding new organisms and viewing their genes. Tooltips display the genes of selected organisms. This can be expanded with more complex genetics, behaviors, and visuals to create a more sophisticated simulator.
To enhance this simulator, consider adding more complex genetics, a richer environment, more detailed visuals, and additional god mode powers. This will make the simulator more engaging and visually appealing.