Gradient Based Optimization Code Python Game Hay