Created
January 31, 2021 21:42
-
-
Save ikbendewilliam/6e7001022d2832ff367cbeadce1c68bb to your computer and use it in GitHub Desktop.
Code for medium article about RL on Snake
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
jList = [] | |
rList = [] | |
for i in range(num_episodes): | |
s = env.clear_board() | |
rAll = 0 | |
d = False | |
j = 0 | |
while j < game_max_length: | |
# Game step... | |
if i % save_interval == 0 and i > 0: | |
print('Done {}/{} {:.2f}% Last game length: {}, Average game length: {}, Average length in last {}: {}, average R in last {}: {}'.format(i, num_episodes, i/num_episodes*100,j, sum(jList)/i, save_interval, sum(jList[-save_interval:])/save_interval, save_interval, sum(rList[-save_interval:])/save_interval)) | |
rlModel.saveVariables() | |
jList.append(j) | |
rList.append(rAll) | |
print("Average R: " + str(sum(rList)/num_episodes)) | |
print("Average lenght: " + str(sum(jList)/num_episodes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment