0

Let’s say a person can set a limit to play a game for N minutes a day. The player may increase their limit, but the increase doesn’t take effect until the next day.

Example, person sets a limit of 10 minutes a day on Monday. They increase it on Monday to 20 minutes. For the rest of Monday, they may only play 10 minutes.

How could this active and pending limit be modeled? Is this already a solved problem?

3 Answers3

2

Ok, so you model "active" and "pending" and "when" (a datetime).

One approach is that you can make a simple formula that computes the limit based on four inputs: active, pending, when, and current datetime.  Nothing further do do here — no housekeeping needed, as this formula will work into the future.  (That formula is currentDateTime <= when ? active : pending).

Then at some point need to switch over from active to pending, but only when user wants the limit is increased once again: copy pending to active (if it is pending is up to date, i.e. currentDateTime > when) and make pending the new request to increase, while setting the new when.  If pending is not currently in effect then can error: ask the user to try again, e.g. tomorrow.

So, you only need housekeeping when the user wants to update their setting — otherwise nothing to do on a daily basis.


If you want to accept as series of increases that are then to happen day over day that is another simple matter of programming involving a queue an some user interfaces to modify it.

Erik Eidt
  • 34,819
2

The easiest way is to use a count-down clock for keeping track of how much time a person has left to play that day. At midnight, the clock is reset to the limit that is then current.

If the player changes the limit during a day, then the limit value is updated, but the clock is not touched. At the start of the next day (i.e. midnight), the clock is reset to the most recently set value of the limit. This even works if the limit gets changed multiple times during a day.

2

A day at school or work is not the same as a day playing games.

Why don't we throw out the whole idea of a day? 24 hours. You want change the play time? Do it 24 hours ahead of time.

Otherwise I can ask for more time at 11:45, go to the bathroom, and be back at it while the toilet is still flushing.

This way the limit is always the one that was set closest to at least 24 hours ago.

candied_orange
  • 119,268