Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import numpy as np
  2. from ple import PLE
  3. from ple.games.snake import Snake
  4.  
  5.  
  6. class NaiveAgent():
  7. """
  8. This is our naive agent. It picks actions at random!
  9. """
  10.  
  11. def __init__(self, p):
  12. #self.actions = actions
  13. #self.states = states
  14. self.instanta = p
  15.  
  16. def pickAction(self, reward):
  17. print(self.instanta.getActionSet())
  18. print(self.instanta.getGameState())
  19. self.actions = self.instanta.getActionSet()
  20. return self.actions[np.random.randint(0, len(self.actions))]
  21. #return self.actions[np.argmax(np.array(list(filter(lambda x: type(x) is int,self.actions))))]
  22.  
  23.  
  24.  
  25. game = Snake(width=200,height=200)
  26.  
  27.  
  28. reward = 0.0
  29. #max_noops = 20
  30. #nb_frames = 15000
  31.  
  32.  
  33. p = PLE(game,fps=30,force_fps=False, display_screen=True,frame_skip=10)
  34.  
  35. agent = NaiveAgent(p)
  36.  
  37. p.init()
  38.  
  39. # lets do a random number of NOOP's
  40. #for i in range(np.random.randint(0, max_noops)):
  41. # reward = p.act(p.NOOP)
  42.  
  43. # start our training loop
  44. for f in range(1000):
  45. # if the game is over
  46. if p.game_over():
  47. p.reset_game()
  48.  
  49. #print(p.getScreenDims())
  50. #obs = p.getScreenRGB()
  51. action = agent.pickAction(reward)
  52. #print("am ajuns aici")
  53. reward = p.act(action)
  54. #print(reward)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement