The reward function belongs the the environment and it is the only way the agent can explore the world given a state.
If we want agent to do something specific, we must provide rewards to it in such a way that it will achieve our goals. It is thus very important that the reward function accurately indicates the exact behaviour.
Depending on your goal you can construct the function such that the agent will try to finish the game as fast as possible, or collect the maximum score.
For example, certain reward functions can cause an agent to commit suicide in order to avoid more severe punishment in form of negative reward in the future (e.g. if the step reward very small). Or it will go the safest way without collecting gold, if falling in pits punishment is very big. In other words, you should experiment with your reward function to find a tradeoff.
Check out this video for more intuition behind it.