Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gym
- import pygame
- from gym import spaces
- import numpy as np
- from MazeGameEnv import MazeGameEnv
- # Register the environment
- gym.register(
- id='MazeGameEnv',
- entry_point='MazeGameEnv:MazeGameEnv',
- kwargs={'maze': None}
- )
- #Maze config
- maze = [
- ['S', '', '.', '.'],
- ['.', '#', '.', '#'],
- ['.', '.', '.', '.'],
- ['#', '.', '#', 'G'],
- ]
- # Test the environment
- env = gym.make('MazeGameEnv',maze=maze)
- obs,_ = env.reset()
- env.render()
- done = False
- while True:
- pygame.event.get()
- action = env.action_space.sample() # Random action selection
- obs, reward, done, _ = env.step(action)
- env.render()
- if done:
- print('Reward:', reward)
- print('Done:', done)
- print("the Game has been completed")
- break
- print('Reward:', reward)
- print('Done:', done)
- pygame.time.wait(200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement