Gradient Based Optimization Code Python Game Ran