function discounted_return(rewards, gamma=0.9):

   total = 0
   for t, reward in enumerate(rewards):
      total += (gamma ** t) * reward # later rewards count less than immedi
 ate ones
   return total
 # credit for a win must flow back to the moves that set it up
