Namespace core.gameSim
Individual game simulation.
Defined in: <js/core/gameSim.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
core.gameSim.GameSim(gid, team1, team2)
Initialize the two teams that are playing this game.
|
<static> |
core.gameSim.GameSim#doBlk(shooter)
Blocked shot.
|
<static> |
core.gameSim.GameSim#doFg(shooter, shooter, type)
Field goal.
|
<static> |
core.gameSim.GameSim#doFt(shooter, amount)
Free throw.
|
<static> |
core.gameSim.GameSim#doPf(t)
Personal foul.
|
<static> |
core.gameSim.GameSim#doReb()
Rebound.
|
<static> |
core.gameSim.GameSim#doShot(shooter)
Shot.
|
<static> |
core.gameSim.GameSim#doStl()
Steal.
|
<static> |
core.gameSim.GameSim#doTov()
Turnover.
|
<static> |
core.gameSim.GameSim#fatigue(energy)
Convert energy into fatigue, which can be multiplied by a rating to get a fatigue-adjusted value.
|
<static> |
core.gameSim.GameSim#homeCourtAdvantage()
Home court advantage.
|
<static> |
core.gameSim.GameSim#injuries()
See if any injuries occurred this possession, and handle the consequences.
|
<static> |
core.gameSim.GameSim#pickPlayer(ratios, exempt)
Pick a player to do something.
|
<static> |
core.gameSim.GameSim#probAst()
Probability that a shot taken this possession is assisted.
|
<static> |
core.gameSim.GameSim#probBlk()
Probability that a shot taken this possession is blocked.
|
<static> |
core.gameSim.GameSim#probStl()
Probability that a turnover occurring in this possession is a steal.
|
<static> |
core.gameSim.GameSim#probTov()
Probability of the current possession ending in a turnover.
|
<static> |
core.gameSim.GameSim#ratingArray(rating, t, power)
Generate an array of composite ratings.
|
<static> |
core.gameSim.GameSim#recordStat(t, p, s, amount)
Increments a stat (s) for a player (p) on a team (t) by amount (default is 1).
|
<static> |
core.gameSim.GameSim#run()
Simulates the game and returns the results.
|
<static> |
core.gameSim.GameSim#simPossession()
Simulate a single possession.
|
<static> |
core.gameSim.GameSim#simPossessions()
Simulate this.numPossessions possessions.
|
<static> |
core.gameSim.GameSim#updatePlayersOnCourt()
Perform appropriate substitutions.
|
<static> |
core.gameSim.GameSim#updatePlayingTime()
Update playing time stats.
|
<static> |
core.gameSim.GameSim#updateSynergy()
Update synergy.
|
<static> |
core.gameSim.GameSim#updateTeamCompositeRatings()
Update team composite ratings.
|
Method Detail
<static>
core.gameSim.GameSim(gid, team1, team2)
Initialize the two teams that are playing this game.
When an instance of this class is created, information about the two teams is passed to GameSim. Then GameSim.run will actually simulate a game and return the results (i.e. stats) of the simulation. Also see core.game where the inputs to this function are generated.
- Parameters:
- {number} gid
- Integer game ID, which must be unique as it will serve as the primary key in the database when the game is saved.
- {Object} team1
- Information about the home team. Top-level properties are: id (team ID number), defense (a number representing the overall team defensive rating), pace (the mean number of possessions the team likes to have in a game), stat (an for storing team stats), and player (a list of objects, one for each player on the team, ordered by rosterOrder). Each player's object contains: id (player's unique ID number), ovr (overall rating, as stored in the DB), stat (an object for storing player stats, similar to the one for team stats), and compositeRatings (an object containing various ratings used in the game simulation), and skills (a list of discrete skills a player has, as defined in core.player.skills, which influence game simulation). In other words... { "id": 0, "defense": 0, "pace": 0, "stat": {}, "player": [ { "id": 0, "ovr": 0, "stat": {}, "compositeRating": {}, "skills": [], "injured": false }, ... ] }
- {Object} team2
- Same as team1, but for the away team.
<static>
{string}
core.gameSim.GameSim#doBlk(shooter)
Blocked shot.
- Parameters:
- {number} shooter
- Integer from 0 to 4 representing the index of this.playersOnCourt[this.o] for the shooting player.
- Returns:
- {string} Output of this.doReb.
<static>
{string}
core.gameSim.GameSim#doFg(shooter, shooter, type)
Field goal.
Simulate a successful made field goal.
- Parameters:
- {number} shooter
- Integer from 0 to 4 representing the index of this.playersOnCourt[this.o] for the shooting player.
- {number} shooter
- Integer from 0 to 4 representing the index of this.playersOnCourt[this.o] for the passing player, who will get an assist. -1 if no assist.
- {number} type
- 2 for a two pointer, 3 for a three pointer.
- Returns:
- {string} Currently always returns "fg".
<static>
{string}
core.gameSim.GameSim#doFt(shooter, amount)
Free throw.
- Parameters:
- {number} shooter
- Integer from 0 to 4 representing the index of this.playersOnCourt[this.o] for the shooting player.
- {number} amount
- Integer representing the number of free throws to shoot
- Returns:
- {string} "fg" if the last free throw is made; otherwise, this.doReb is called and its output is returned.
<static>
core.gameSim.GameSim#doPf(t)
Personal foul.
- Parameters:
- {number} t
- Team (0 or 1, this.or or this.d).
<static>
{string}
core.gameSim.GameSim#doReb()
Rebound.
Simulates a rebound opportunity (e.g. after a missed shot).
- Returns:
- {string} "drb" for a defensive rebound, "orb" for an offensive rebound, null for no rebound (like if the ball goes out of bounds).
<static>
{string}
core.gameSim.GameSim#doShot(shooter)
Shot.
- Parameters:
- {number} shooter
- Integer from 0 to 4 representing the index of this.playersOnCourt[this.o] for the shooting player.
- Returns:
- {string} Either "fg" or output of this.doReb, depending on make or miss and free throws.
<static>
{string}
core.gameSim.GameSim#doStl()
Steal.
- Returns:
- {string} Currently always returns "stl".
<static>
{string}
core.gameSim.GameSim#doTov()
Turnover.
- Returns:
- {string} Either "tov" or "stl" depending on whether the turnover was caused by a steal or not.
<static>
{number}
core.gameSim.GameSim#fatigue(energy)
Convert energy into fatigue, which can be multiplied by a rating to get a fatigue-adjusted value.
- Parameters:
- {number} energy
- A player's energy level, from 0 to 1 (0 = lots of energy, 1 = none).
- Returns:
- {number} Fatigue, from 0 to 1 (0 = lots of fatigue, 1 = none).
<static>
core.gameSim.GameSim#homeCourtAdvantage()
Home court advantage.
Scales composite ratings, giving home players bonuses and away players penalties.
<static>
core.gameSim.GameSim#injuries()
See if any injuries occurred this possession, and handle the consequences.
This doesn't actually compute the type of injury, it just determines if a player is injured bad enough to miss the rest of the game.
<static>
core.gameSim.GameSim#pickPlayer(ratios, exempt)
Pick a player to do something.
- Parameters:
-
{Array.
} ratios - output of this.ratingArray.
- {number} exempt
- An integer representing a player that can't be picked (i.e. you can't assist your own shot, which is the only current use of exempt). The value of exempt ranges from 0 to 4, corresponding to the index of the player in this.playersOnCourt. This is *NOT* the same value as the player ID *or* the index of the this.team[t].player list. Yes, that's confusing.
<static>
{number}
core.gameSim.GameSim#probAst()
Probability that a shot taken this possession is assisted.
- Returns:
- {number} Probability from 0 to 1.
<static>
{number}
core.gameSim.GameSim#probBlk()
Probability that a shot taken this possession is blocked.
- Returns:
- {number} Probability from 0 to 1.
<static>
{number}
core.gameSim.GameSim#probStl()
Probability that a turnover occurring in this possession is a steal.
- Returns:
- {number} Probability from 0 to 1.
<static>
{number}
core.gameSim.GameSim#probTov()
Probability of the current possession ending in a turnover.
- Returns:
- {number} Probability from 0 to 1.
<static>
{Array.}
core.gameSim.GameSim#ratingArray(rating, t, power)
Generate an array of composite ratings.
- Parameters:
- {string} rating
- Key of this.team[t].player[p].compositeRating to use.
- {number} t
- Team (0 or 1, this.or or this.d).
- {number=} power
- Power that the composite rating is raised to after the components are linearly combined by the weights and scaled from 0 to 1. This can be used to introduce nonlinearities, like making a certain stat more uniform (power < 1) or more unevenly distributed (power > 1) or making a composite rating an inverse (power = -1). Default value is 1.
- Returns:
- {Array.
} Array of composite ratings of the players on the court for the given rating and team.
<static>
core.gameSim.GameSim#recordStat(t, p, s, amount)
Increments a stat (s) for a player (p) on a team (t) by amount (default is 1).
- Parameters:
- {number} t
- Team (0 or 1, this.or or this.d).
- {number} p
- Integer index of this.team[t].player for the player of interest.
- {string} s
- Key for the property of this.team[t].player[p].stat to increment.
- {number} amount
- Amount to increment (default is 1).
<static>
{Array.
core.gameSim.GameSim#run()
Simulates the game and returns the results.
Also see core.game where the outputs of this function are used.
- Returns:
- {Array. Game result object, an array of two objects similar to the inputs to GameSim, but with both the team and player "stat" objects filled in and the extraneous data (pace, ovr, compositeRating) removed. In other words... { "gid": 0, "overtimes": 0, "team": [ { "id": 0, "stat": {}, "player": [ { "id": 0, "stat": {}, "skills": [], "injured": false }, ... ] }, ... ] }
<static>
{string}
core.gameSim.GameSim#simPossession()
Simulate a single possession.
- Returns:
- {string} Outcome of the possession, such as "tov", "drb", "orb", "fg", etc.
<static>
core.gameSim.GameSim#simPossessions()
Simulate this.numPossessions possessions.
To simulate regulation or overtime, just set this.numPossessions to the appropriate value and call this function.
<static>
{boolean}
core.gameSim.GameSim#updatePlayersOnCourt()
Perform appropriate substitutions.
Can this be sped up?
- Returns:
- {boolean} true if a substitution occurred, false otherwise.
<static>
core.gameSim.GameSim#updatePlayingTime()
Update playing time stats.
This should be called once every possession, at the end, to record playing time and bench time for players.
<static>
core.gameSim.GameSim#updateSynergy()
Update synergy.
This should be called after this.updatePlayersOnCourt as it only produces different output when the players on the court change.
<static>
core.gameSim.GameSim#updateTeamCompositeRatings()
Update team composite ratings.
This should be called once every possession, after this.updatePlayersOnCourt and this.updateSynergy as they influence output, to update the team composite ratings based on the players currently on the court.