def reward_function(state, action): if goal_reached(state): return 1.0 # Sparse reward return -0.01 # Dense reward for each time step