# Using timing/clock in Simulation - (Basketball)

This topic is 1796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am creating a college basketball simulation that uses statistics to simulate games. Ultimately, going to buy a GUI interface on top of it, and create a management game.

Each game is simulated via a state machine, essentially. Could also be done in a while loop just as effectively. Anyways, I am having trouble with the clock mechanism. How and when does the game stop? There is two 20 minute halves in college basketball. The most reasonable method I could come up with is as follows:

You initialize a variable to 20 minutes (12,000 deciseconds). Then, each basektball posession is given a randomized length of posession off of a bell curve, centered around the teams average posession length. Each time, this amount is deducted from the initialized time variable until it reaches zero.

What do you guys think? Can anyone think of a more accurate clock representation?

##### Share on other sites

I am a programmer and so by definition know nothing about the rules of the clock of basketball.

But whatever the situation, game time is usually handled with microsecond resolution and any time you need to time something the time is either accumulated or unaccumulated.

If you want a timer to count down from 1,200,000,000 microseconds, start it there and each logical update subtract the amount of time that has passed since the last logical update.  You should be using a fixed time-stamp for this, but it will work either way.

When subtracting, modify the amount of time you subtract by whatever the rules of basketball dictate.  If under X condition the timer is supposed to count down twice as fast, multiply your subtraction time by 2.  If for Y reason the clock is supposed to stop, multiply your subtraction value by 0.

L. Spiro

##### Share on other sites

Then, each basektball posession is given a randomized length of posession off of a bell curve, centered around the teams average posession length. Each time, this amount is deducted from the initialized time variable until it reaches zero.

Don't you think it would be more fun to add realism instead of just randomizing possession time? I'm sure you know that turnovers play a big role in Basketball. If you just randomize possession time then you kinda miss out on that. When you take turnovers into account, you could just let the clock run, and the possessions would sort themselves out. No need for randomization. In a real game, possession changes occur when a basket is scored, or on a turnover - to my mind you want to have that same logic in a simulation.

##### Share on other sites

Kinda goes down to how much "simulation" you want to do, are you just doing statistical simulations of who wins the games and their scores and other data? If so you could technically randomize clock time and all that or just base it off some other factors.

Alternatively you could go into deeper simulation like a game of life would or something and have it literally play out randomized AI plays of the game and count the clock down when play is actually.. well going, a bit more complex obviously and would be running in super time but still.

This is one of those things that doesn't neccesarily have one right answer you just want to pick the one that sounds reasonable to code and will give a reasonable result.