Skip to content

Commit

Permalink
improve toy_text printing
Browse files Browse the repository at this point in the history
  • Loading branch information
joschu committed Feb 12, 2017
1 parent 4647fb1 commit 622429c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions gym/envs/toy_text/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _seed(self, seed=None):

def _reset(self):
self.s = categorical_sample(self.isd, self.np_random)
self.lastaction=None
return self.s

def _step(self, a):
Expand Down
11 changes: 5 additions & 6 deletions gym/envs/toy_text/frozen_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def __init__(self, desc=None, map_name="4x4",is_slippery=True):
def to_s(row, col):
return row*ncol + col
def inc(row, col, a):
if a==0:
if a==0: # left
col = max(col-1,0)
elif a==1:
elif a==1: # down
row = min(row+1,nrow-1)
elif a==2:
elif a==2: # right
col = min(col+1,ncol-1)
elif a==3:
elif a==3: # up
row = max(row-1,0)
return (row, col)

Expand Down Expand Up @@ -116,17 +116,16 @@ def inc(row, col, a):
def _render(self, mode='human', close=False):
if close:
return

outfile = StringIO() if mode == 'ansi' else sys.stdout

row, col = self.s // self.ncol, self.s % self.ncol
desc = self.desc.tolist()
desc = [[c.decode('utf-8') for c in line] for line in desc]
desc[row][col] = utils.colorize(desc[row][col], "red", highlight=True)
outfile.write("\n".join(''.join(line) for line in desc)+"\n")
if self.lastaction is not None:
outfile.write(" ({})\n".format(["Left","Down","Right","Up"][self.lastaction]))
else:
outfile.write("\n")
outfile.write("\n".join(''.join(line) for line in desc)+"\n")

return outfile

0 comments on commit 622429c

Please sign in to comment.