1- __author__ = 'Tom Schaul, tom@idsia.ch'
1+ # -*- coding: utf-8 -*-
22
33from random import random , choice
44from scipy import zeros
55
66from pybrain .utilities import Named
77from pybrain .rl .environments .environment import Environment
88
9- # TODO: mazes can have any number of dimensions?
9+ __author__ = 'Tom Schaul, tom@idsia.ch'
1010
1111
1212class Maze (Environment , Named ):
@@ -52,9 +52,12 @@ def __init__(self, topology, goal, **args):
5252 self .setArgs (** args )
5353 self .mazeTable = topology
5454 self .goal = goal
55- if self .initPos == None :
55+ self .bang = False
56+
57+ if self .initPos is None :
5658 self .initPos = self ._freePos ()
5759 self .initPos .remove (self .goal )
60+
5861 self .reset ()
5962
6063 def reset (self ):
@@ -65,24 +68,29 @@ def reset(self):
6568 def _freePos (self ):
6669 """ produce a list of the free positions. """
6770 res = []
71+
6872 for i , row in enumerate (self .mazeTable ):
6973 for j , p in enumerate (row ):
70- if p == False :
74+ if p is False :
7175 res .append ((i , j ))
76+
7277 return res
7378
74- def _moveInDir (self , pos , dir ):
79+ def _moveInDir (self , pos , direction ):
7580 """ the new state after the movement in one direction. """
76- return (pos [0 ] + dir [0 ], pos [1 ] + dir [1 ])
81+ return (pos [0 ] + direction [0 ], pos [1 ] + direction [1 ])
7782
7883 def performAction (self , action ):
7984 if self .stochAction > 0 :
8085 if random () < self .stochAction :
8186 action = choice (range (len (self .allActions )))
87+
8288 tmp = self ._moveInDir (self .perseus , self .allActions [action ])
83- if self .mazeTable [tmp ] == False :
89+
90+ if self .mazeTable [tmp ] is False :
8491 self .perseus = tmp
8592 self .bang = False
93+
8694 else :
8795 self .bang = True
8896
0 commit comments