Gridworld-wall0

W W W W W W W W W W W W W W W W W W W W W W W W
W         35 W     42     W   5 43   W 1     47   W
W   6 2     W   14     27 W               7     W
W   46       W           W     32   W     21     W
W W W W W   W W W   W W W   W W W W W W W W W W
W     41 W                             W   48   W
W 15     W                                 8   W
W     31 W     W W W   W W W W W W     W 28     W
W   50         W   24         16   W     W W W W W
W W W W W     W         25   23   W     W       W
W     30 W     W W W W W W W W W W     W 29     W
W 10           W   17   W   20     W     W 9   22 W
W     40 W     W     18 W 19   49         W       W
W W W W W     W W   W W W W W W W     W W   W W
W                                             W
W                                             W
W W   W W W W   W W W W W W W   W W W W W W W W
W     39   W         38   W 37       W   36     13 W
W     3   W     11       W     12         4     W
W   26     W 44       34   W     33   W   45       W
W W W W W W W W W W W W W W W W W W W W W W W W

gym更新: 0.10.5: Env方法改  _seed(), _step(), _reset(), _render() 去下划线

gym.make('WallGridworld-v0')

'''
@ E.C.Ares
# MixedGridworldEnv-01
'''

import gym
from gym import spaces
import numpy as np



# environment
class MixedGridworldEnv(gym.Env):

    def __init__(self):
        self.height = 21
        self.width = 24
        self.action_space = spaces.Discrete(4)
        self.observation_space = spaces.Tuple((
                spaces.Discrete(self.height),
                spaces.Discrete(self.width)
                ))
        self.moves = {
                0: (1, 0),   # down
                1: (0, -1),   # left
                2: (-1, 0),  # up
                3: (0, 1),  # right
                }
        self.wallset = {(1,6), (1,12), (1,17), (2,6), (2,12), (3,6), (3,12), (3,17), (4,1), (4,2), (4,3), (4,4), (4,6), (4,7), (4,8), (4,10), (4,11), (4,12), (4,14), (4,15), (4,16), (4,17), (4,18), (4,19), (4,20), (4,21), (4,22), (5,4), (5,19), (6,4), (7,4), (7,7), (7,8), (7,9), (7,11), (7,12), (7,13), (7,14), (7,15), (7,16), (7,19), (8,7), (8,16), (8,19), (8,20), (8,21), (8,22), (9,1), (9,2), (9,3), (9,4), (9,7), (9,16), (9,19), (10,4), (10,7), (10,8), (10,9), (10,10), (10,11), (10,12), (10,13), (10,14), (10,15), (10,16), (10,19), (11,7), (11,11), (11,16), (11,19), (12,4), (12,7), (12,11), (12,19), (13,1), (13,2), (13,3), (13,4), (13,7), (13,8), (13,10), (13,11), (13,12), (13,13), (13,14), (13,15), (13,16), (13,19), (13,20), (13,22), (16,1), (16,3), (16,4), (16,5), (16,6), (16,8), (16,9), (16,10), (16,11), (16,12), (16,13), (16,14), (16,16), (16,17), (16,18), (16,19), (16,20), (16,21), (16,22), (17,5), (17,12), (17,17), (18,5), (18,12), (19,5), (19,12), (19,17)} 

        # begin in start state
        self.reset()


    def step(self, action):
        x, y = self.moves[action]
        self.tempS = self.S[0] + x, self.S[1] + y

        # not get out of the world
        self.tempS = (max(0, self.tempS[0]), max(0, self.tempS[1]))
        self.tempS = (min(self.tempS[0], self.height - 1), min(self.tempS[1], self.width - 1))

        # Return:
        # Final Point
        if self.tempS == (1, 18):
            self.S = self.tempS
            return self.tempS, -1, True, {}
        # Bounding Wall
        elif self.tempS[0] == 0 or self.tempS[1] == 0 or self.tempS[0] == (self.height - 1) or self.tempS[1] == (self.width - 1):
            # the cliff
            return self.S(), -10, False, {}
        # Set Wall
        elif self.tempS in self.wallset:
            # the cliff
            return self.S(), -10, False, {}
        # Normal
        else:
            selfS = self.tempS
            return self.S, -1, False, {}


    def reset(self):

        #Start Point
        self.tempS = (0, 0)
        while self.tempS[0] == 0 or self.tempS[1] == 0 or self.tempS[0] == (self.height - 1) or self.tempS[1] == (self.width - 1) or self.tempS in self.wallset:
            self.temp = (np.random.randint(0,21), np.random.randint(0,24))
        self.S = self.tempS
        return self.S

    class Box(gym.Spaces):
AttributeError: 'module' object has no attribute 'Spaces'

ghh

[(1,6,1), (1,12,1), (1,17,1), (2,6,1), (2,12,1), (3,6,1), (3,12,1), (3,17,1), (4,1,1), (4,2,1), (4,3,1), (4,4,1), (4,6,1), (4,7,1), (4,8,1), (4,10,1), (4,11,1), (4,12,1), (4,14,1), (4,15,1), (4,16,1), (4,17,1), (4,18,1), (4,19,1), (4,20,1), (4,21,1), (4,22,1), (5,4,1), (5,19,1), (6,4,1), (7,4,1), (7,7,1), (7,8,1), (7,9,1), (7,11,1), (7,12,1), (7,13,1), (7,14,1), (7,15,1), (7,16,1), (7,19,1), (8,7,1), (8,16,1), (8,19,1), (8,20,1), (8,21,1), (8,22,1), (9,1,1), (9,2,1), (9,3,1), (9,4,1), (9,7,1), (9,16,1), (9,19,1), (10,4,1), (10,7,1), (10,8,1), (10,9,1), (10,10,1), (10,11,1), (10,12,1), (10,13,1), (10,14,1), (10,15,1), (10,16,1), (10,19,1), (11,7,1), (11,11,1), (11,16,1), (11,19,1), (12,4,1), (12,7,1), (12,11,1), (12,19,1), (13,1,1), (13,2,1), (13,3,1), (13,4,1), (13,7,1), (13,8,1), (13,10,1), (13,11,1), (13,12,1), (13,13,1), (13,14,1), (13,15,1), (13,16,1), (13,19,1), (13,20,1), (13,22,1), (16,1,1), (16,3,1), (16,4,1), (16,5,1), (16,6,1), (16,8,1), (16,9,1), (16,10,1), (16,11,1), (16,12,1), (16,13,1), (16,14,1), (16,16,1), (16,17,1), (16,18,1), (16,19,1), (16,20,1), (16,21,1), (16,22,1), (17,5,1), (17,12,1), (17,17,1), (18,5,1), (18,12,1), (19,5,1), (19,12,1), (19,17,1)]

猜你喜欢

转载自my.oschina.net/geminoria/blog/1790754
今日推荐