• API
• FAQ
• Tools
• Archive
daily pastebin goal
49%
SHARE
TWEET

# Untitled

a guest Jun 13th, 2018 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. class RandomWalk:
2.     def __init__(self):
3.         # states = [T_0, A, B, C, D, E, T_1]
4.         self.state = 3
5.         self.moves = 0
6.
7.     def move_right(self):
8.         if self.state == 6:
9.             return False
10.         self.state += 1
11.         self.moves += 1
12.
13.     def move_left(self):
14.         if self.state == 0:
15.             return False
16.         self.state -= 1
17.         self.moves += 1
18.
19.     def done(self):
20.         reward = 1 if self.state == 6 else 0
21.         done = True if self.state in [0, 6] else False
22.         return done, reward, self.state, self.moves
23.
24.     def getState(self):
25.         return self.state
26.
27.     def state_space(self):
28.         return list(range(7))
29.
30.     def moves(self):
31.         return self.moves
32.
33.
34. def main():
35.     rw = RandomWalk()
36.     print(rw.done())
37.     rw.move_right()
38.     print(rw.done())
39.     rw.move_right()
40.     print(rw.done())
41.     rw.move_right()
42.     print(rw.done())
43.
44.     print('-' * 10)
45.
46.     rw = RandomWalk()
47.     print(rw.done())
48.     rw.move_left()
49.     print(rw.done())
50.     rw.move_left()
51.     print(rw.done())
52.     rw.move_left()
53.     print(rw.done())
54.
55. if __name__ == '__main__':
56.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top