Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:38:38+00:00 2026-05-26T10:38:38+00:00

In my application I have multiple not realtime games. In each game, each player

  • 0

In my application I have multiple not realtime “games”. In each game, each player has a score. During the course of the game, players may take turns doing some action.

However, if no actions are taken within a customizable amount of time (anywhere from 1 hour to 1 month), then both players will lose x amount of points.

I thought to have a global “timer” that is called by a cron job. At an interval of 1 hour, the timer will call each game’s deductPoints() function.

Within the deductPoints() function I will do something like this:

deductPoints()
{
   timeSinceLastDeduction++;
   if(timeSinceLastDeduction >= frequencyOfDeduction)
   {
       deduct();
       timeSinceLastDeduction = 0;
   }
}

Is there a better way to accomplish this task?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:38:39+00:00Added an answer on May 26, 2026 at 10:38 am

    If you are willing to store more data, I would suggest this design.

    Instead of deducting the points every time (relying strongly on the “state” of the game), instead, store every action that the players have taken. Ex, lets take this table:

     id | playerid | action   |         stamp
    ----+----------+----------+------------------------
      1 |        1 | e2 to e4 | 2011-10-27 04:00:00-04
      2 |        1 |          | 2011-10-27 04:30:00-04
      3 |        1 |          | 2011-10-27 06:00:00-04
      4 |        1 |          | 2011-10-27 07:45:00-04
      5 |        1 |          | 2011-10-27 08:00:00-04
    

    Etc. etc.

    e2 to e4 is a Chess move by the way, one of the common opening moves. Your game, I can’t really design that. The “action” is optional however, you only really need to store the fact that an action occured to calculate the penalty. (But might as well store extra information, as long as you have the space to do so of course).

    “id” is the surrogate key in this case. In Postgresql, the DDL would look like:

    CREATE TABLE actions(
      id BIGSERIAL PRIMARY KEY,
      playerid int,
      action text,
      stamp timestamptz,
      UNIQUE(playerid, stamp));
    

    The tuple (playerid,stamp) will be the “real” primary key. “id” is the surrogate key.

    To see the difference in timestamps, the code is relatively simple using window functions. (Continuing to use PostgreSQL)

    select playerid, time_between, id FROM
            (SELECT playerid,
                    stamp - lag(stamp) OVER () as time_between,
                    id FROM actions
                    ORDER BY stamp)
                    as ss
            WHERE playerid = 1
                    AND time_between > '1 hour';
    

    Sample Output, given the test data from earlier:

     playerid | time_between | id
    ----------+--------------+----
            1 | 01:30:00     |  3
            1 | 01:45:00     |  4
    

    You don’t have cron jobs at all. You stored more data (so it will be easier to “undo” actions). Your players can review past moves if they want to. If calculating the penalty becomes inefficient, then you can always just cache the score at a higher level.

    Window Functions are not available in MySQL btw. But are available in PostgreSQL, SQL Server and Oracle.

    EDIT: If space is a concern, then you can always “garbage collect” this table regularly. Still, that’d be a lot of games. Each row takes up ~48 bytes (assuming a null “action”). If you had 1000 players, each playing 200 games with 40 actions, you’d only have ~384MB of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple rails application running at a server. Each one at one port
I have multiple drop down menus with my JSF/ICEFaces application that update each others
I have a Windows Forms (.NET) application that can have multiple documents open simultaneously.
I have multiple layers in an application and i find myself having to bubble
I have multiple threads (C# application running on IIS) running that all need to
We have multiple BizTalk 2006 application servers, and I find it almost impossible to
I have multiple IPs on a NIC. I've programmed a console application to connect
We have multiple log files like database log, weblog, quartzlog in our application. Any
Hello I need to have multiple language support of my django admin application.I can
Is it a good design to have multiple masterpages in an application. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.