Hi I am creating genetic algorithm for solving snake game. I have Game
class, it has implemented all snake game logic. I use it to evaluate every Snake
in population.
I am generating random snacks for snake in game. But I need a way to generate the same random snacks positions for every new Game
instance, so each snake in population will be evaluated in the same environment.
class Game:
def __init__(self, width, height, phenotype, seed, game_representation_strategy,
snake_length=5, snack_eaten_points=1, moved_toward_snack_points=0.1,
moved_away_from_snack_points=-0.2):
self.width = width
self.height = height
self.phenotype = phenotype
self.seed = seed
self.game_representation_strategy = game_representation_strategy
self.snack_perspective = None
self.snack_eaten_points = snack_eaten_points
self.moved_toward_snack_points = moved_toward_snack_points
self.moved_away_from_snack_points = moved_away_from_snack_points
self.status = GameStatus.INITIALIZED
self.snack = None
self.snake = []
self.score = 0
self.direction = Direction.LEFT
self.last_snack_distance = 0
self.initialize_snake(snake_length)
self.initialize_snack()
self.initialize_last_snack_distance()
Aucun commentaire:
Enregistrer un commentaire