The reward function belongs to the environment and it is the only way the agent can explore the world given a state.
If we want agents to do something specific, we must provide rewards to them in such a way that they will achieve our goals. It is thus very important that the reward function accurately indicates the exact behavior.
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 is 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.