Example #1
0
def TrainSmallAgent(NrGames, writeOn, savePath, show=False):
    from SmallAgent import SmallAgent as Agent

    #make the enviroment
    env = Enviroment(fullImage=False, enhancedReward=True, autoFire=True)
    if (show):
        env.reset()
        env.render()

    agent = Agent()

    #see how many times to save the agent
    NrBatches = int(NrGames / float(writeOn)) + 1

    #Train some games then save the results keep repeating until all number of games have been played
    for i in range(NrBatches):
        print "batch", i, "of", NrBatches
        #train the agent
        reward, steps = trainAgent(env, agent, writeOn, show=show)

        #save the itermediate agent
        agent.save(savePath + "_" + str(i * writeOn))

        #save the stats
        f = open(savePath, 'a')
        for r, s in zip(reward, steps):
            f.write(str(r) + "," + str(s) + '\n')
        f.close()

        env.makeVideo(savePath + "_" + str(i * writeOn) + ".gif")
Example #2
0
def TrainLargeAgent(NrGames, writeOn, savePath, show=False):
    from LargeAgent import LargeAgent as Agent

    #make the enviroment
    env = Enviroment(enhancedReward=True, autoFire=True)
    #because of the influence of tensorflow draw the enviroment once before making any call to tensorflow of don't draw at all
    if (show):
        env.reset()
        env.render()

    #make the agent
    agent = Agent()

    #see how many times to save the agent
    NrBatches = int(NrGames / float(writeOn)) + 1

    totalNrFrames = 0
    #Train some games then save the results keep repeating until all number of games have been played
    for i in range(NrBatches):
        print "batch", i, "of", NrBatches
        #train the agent
        reward, steps = trainAgent(env, agent, writeOn, show=show)

        totalNrFrames += np.sum(steps)
        #save the itermediate agent
        agent.save(savePath + "_" + str(i * writeOn))

        #save the stats
        f = open(savePath, 'a')
        for r, s in zip(reward, steps):
            f.write(str(r) + "," + str(s) + '\n')
        f.close()

        env.makeVideo(savePath + "_" + str(i * writeOn) + ".gif")
Example #3
0
                 'w'))
        json.dump(
            self.actionTable,
            open("./" + folder + '/' + filename + '/' + filename + "act.table",
                 'w'))
        # "./" + folder + '/' + filename + '/' + filename)


if (__name__ == "__main__"):
    import time
    from Eviroment import Enviroment

    env = Enviroment(gameMode="vector2", rewardMode="follow", autoFire=True)

    agent = DoraAgent(double=True)

    action = 0

    frame = -1
    skipFrame = 1

    done = False
    S = env.reset()
    while not done:
        frame += 1
        if (frame % skipFrame == 0):
            action = agent.getAction(S)
        S, r, done, info = env.step(action)
        time.sleep(0.5)
        env.render()
    print "game evaluation: ", env.reward
Example #4
0
from Eviroment import Enviroment
import numpy as np

if(__name__ == "__main__"):
  from SmallAgent import SmallAgent as Agent
  show = False
  
  #make the enviroment
  env = Enviroment(fullImage=False,enhancedReward=True,autoFire=True)
  if(show):
    env.reset()
    env.render()
  
  agent = Agent.load('')
  
  write = 0
  
  rweards = []
  for i in range(500):
    S = env.reset()
    done = False
    while not done:
      action = agent.getAction(S)
      Snew,reward,done,info = env.step(action)
      agent.update(S,action,Snew,reward,done)
      S = Snew
      if(show):
	env.render()
    if(write == 0):
      write = 1
      env.makeVideo('./randomMovement.gif')