当前位置: 首页>>代码示例>>Python>>正文


Python ALEInterface.getScreen方法代码示例

本文整理汇总了Python中ale_python_interface.ALEInterface.getScreen方法的典型用法代码示例。如果您正苦于以下问题:Python ALEInterface.getScreen方法的具体用法?Python ALEInterface.getScreen怎么用?Python ALEInterface.getScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ale_python_interface.ALEInterface的用法示例。


在下文中一共展示了ALEInterface.getScreen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: type

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
#     ale.setBool('display_screen', True)

# Load the ROM file
ale.loadROM('Breakout.bin')

# Get the list of legal actions
# legal_actions = ale.getLegalActionSet()
legal_actions = ale.getMinimalActionSet()
print legal_actions

# (screen_width,screen_height) = ale.getScreenDims()
# screen_data = np.zeros(screen_width*screen_height,dtype=np.uint32)
# ale.getScreenRGB(screen_data)

(screen_width, screen_height) = ale.getScreenDims()
screen_data = np.zeros(screen_width * screen_height, dtype=np.uint8)
print type(ale.getScreen(screen_data))

# Play 10 episodes
for episode in xrange(10):

    total_reward = 0
    while not ale.game_over():
        a = legal_actions[randrange(len(legal_actions))]
        # Apply an action and get the resulting reward
        reward = ale.act(a)
        print  reward
        total_reward += reward
    print 'Episode', episode, 'ended with score:', total_reward
    ale.reset_game()
开发者ID:ElchinValiyev,项目名称:GameAI,代码行数:32,代码来源:qlearning_breakout.py

示例2: xrange

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
State1 = np.zeros([batchSize,network_size])
Action0 = np.zeros([batchSize])
Reward0 = np.zeros([batchSize])


for episode in xrange(maxEpisode):

    ale.reset_game()
    score = 0
    cost_average = 0.0
    frameCountLast = frameCount
    t0   = time.time()

    while not ale.game_over():

        imgBinary = Scale(ale.getScreen())
        if np.random.rand(1) > explorationRate:
            [actionIndex, actionValue] = forward([imgBinary],Q_train,  all=False)
        else:
            actionIndex = randrange(len(legal_actions))  # get action
        reward = ale.act(legal_actions[actionIndex])  # reward
        memory.append([imgBinary,actionIndex,reward])
        score += reward

        if frameCount >= startLearningFrame -1:
            index = np.random.permutation(len(memory) - 1)[0:batchSize]

            for i in xrange(batchSize):
                State0[i,:] = memory[index[i]][0]
                State1[i,:] = memory[index[i]+1][0]
                Action0[i] = memory[index[i]][1]
开发者ID:boluoweifenda,项目名称:DQN,代码行数:33,代码来源:copy+of+DQN.py

示例3: forward

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
def forward(input, all = False):
    actionValues = sess.run(y, feed_dict={x: input})
    if all is True:
        return actionValues
    actionValue_max= np.max(actionValues)
    index = np.argmax(actionValues,axis = 1)
    return [index, actionValue_max]





ale = ALEInterface()
ale.loadROM("Breakout.A26")
legal_actions = ale.getLegalActionSet()
img = ale.getScreen()
actionIndex = forward(img)
reward = ale.act(legal_actions(actionIndex))

# Get & Set the desired settings
ale.setInt('random_seed', 123)
ale.setInt("frame_skip",frameSkip)


# Set USE_SDL to true to display the screen. ALE must be compilied
# with SDL enabled for this to work. On OSX, pygame init is used to
# proxy-call SDL_main.
USE_SDL = True
if USE_SDL:
  if sys.platform == 'darwin':
    import pygame
开发者ID:boluoweifenda,项目名称:DQN,代码行数:33,代码来源:python_example.py

示例4: xrange

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
terminal = 1

# t0s = t1s = t2s = t3s = t4s =t5s =t6s=t7s= 0

ale.reset_game()

trainThread = threading.Thread(target=train)
trainThread.start()


for frameCount in xrange(maxFrame):

    t00 = time.time()

    lives = ale.lives()
    observe = Scale(ale.getScreen())  # 0.08s


    if terminal:
        actionIndex = 1
        # # a random start
        # ale.act(1)
        # for i in xrange(np.random.randint(0,maxRandomStartFrame)):
        #     ale.act(np.random.randint(len(legal_actions)))
        # ale.act(0)
        # actionIndex = 0
    else:
        if np.random.rand(1) > explorationRate:
            [actionIndex, actionValue] = forward([np.transpose(memory.History,[1,2,0])],Q_train,  all=False)
        else:
            actionIndex = np.random.randint(len(legal_actions))  # get action
开发者ID:boluoweifenda,项目名称:DQN,代码行数:33,代码来源:0722Light.py

示例5: xrange

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
ram_size = ale.getRAMSize()
ram=np.zeros((ram_size),dtype=np.uint8)
ale.getRAM(ram)
print ram[54:108]



(screen_width,screen_height) =ale.getScreenDims()
screen_data=np.zeros(screen_width*screen_height,dtype=np.uint32)

legal_actions = ale.getLegalActionSet()

# Play 10 episodes
for episode in xrange(10):
  total_reward = 0
  a=4
  while not ale.game_over():
    time.sleep(0.1)
    a = legal_actions[randrange(len(legal_actions))]
    reward = ale.act(a);
    total_reward += reward
    temp = [i for i in ram]
    ale.getRAM(ram)

      #print ram
    # print [temp[i]-ram[i] for i in range(len(ram))] 
    ale.getScreen(screen_data)
    print screen_data
  print 'Episode', episode, 'ended with score:', total_reward
  ale.reset_game()
开发者ID:sam1064max,项目名称:Arcade-Learning-Environment,代码行数:32,代码来源:cent.py

示例6: detect_maze

# 需要导入模块: from ale_python_interface import ALEInterface [as 别名]
# 或者: from ale_python_interface.ALEInterface import getScreen [as 别名]
  if sys.platform == 'darwin':
    import pygame
    pygame.init()
    ale.setBool('sound', False) # Sound doesn't work on OSX
  elif sys.platform.startswith('linux'):
    ale.setBool('sound', True)
  ale.setBool('display_screen', True)

# Load the ROM file
ale.loadROM(sys.argv[1])

# Get the list of legal actions
legal_actions = ale.getLegalActionSet()

# Play 10 episodes
screen = np.reshape(ale.getScreen(), (210, -1))
maze = detect_maze(screen)
image = pacman_image(maze)
# print_maze(maze)

for episode in xrange(1):
  total_reward = 0
  step = 1
  while not ale.game_over():
    # if step == 500:
    screen = np.reshape(ale.getScreen(), (210, -1))
    if step % 3 == 0:
      image.new_image(screen)
    a = legal_actions[randrange(len(legal_actions))]
    step += 1
    # Apply an action and get the resulting reward
开发者ID:rimcoharish,项目名称:Arcade-Learning-Environment,代码行数:33,代码来源:agent.py


注:本文中的ale_python_interface.ALEInterface.getScreen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。