================================================================================
import gym
import readchar
import utils.prints as print_utils
================================================================================
# Defined MACROS in OpenAI GYM
LEFT=0
DOWN=1
RIGHT=2
UP=3
================================================================================
# Key mapping
arrow_keys={'\x1b[A':UP,'\x1b[B':DOWN,'\x1b[C':RIGHT,'\x1b[D':LEFT}
================================================================================
# v0 is slippery mode
env = gym.make('FrozenLake-v0')
================================================================================
env.reset()
================================================================================
print_utils.clear_screen()
================================================================================
# Show the initial board
env.render()
# ================================================================================
while True:
# Pressed key from user
key=readchar.readkey()
# ================================================================================
if key not in arrow_keys.keys():
print("Game aborted!")
break
# ================================================================================
# You create action by accepting pressed key
action=arrow_keys[key]
# ================================================================================
# You execute action
state,reward,done,info=env.step(action)
# ================================================================================
# You show score board after action
print_utils.clear_screen()
env.render()
# ================================================================================
print("State:{}Action:{}Reward:{}Info:{}".format(state,action,reward,info))
# ================================================================================
if done:
print_utils.print_result(reward)