how do i incoorprate player stats in a sports game? (hockey)

Started by
6 comments, last by Rutin 5 years, 6 months ago

I'm a beginner so this might be very dumb. I think I've finally understood the logic behind how a game is simulated and i still don't know how to do it in swift code . I use the offensive ability of a team and translate that to goals for based on, in this case, the NHL stats on about how much good offenses score vs bad offenses and do the same for goals against. multiply the offense of team one with team twos defense and vice versa. and then square root the two and you should get the average number of goals expected from the teams in a matchup. How do I do this in swift code? how do I make a number where there is supposed to be an average but the number should still be kind of random?

and then there is the player part. how do i have so that it is a certain player that scores the goal? And make it so that players with higher stats score more goals. because I just averaged the offensive abilities of all the players and defensive abilities of all the players to make the team abilities. can I incorporate a player stats in a system like this or do I need to use a different kind of simulation? also any new simulation styles ideas are welcomed.

thanks in advance!!!!!

Advertisement

When working in a simulation environment you need to consider a lot more than just possible goals scored. I've worked on simulations and you need an extensive collection of events, and formulas, but most of all you need to have a deep understanding of possible events.

To keep things simple if you're wanting to simulate the chances a player would score on a goalie 1-on-1 you could consider a few things.

The goalie's stats for making a save with his blocker, stick, paddle, glove, pads, and chest. Then you need to consider movement speed when transitioning positions. This really depends on how realistic and how far you want to push. Next you would need to find out about the player shooting, what is their shot type? Are they doing a wrist shop, slap shot, snap shot, back hand, and have some number for accuracy and speed, plus power. Then you need to consider the position of the puck upon release as well as the distance and where the goalie is at the time to calculate angles from the puck's perspective to see if open holes are there. With this information you can make formula to see if the player has a fast enough release to bypass the goalie, and if the puck can realistically go past. You can even go a step further, if the puck hits a spot on the goalie, what is the recovery rate based on the power of the shot? You could have an event run to see if the player is able to rebound the puck into the net, ect...

All of this can be done within a spreadsheet environment to calculate possibilities. I would suggest doing it all outside of code before starting. Once you have an idea it's just a matter of making objects with variables for each stat and running an event manager that feeds in all these values in tune with the formulas to complete your calculations.

Programmer and 3D Artist

27 minutes ago, Rutin said:

When working in a simulation environment you need to consider a lot more than just possible goals scored. I've worked on simulations and you need an extensive collection of events, and formulas, but most of all you need to have a deep understanding of possible events.

To keep things simple if you're wanting to simulate the chances a player would score on a goalie 1-on-1 you could consider a few things.

The goalie's stats for making a save with his blocker, stick, paddle, glove, pads, and chest. Then you need to consider movement speed when transitioning positions. This really depends on how realistic and how far you want to push. Next you would need to find out about the player shooting, what is their shot type? Are they doing a wrist shop, slap shot, snap shot, back hand, and have some number for accuracy and speed, plus power. Then you need to consider the position of the puck upon release as well as the distance and where the goalie is at the time to calculate angles from the puck's perspective to see if open holes are there. With this information you can make formula to see if the player has a fast enough release to bypass the goalie, and if the puck can realistically go past. You can even go a step further, if the puck hits a spot on the goalie, what is the recovery rate based on the power of the shot? You could have an event run to see if the player is able to rebound the puck into the net, ect...

All of this can be done within a spreadsheet environment to calculate possibilities. I would suggest doing it all outside of code before starting. Once you have an idea it's just a matter of making objects with variables for each stat and running an event manager that feeds in all these values in tune with the formulas to complete your calculations.

Thanks for the reply. I do understand that there are many possibilities in sports as I watch spots a lot but since I'm still starting out with coding I figured id do something simple first and than build on that. you mentioned the chances of a player scoring a goal on a goalie 1 v 1, how do I connect events such as that to the game simulated as a whole? I could add shots on goal and shots against to the simulation instead of goals per game and against. but than again how do I incorporate a players likelihood of getting a chance and scoring with the team as right now I only know how many chances a team created as a whole and how many goals they scored as a whole. should I break down the game to even smaller parts and simulate with the players than simulating the game as a whole with teams? sorry if I make no sense ;)

19 minutes ago, Liu Angyan said:

Thanks for the reply. I do understand that there are many possibilities in sports as I watch spots a lot but since I'm still starting out with coding I figured id do something simple first and than build on that. you mentioned the chances of a player scoring a goal on a goalie 1 v 1, how do I connect events such as that to the game simulated as a whole? I could add shots on goal and shots against to the simulation instead of goals per game and against. but than again how do I incorporate a players likelihood of getting a chance and scoring with the team as right now I only know how many chances a team created as a whole and how many goals they scored as a whole. should I break down the game to even smaller parts and simulate with the players than simulating the game as a whole with teams? sorry if I make no sense ;)

This is most likely beyond the beginner level to create an entire detailed simulation with a team vs another team in hockey. So you might have to 'dumb' down the events a bit.

You can either create a basic simulation that stacks all players offensive abilities against the other teams defensive to see if a goal can be reached before puck turn over. Then reverse it for the other team. Essentially like so:

1. Who wins the face off?

2. Face off winner is the attacking team

3. Run a simulation based on the attacking teams stats with RNG based events against the defending teams stats plus their goalie to see if a goal can be scored

4. Once puck turn over happens, just repeat the above

The above would be the simple approach.

Going into a full detailed simulation at this level isn't practical, and I honestly wouldn't have the time to go into details on all the simulation steps to take. If you had the ability to program a 2D or 3D hockey game with two computers playing against each other you would be able to tackle this challenge. Your ability to program AI will greatly impact the quality of the simulation itself. You need to account for all the many scenarios, penalties, offensive and defensive plays, ect... This is no easy task.

My advice is keep it simple and add more as you go. Steps 1 to 4 should get you started, just create a formula that uses offensive stats vs defensive stats, then add in the goalie stats for now.

 

Programmer and 3D Artist

thanks for the advice

ahhhh, sorry to drag this on but there is one more thing I can't fully understand. if I have different classes for players and teams than how do I connect the two? if I use the average offensive and defensive abilities of players to make a team offensive and defensive ability and sim based on that than how does the individual player ratings affect how many points a player gets? how do I get the star player to score more points when I am simulating team vs team?

Just now, Liu Angyan said:

ahhhh, sorry to drag this on but there is one more thing I can't fully understand. if I have different classes for players and teams than how do I connect the two? if I use the average offensive and defensive abilities of players to make a team offensive and defensive ability and sim based on that than how does the individual player ratings affect how many points a player gets? how do I get the star player to score more points when I am simulating team vs team?

You need to create a class for the simulation which handles the events, and feed in the applicable values to generate your end result.

Programmer and 3D Artist

This topic is closed to new replies.

Advertisement