• Create Account

## Using timing/clock in Simulation - (Basketball)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1brandon93s  Members

101
Like
0Likes
Like

Posted 14 February 2013 - 10:54 AM

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?

### #2L. Spiro  Members

24842
Like
0Likes
Like

Posted 14 February 2013 - 03:59 PM

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

### #3EmployeeNumber8  Members

1103
Like
0Likes
Like

Posted 15 February 2013 - 08:38 AM

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.

### #4Satharis  Members

2100
Like
0Likes
Like

Posted 16 February 2013 - 06:33 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.