Я пытаюсь извлечь кадры из моего ранее закодированного модуля pygames, чтобы обучить на нем агента RL. Однако я не уверен, как извлекать кадры из игрового движка.
В частности, я просмотрел это и нашел это сообщение в блоге, однако я действительно не понимаю, как я могу получить доступ к pygame.display и обернуть его, не взламывая основной цикл моего игрового объекта.
https://danielslater.net/2015/12/29/how-to-run-learning-agents-against-pygame/
Это игра, из которой я пытаюсь извлечь кадры: https://github.com/Jh123x/Orbital/blob/master/Space%20Invaders/classes/game.py
Могу я получить совет, как это сделать?
edit: Точнее, как мне вызвать функцию для извлечения кадров из игрового цикла во время его работы?
код экстрактора кадров
import pygame
import pygame.surfarray
# function that we can give two functions to and will return us a new function that calls both
def function_combine(screen_update_func, our_intercepting_func):
def wrap(*args, **kwargs):
screen_update_func(*args,
**kwargs) # call the screen update func we intercepted so the screen buffer is updated
our_intercepting_func() # call our own function to get the screen buffer
return wrap
def on_screen_update():
surface_array = pygame.surfarray.array3d(pygame.display.get_surface())
print("We got the screen array")
print(surface_array)
# set our on_screen_update function to always get called whenever the screen updated
pygame.display.update = function_combine(pygame.display.update, on_screen_update)