Skip to content

Instantly share code, notes, and snippets.

@ikbendewilliam
Created January 31, 2021 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikbendewilliam/6e7001022d2832ff367cbeadce1c68bb to your computer and use it in GitHub Desktop.
Save ikbendewilliam/6e7001022d2832ff367cbeadce1c68bb to your computer and use it in GitHub Desktop.
Code for medium article about RL on Snake
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