Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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