Engine Basics

For discussion about creating our own sim engine.
Post Reply
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Engine Basics

Post by WigNosy »

Okay, as discussed on Skype this morning, let's try to lay down some guidelines as to what it would take to "roll our own" sim league engine, as well as the kind of things we want to track.

Having taken a couple of stabs at building a sim engine myself in the past, here is what I personally think the best strategy to build is (and also lets us capture the most data):

1. The "basic unit of gameplay" is a "touch." A "touch" ends in one of the following outcomes:
a. Field Goal Attempt (may include defensive and-1 foul)
b. Defensive Foul
c. Turnover (includes offensive fouls)
d. End of Period
e. Pass

2. A "possession" as we generally understand it in basketball is then a "touch" that ends in anything but a pass, and also contains all touches preceding it that ended in a pass.

3. A "touch" should probably track the following:
a. Player with the ball
b. Primary defender against player with ball
c. Player who had the ball on the previous touch (e.g., potential assist man)
d. Location on floor where touch takes place (see http://www.82games.com/locations.htm as a start)
e. Secondary defenders (if any, i.e., secondary shot blockers)
f. All ten players on the floor (tracks +/-)
g. Time elapsed on this possession (how deep into the 24-second clock)
h. Time remaining and point differential (lets us track "clutch performance" etc.)
i. Offensive gameplan
j. Defensive gameplan

4. I suggest player ratings be simple, "direct" ratings that affect:
Offense:
a. How likely a player is to create a shot during a touch (may have multiple ratings, e.g., inside, slashing, spot-up, etc. and may need multiple ratings to decide what kind of shot the player is likely to try to create)
b. How likely a player is to make a shot (may have multiple ratings based on floor location)
c. How likely a player is to draw a shooting foul
d. How likely a player is to draw a non-shooting foul
e. How likely the player is to commit an offensive foul
f. How likely the player is to allow a steal of the dribble ("handles")
g. How likely the player is to commit an unforced turnover (e.g., bad pass, travel)
h. How likely the player is to create a better touch for another player (i.e., good pass)
i. How likely a player is to "Get open" (e.g., Reggie Miller running off screens) when someone else is using a touch
j. How likely a player is to "help others get open" (e.g., set a pick) when someone else is using a touch
k. How likely the player is to allow a steal on a pass ("court vision")
l. How likely the player is to have his shot blocked/avoid a potential block

Defense:
a. How likely a player is to keep the offensive player from shooting (i.e., a good defender reduces chances of creating a shot for himself), may need multiple ratings based on floor position (i.e., the exact opposite of offensive "A" above)
b. How likely the player is to bother a shot as a primary defender (i.e., reduce shooter's chance of making it)
c. How likely the player is to avoid or commit a shooting foul
d. How likely the player is to avoid or commit a non-shooting foul
e. How likely the player is to draw an offensive foul
f. How likely the player is to draw an on-ball steal (i.e., quick hands)
g. How likely the player is to induce a non-steal turnover (e.g., travel, bad pass)
h. How likely the player is to deny a lane to get a better touch for an offensive player's teammate ("crowd the passer")
i. How likely the player is to stick with his assigned player off the ball (i.e., fight through screens)
j. How likely the player is to help when other players get free (i.e., switch)
k. How likely the player is to steal a pass (i.e., "jump the passing lanes")
l. How likely the player is to block a shot as a primary defender/secondary defender

5. As a general rule of thumb, I would suggest that all players are considered to have a baseline level of competence (e.g., shoot 45% from the floor) and that offense or defensive ratings can shift that up by about 15-20% each way (i.e., the best offensive player versus the worst defensive player would get a 40% boost over 45% from the floor - that's 45%x1.4 for a 63% shooting, not 45%+40% = 85%; similarly the worst offensive player versus the best defensive player would shoot 45%x0.6 or 27%, not 45%-40% for a total of 5%)

6. "Secondary" factors (e.g., height difference improving/hindering blocked shots) might be factored in later but I woudl suggest instead we make height completely cosmetic and have height directly boost the "block shot" rating when a player is created.

More later, but that's the basics as I see it and we can start discussion from there.

The database could store the results of each touch so we can get deep analysis of how efficient a player is, and allow gameplanning to increase the number of touches a player gets. There probably also needs to be a rating to reflect how often a player "demands" touches (i.e., affects the likelihood he's the one picked to get the next touch) so we can simulate clueless chuckers (see also: P, Swaggy) that kill team chemistry.
The Cat is Back
User avatar
JNR
Posts: 3710
Joined: Tue Jan 13, 2015 1:21 pm
PBSL Team: San Diego Clippers

Re: Engine Basics

Post by JNR »

I am a fan of the off-court elements of player personality. Ratings for things like greed, loyalty, play-for-winner, and even Basketball IQ (though that is more of a combination of several of those stats you mentioned).
Image
I
Inner_GI
Posts: 1668
Joined: Tue Jan 13, 2015 10:44 pm
PBSL Team:

Re: Engine Basics

Post by Inner_GI »

I like the way this sounds. My follow up question would be how do these basic outlines of offense and defense adjust based on game plan settings.
Image
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

Inner_GI wrote:I like the way this sounds. My follow up question would be how do these basic outlines of offense and defense adjust based on game plan settings.
I would think of it in this manner (described in terms of both physical analogs and programming terms):

1. The "basic offensive outcomes" are a set of cards, with "Field Goal Attempt" or "Turnover" or "Foul" written on them - you get a certain number of each card based on the baseline (leaguewide average) likelihood the event happens (in programming speak, these would be elements of an array).

2. The offensive player's ratings would add a certain number of cards to these baseline likelihoods, for instance, a player who has a tendency to commit turnovers would increas the number of "Turnover" cards in the pool (i.e., additional array elements).

3. The defenders' ratings would add or take away a certain number of cards from these baseline likelihoods (i.e., additional array elements).

4. Offense/defense gameplans could either add/take away cards directly or (my preference) be checked against each other in a rock-paper-scissors way to add/take away a set of cards based on how the two gameplans interact (for example, a "shoot a lot of threes" offense versus a "sag into the paint" defense should generate a lot of extra shots and not a lot of extra tunovers, while an "isolation" offense versus a "help" defense might generate more turnovers and fewer shots).

The final result of a "Touch" is figured by shuffling the cards (or using shuffle on the elements of an array) then "taking the top card" (first element of the array). By adding or taking away cards from the stack, you play with the odds of a given outcome, but since odds are all outcomes will have chances added and/or taken away, an overwhelming advantage in one area won't throw the whole stack obviously in your favor.

http://stats.nba.com/tracking/#!/team/ may give us a good idea of how often certain events occur out of a touch, league-wide. As of tonight, leaguewide averages:

Touches per game: 431.8

Passes per game: 307.5 (or 71.2% of touches)
FGA: 85.2 (19.7% of touches)
Fouls: 21.4 (4.96% of touches)
Turnovers: 15.4 (3.56% of touches)
Touches that end in none of the above (end of quarter?): 2.3

FIRST CRACK AT NUMBERS:

So maybe have the baseline draw of outcomes be 1000 total elements, broken down as follows:
714 "Pass"
198 "FGA"
51 "Draw Foul"
37 "Turnover"

Perhaps then allow a player's offensive "shoot the ball" rating (e.g., FBB's "Inside" rating) add twice it's value to the number of "FGA" cards, and a defender's defensive rating take up to 100 away (since great defense always tends to be trumped by great offense). For a "perfect" offensive player versus the "absolute worst" defender, all else being equal, this means the possibilities look like:

714 "Pass" (now only 59.5% likely)
398 "FGA" (now now 33% likely, up from 19.7% baseline - this means this guy will shoot about 50% more than average)
51 "Draw Foul" (5.1% likely)
37 "Turnover" (3.7% likely)

...and a "perfect defender" against a horrid offensive player would look like this:
714 "Pass" (now 79% likely)
98 "FGA" (now only 10.8% likely, down from 19.7% baseline)
51 "Draw Foul" (now 5.6% likely)
37 "Turnover" (now 4.1% likely)

So if you assume "average" players at all positions, and you're likely to see about 20 ppg from each position (C/PF/SF/SG/PG), the percent of FGA is probably roughly equal to the PPG. So a "perfect offensive player" teamed with "league average" players" might score about 33 ppg if he plays close to 48 minutes (which sounds about right when league pace is about 100 ppg).
The Cat is Back
I
Inner_GI
Posts: 1668
Joined: Tue Jan 13, 2015 10:44 pm
PBSL Team:

Re: Engine Basics

Post by Inner_GI »

Nice work. So with this cards in an array thinking it should be pretty easy to manipulate the likelihood of events.

A high motion team will increase the likelihood a pass it performed and a low motion lowers the pass chance.

What I was a little confused about was individual players adding cards to the array. Are you saying each player will have a unique chance of taking or shot?

For instance a great offensive player adding a global 120 more fga attempt cards seems a little odd. It doesn't really mean that player is more likely to take the shot just that the team will take a shot.


Sent from my iPhone using Tapatalk
Image
User avatar
IamQuailman
Posts: 10407
Joined: Tue Jan 06, 2015 8:25 am
PBSL Team: Milwaukee Bucks
Contact:

Re: Engine Basics

Post by IamQuailman »

This is pretty awesome. But I have no idea how I can help contribute. BUT I did want to say... where would "technical fouls" fall in? Not a "touch" since they can happen outside of a play
ImageImageImageImage
N
NOLa.
Posts: 3994
Joined: Fri Jan 09, 2015 9:21 pm
PBSL Team: Sacramento Kings

Re: Engine Basics

Post by NOLa. »

After a foul im guessing

Sent via Morse code
I
Inner_GI
Posts: 1668
Joined: Tue Jan 13, 2015 10:44 pm
PBSL Team:

Re: Engine Basics

Post by Inner_GI »

NOLa. wrote:After a foul im guessing

Sent via Morse code
Or turnover that stops the clock.


Sent from my iPhone using Tapatalk
Image
N
NOLa.
Posts: 3994
Joined: Fri Jan 09, 2015 9:21 pm
PBSL Team: Sacramento Kings

Re: Engine Basics

Post by NOLa. »

Inner_GI wrote:
NOLa. wrote:After a foul im guessing

Sent via Morse code
Or turnover that stops the clock.


Sent from my iPhone using Tapatalk
This too! Also, from pbp experience, taunting after a made FG. Those are the best

Sent via Morse code
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

Inner_GI wrote:What I was a little confused about was individual players adding cards to the array. Are you saying each player will have a unique chance of taking or shot?

For instance a great offensive player adding a global 120 more fga attempt cards seems a little odd. It doesn't really mean that player is more likely to take the shot just that the team will take a shot.
Remember, a touch is based on a particular player having the ball. So a great offensive player (e.g., Jordan) would add 100 FGA attempt cards when the ball is in his hands. When he passes it to a teammate who is not offensively gifted (e.g., Bill Wennington) a new touch starts without those extra 100 FGA.

Also, I should note that when I say a touch results in a "pass" it's another way of saying "the player couldn't create a shot and had to give it up."

We'll probably want to have other players on the floor (i.e., not the guy with the ball) affect things a bit as well, but it's generally best to build the "Base" of the engine, then let additional features add perturbations to the main engine as we grow it out.
The Cat is Back
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

Also, we don't want to make things TOO complex. A player with 300 attributes might better model a real-world player, but the human GMs will have a tough time juggling 300 variables in their head. At some point, we have to cede "more realistic sim" to "quickly understandable to a human."
The Cat is Back
I
Inner_GI
Posts: 1668
Joined: Tue Jan 13, 2015 10:44 pm
PBSL Team:

Re: Engine Basics

Post by Inner_GI »

Yea. That makes sense. I didn't realize we were talking about creating an array of possibilities for each touch based on the offensive and defensive players.

That seems pretty simple. The complexity comes into how does a game plan on offensive and defensive affect what the possibilities of a touch are.


Sent from my iPhone using Tapatalk
Image
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

Inner_GI wrote:Yea. That makes sense. I didn't realize we were talking about creating an array of possibilities for each touch based on the offensive and defensive players.

That seems pretty simple. The complexity comes into how does a game plan on offensive and defensive affect what the possibilities of a touch are.


Sent from my iPhone using Tapatalk
The other complexity can come in the "distribution of touches" (i.e., not just "who shoots the ball more when he has it" but "who demands the ball more often" and thus gets more touches - think Kobe Bryant versus Ben Wallace).
The Cat is Back
T
TheSyndicate
Posts: 3717
Joined: Mon Jan 19, 2015 2:15 pm
PBSL Team:

Re: Engine Basics

Post by TheSyndicate »

WigNosy wrote:
Inner_GI wrote:Yea. That makes sense. I didn't realize we were talking about creating an array of possibilities for each touch based on the offensive and defensive players.

That seems pretty simple. The complexity comes into how does a game plan on offensive and defensive affect what the possibilities of a touch are.


Sent from my iPhone using Tapatalk
The other complexity can come in the "distribution of touches" (i.e., not just "who shoots the ball more when he has it" but "who demands the ball more often" and thus gets more touches - think Kobe Bryant versus Ben Wallace).

So I think this should actually impact the number of 'FG Attempt' cards in the deck more than offensive prowess. For example, Lamar Odom on the Lakers could have had his defender completely overmatched, but would still more likely pass up a shot to Kobe/Gasol/Bynum. Then once the action 'FG attempt' occurs it is then impacted by relative offensive skill and defensive skill of the primary/secondary offender, whether the player is double teamed, and where the shot comes from. Using the previous example, Odom would be more likely to take fewer shots, but make a higher percentage of them assuming he was matched up against an average or below average defender and wasn't exclusively shooting jumpers.

Just my two cents.
6 Rings. That's it. That's the tweet.
T
TheSyndicate
Posts: 3717
Joined: Mon Jan 19, 2015 2:15 pm
PBSL Team:

Re: Engine Basics

Post by TheSyndicate »

WigNosy wrote:
Inner_GI wrote:Yea. That makes sense. I didn't realize we were talking about creating an array of possibilities for each touch based on the offensive and defensive players.

That seems pretty simple. The complexity comes into how does a game plan on offensive and defensive affect what the possibilities of a touch are.


Sent from my iPhone using Tapatalk
The other complexity can come in the "distribution of touches" (i.e., not just "who shoots the ball more when he has it" but "who demands the ball more often" and thus gets more touches - think Kobe Bryant versus Ben Wallace).

With obviously game planning also playing a central role in whether a particular player's touch ends with a FG attempt.
6 Rings. That's it. That's the tweet.
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

There are really three distinct steps going into a shot..

1. How likely is the player to get the ball? (Needs to be discussed)

2. When the player has the ball, how likely is he to shoot? (This is what we've been discussing so far with the "cards")

3. When the player shoots, how likely is the ball to go in (or if you prefer, how good a look does he usually get)? (Still needs to be discussed)

A player can be great at creating shots (how likely is he to shoot?) but bad at making them (AI or this year's Kobe). A player can be a great shooter who shoots when he does get touches but rarely gets the ball (Steve Kerr). A player can have a hard time getting shots off, but make them when he does, etc.

The combination of these three things gives us all sorts of players. Extreme examples:
Allen Iverson (likely to get the ball, likely to shoot it, not likely to make it)
Nick Young (average chance to get the ball, likely to shoot it, not likely to make it)
2009 Andrew Bynum (not likely to get the ball, likely to shoot it, likely to make it)
Dennis Rodman (not likely to get the ball, not likely to shoot it, likely to make it)
The Cat is Back
I
Inner_GI
Posts: 1668
Joined: Tue Jan 13, 2015 10:44 pm
PBSL Team:

Re: Engine Basics

Post by Inner_GI »

WigNosy wrote:There are really three distinct steps going into a shot..

1. How likely is the player to get the ball? (Needs to be discussed)
First thing, I assume Key Players comes into to play here. Another idea was to continue to use the defensive stats to determine if an offensive player is "open" to receive the ball. I'm thinking athleticism here.

Saying that leads me to ask... we need to track every player's position on the court at the time of a touch.
WigNosy wrote:2. When the player has the ball, how likely is he to shoot? (This is what we've been discussing so far with the "cards")

3. When the player shoots, how likely is the ball to go in (or if you prefer, how good a look does he usually get)? (Still needs to be discussed)
Simply put this should be based on position on court, ratings, athleticism - defensive attributes. The only problem I'm really seeing that will limit us is the fact that players will "never" be wide open.
WigNosy wrote:A player can be great at creating shots (how likely is he to shoot?) but bad at making them (AI or this year's Kobe). A player can be a great shooter who shoots when he does get touches but rarely gets the ball (Steve Kerr). A player can have a hard time getting shots off, but make them when he does, etc.

The combination of these three things gives us all sorts of players. Extreme examples:
Allen Iverson (likely to get the ball, likely to shoot it, not likely to make it)
Nick Young (average chance to get the ball, likely to shoot it, not likely to make it)
2009 Andrew Bynum (not likely to get the ball, likely to shoot it, likely to make it)
Dennis Rodman (not likely to get the ball, not likely to shoot it, likely to make it)
Image
User avatar
WigNosy
Posts: 6908
Joined: Fri Apr 04, 2014 6:39 pm
PBSL Team: Portland Trailblazers

Re: Engine Basics

Post by WigNosy »

Been thinking more about this and thought there might be a better way to handle possession outcomes - instead of both the offensive and defensive player adding and subtracting cards from a single pool, what if the offensive player has a "deck of cards" based on his offensive skills and the defensive player has a "deck of cards" based on his defensive skills (both "added to some baseline deck")? The outcome of a possession would be based on the combination of cards - for instance, if the offensive player lays down "take jumper" and the defensive player lays down "steal pass attempt" the offensive player gets his shot off. But if the offensive player lays down "pass" and the defensive player lays down "steal pass attempt" the defender steals the pass. This gets a lot more complicated when figuring out percentages and I'd have to work it out to figure out if this is a better method - but both "individual decks" probably wind up smaller than the single massive possession deck.

This could also allow for some more interesting quirks, for example, cards used might be "removed from the player's deck" for the rest of the game (or at least until he takes a rest, or halftime, or what have you). Alternatively, each card might have an "exhaustion" value that is deducted from a player's stamina and determines when he has to go to the bench. Different gameplans might provide different "baseline decks" either overall or even by position on the floor.

You could also throw in "special ability" cards that, when drawn, give a player some sort of extra tweak for a number of possessions - for instance, a "looking to shoot" card might mean that a "pass the ball harmlessly" result for the offensive player has a 25% (or whatever) chance of being turned into a "attempt a shot" card for his next 10 touches. Or a "hot hand" card might improve the player's chance of a successful make on his next 5 field goal attempts.

Need to think of this a little more, but having some sort of "opposed check" and allowing players to gain access to limited-term special abilities based on years in the league (perhaps each year in Training Camp you get to select one new "special ability card" - maybe call it a "quirk" - to add to your player's arsenal and the player also gets one random quirk that you can't control) could be REALLY interesting. The longer they're in the league, the quirkier they get (and you know Allen Iverson and Kobe Bryant took "looking to shoot" every single TC). It also means players with similar basic ratings but different quirks could perform quite differently.
The Cat is Back
N
NOLa.
Posts: 3994
Joined: Fri Jan 09, 2015 9:21 pm
PBSL Team: Sacramento Kings

Re: Engine Basics

Post by NOLa. »

Rrally like the above idea, just wonder how many cards will be needed to account for player actions/stamina/game plan and such.

Sent from my SM-S765C using Tapatalk
User avatar
IamQuailman
Posts: 10407
Joined: Tue Jan 06, 2015 8:25 am
PBSL Team: Milwaukee Bucks
Contact:

Re: Engine Basics

Post by IamQuailman »

Live blog on engine basics: zzzzzz bleep bloop

Sent from my SM-G935P using Tapatalk
ImageImageImageImage
Post Reply

Return to “Roll Your Own Sim Engine”