# asteroid_spawner.py # ------------------- # By MWC Contributors # This module defines an AsteroidSpawner agent class. from random import randint from asteroid import Asteroid class AsteroidSpawner: display = False def play_turn(self, game): width, height = game.board_size # Increase score each turn survived game.state['score'] += 1 if self.should_spawn_asteroid(game.turn_number): # Random x position at the top x = randint(0, width - 1) # Random speed: 1 = fast, 2–3 = slower speed = randint(1, 3) asteroid = Asteroid((x, 0), speed) game.add_agent(asteroid) def should_spawn_asteroid(self, turn_number): # More asteroids as the game goes on return randint(0, 1000) < turn_number