mirror of
https://github.com/wassname/Deep-reinforcement-learning-with-pytorch.git
synced 2026-09-09 11:13:45 +08:00
Create .gridworld_v3.py
This commit is contained in:
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
|
||||
SIZE = (14,14)
|
||||
class CrossRoadGridWorld():
|
||||
def __init__(self, size=(14,14)):
|
||||
super(CrossRoadGridWorld, self).__init__()
|
||||
self.state = np.zeros(size)
|
||||
self.size = size
|
||||
self.init_state = self.get_init_state()
|
||||
if size[0] <= 4 or size[1] <= 4:
|
||||
raise ValueError("Size error, the grid size must be larger than 4*4")
|
||||
self.title = "Cross Road Grid World"
|
||||
self.length = size[0]
|
||||
self.width = size[1]
|
||||
|
||||
def reset(self):
|
||||
self.state = self.get_init_state()
|
||||
|
||||
def get_init_state(self):
|
||||
#plot the horizon block
|
||||
init_state = np.zeros((self.size))
|
||||
for i in range(self.size[0]):
|
||||
for j in [self.size[1]//2-1, self.size[1]//2]:
|
||||
init_state[i,j] = 200
|
||||
|
||||
#plot the vertical block
|
||||
for i in [self.size[0]//2-1, self.size[0]//2]:
|
||||
for j in range(self.size[1]):
|
||||
init_state[i,j] = 200
|
||||
|
||||
return init_state
|
||||
Reference in New Issue
Block a user