Created
November 7, 2016 11:40
-
-
Save taotao54321/3be8abcaf3937e2c66eeef669556b4ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Just a handmade algorithm. NOT AI. | |
import gym | |
### MAP ### | |
# SFFF | |
# FHFH | |
# FFFH | |
# HFFG | |
########### | |
# 0:L, 1:D, 2:R, 3:U | |
ACTIONS = ( | |
0, 3, 3, 3, | |
0, -1, 0, -1, | |
3, 1, 0, -1, | |
-1, 2, 1, -1, | |
) | |
EPISODE_COUNT = 1000 | |
DEBUG = False | |
#DEBUG = True | |
def get_action(ob): | |
act = ACTIONS[ob] | |
assert 0 <= act <= 3 | |
return act | |
def main(): | |
env = gym.make("FrozenLake-v0") | |
env.monitor.start("rec") | |
reward_total = 0.0 | |
for episode in range(EPISODE_COUNT): | |
ob = env.reset() | |
if DEBUG: env.render() | |
while True: | |
ob, reward, done, info = env.step(get_action(ob)) | |
if DEBUG: | |
env.render() | |
print(ob, reward, done, info) | |
if done: | |
reward_total += reward | |
break | |
env.monitor.close() | |
print("episodes: {}".format(EPISODE_COUNT)) | |
print("total reward: {}".format(reward_total)) | |
print("average reward: {:.2f}".format(reward_total / EPISODE_COUNT)) | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment