def step(self, action_index: int, real_snake: bool) -> Tuple['Board', int, bool]: action = Dir.ALL[action_index] next_snake, is_alive = self.snake.move(action) next_board = Board(self.apples, next_snake) if not is_alive: if real_snake: print('Death!') next_board.reset() reward = -1 elif self.snake.head in self.apples: if real_snake: print('Apple!') next_board.apples.remove(self.snake.head) next_board.apples.append(Pos.random()) next_snake.grow() reward = 1 else: reward = 0 return next_board, reward, is_alive
def random_apples(cls) -> List[Pos]: return [Pos.random() for i in range(cls.APPLES)]
def random(cls) -> 'Snake': pos = Pos.random() return Snake([pos for i in range(6)])