Files
lab_retro/asteroid_spawner.py
caglazir 9a4ef2eb8d This program differed from Unit 1 programs because
it felt more foreign, if that makes sense. The code used in this program
was not my work hence, I did not feel as though I completely understood how
each agent was doing what it was doing. I guess I can see the value of
agents because they really do cut things short and functional. But I much
prefer the labs and programs that had more original input for the learning
experience! At this stage I don't know if I am comfortable or confident going
into the game project but I will try to think more about the agents
to understand better.
2025-12-01 21:31:36 -05:00

19 lines
576 B
Python

# 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
game.state['score'] += 1
if self.should_spawn_asteroid(game.turn_number):
asteroid = Asteroid((randint(0, width - 1), 0))
game.add_agent(asteroid)
def should_spawn_asteroid(self, turn_number):
return randint(0, 1000) < turn_number