-
Notifications
You must be signed in to change notification settings - Fork 0
/
frozenlake.py
37 lines (33 loc) · 929 Bytes
/
frozenlake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#frozen lake solver 4*4
#it is a bruteforce approach with the forbidden states explicitly assigned by me
import gym
import random
env = gym.make("FrozenLake-v0")
env.reset()
env.render()
reward=0.00
forbidden=[5,7,11,12]
actions = {
'Left': 0,
'Down': 1,
'Right': 2,
'Up': 3
}
counter=0
bool=True
while(bool):
counter=counter+1
winning_sequence=[random.choice(["Left","Down","Right"]),random.choice(["Left","Down","Right"]),random.choice(["Left","Down"]),random.choice(["Left","Down","Right","Up"])]
for a in winning_sequence:
new_state, reward, done, info = env.step(actions[a])
print()
env.render()
print("Reward: {:.2f}".format(reward))
if new_state in forbidden:
env.reset()
break
if new_state==15:
bool=False
break
print("no.of attempts",counter)
print("the winning sequence",winning_sequence)