Advertisement
kingbode

Untitled

Oct 20th, 2023
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1.  
  2. import gym
  3. import pygame
  4. from gym import spaces
  5. import numpy as np
  6. from MazeGameEnv import MazeGameEnv
  7.  
  8. # Register the environment
  9. gym.register(
  10.     id='MazeGameEnv',
  11.     entry_point='MazeGameEnv:MazeGameEnv',
  12.     kwargs={'maze': None}
  13. )
  14.  
  15.  
  16. #Maze config
  17. maze = [
  18.     ['S', '', '.', '.'],
  19.     ['.', '#', '.', '#'],
  20.     ['.', '.', '.', '.'],
  21.     ['#', '.', '#', 'G'],
  22. ]
  23. # Test the environment
  24. env = gym.make('MazeGameEnv',maze=maze)
  25. obs,_ = env.reset()
  26. env.render()
  27.  
  28. done = False
  29. while True:
  30.     pygame.event.get()
  31.     action = env.action_space.sample()  # Random action selection
  32.     obs, reward, done, _ = env.step(action)
  33.     env.render()
  34.     if done:
  35.         print('Reward:', reward)
  36.         print('Done:', done)
  37.         print("the Game has been completed")
  38.         break
  39.  
  40.     print('Reward:', reward)
  41.     print('Done:', done)
  42.  
  43.     pygame.time.wait(200)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement