A Season of Simulations - NFL Python Sim
Feb 6, 2022 23:16:20 GMT -6
Reignman, Funkytown, and 6 more like this
Post by Danchat on Feb 6, 2022 23:16:20 GMT -6
Welcome one, welcome all to a project I've poured way too much time into - I have developed a functional NFL game simulation in the Python language. To keep things brief, here's a quick explanation:
* The only user input needed is two files: A PLAY file (player database) and DCHT file (depth chart database) into the script. These can be taken from a Madden franchise or roster file. For this article, I will be using Rogerjinx's NFL 2021 files (for Madden 08, of course).
* Select two teams to play each other, and run the script. One entire game will be simulated in about 2-3 seconds.
What exactly is simulated, you ask? Let's look through a sample, one drive from a Vikings vs Bills game.
(note that the Yardline goes from 100 to 0, with 100 being the offense's goal line and 0 being the defense's goal line. So the 70 yard line is the offense's own 30)
The Python script will call plays depending on the situation, and also can be influenced by certain "slider" spreadsheets that can be edited by the user. Here are a few things that happened in the plays above:
* On 3rd and 1, the Vikings opt to go with a run with Cook, which is a base 45% chance plus 20% because it is 3rd and 1. As of now, that boost is universal among all teams
* Later on a 3rd and 5, the chances drop by 25%, meaning that our run % is down to 20%. The script chooses to throw intermediate (10-15 yards) to Osborn instead of a shorter throw. I have it so that all QBs will try to throw to the sticks or very close, and checkdowns are rare... perhaps for realism, I should find a way to increase futile passes on 3rd down?
* And then on a 3rd and 8, Kirk throws short to Jefferson for 5 yards. The odds on 3rd and 8 are 35% short, 58% intermediate, and 7% deep. It seems the script understands what Kirk would do here!
* Also, the odds of going for it on 4th & 3 in a tie game is 15%. This decreases the closer the team is to their own endzone, of course.
Each team has a few sliders that are unique to it: RunPassRatio is one of them, in which the Vikings are at 45% (which is the chance of a run on a neutral play). The pass-happy Bills are at 36%. Other sliders include runner and receiver usage, which for example sets a base 27% chance Jefferson is targeted and 21% for Thielen, and so on.
--------
Now that I've finished the brief summary of the script, let's go through an entire game with the Vikings vs Bills. Here we go!
Another missed FG! Ugh. This time we see a deep shot completed to Dede Westbrook, but then Kirk checks down on 3rd and 8 again.
The Bills' first drive:
Hey hey, a 3 and out! Allen got aggressive and went deep on 3rd and 12.
The Vikings' second drive:
A couple nice passes to Thielen puts the Vikings in position for a 10 yard score for Jefferson. They did well to overcome the sack on 2nd down... and we'll be seeing Kirk get sacked a lot with how Madden rates our OL so poorly.
Later on:
After a couple of punts, the Bills get down the field and tie the game up. They love to pass the ball as much as they do in real life.
The game continues to stay close, as they trade FGs. Mattison broke off a big 31 yarder against a good run defense, and Allen hit a big deep ball to Isaiah McKenzie, their 5th receiver. He only has a 5% chance of getting targeted on a play, so he took advantage of his chance!
Now for the 2 minute drill and how my script handles these scenarios:
The Vikings score quickly and use a timeout, leaving too much time for Allen. Coding ideal behavior in these situations that perfectly balance how much time to leave on the clock is difficult - I let the offense focus on trying to score before the end of the half so that points aren't thrown away due to time management gaffes.
But then the irony strikes - Allen goes 3 and out, and the Cousins & Co. start driving down the field, just to throw a Pick 6.
---
Let's cut to the final few drives of the game, where the score is 27-27 at the 2 minute warning:
Some issues have begun to pop up in the script - Kirk gets sacked on 3rd down, resulting in 4th and 22. The Vikings stupidly call a timeout, which is what the Bills should be doing. Clearly I need to fix the logic here.
We also see a bizarre issue where the Bills get an extra play with 0:00 left, and instead of punting like they should, they go for it on their own 28 yard line. I legitimately do not know why this happened.
Overtime time!
There is nothing stopping the Bills from passing the ball to Diggs as much as they want - it's all reliant on the odds. Eventually I may add individual defensive ratings so a top-notch CB may be able to shut down a receiver like Diggs, but that would be an advanced enhancement that I simply don't have time for.
The Vikings have to at least kick a FG, but need to go TD with so little time left.
And that's the game! A disappointing finish, but yet another close game - that's what the 2021 Vikings are all about!
A few notes to close this out:
* I will be updating this thread regularly, going through the whole 2021 schedule. I will incorporate the exact same injuries / players in and out of the lineup
* One thing that are not present are penalties. I have them on my to-do list, but they were tricky to integrate in with how they vary (pre-snap penalties, post-play penalties, etc)
* Player performance is based upon the Madden ratings. Things like Kirk's accuracy, Thielen's hands, our run defense, pass protection, and everything else is reliant on the player ratings that were assigned to each player. This is the crux of how well each team plays - I've carefully crafted the script to adjust for the best and worst play at each position (there is even an extra script that examines the PLAY file for what the max/min/avg/median are for each position. Yeah, I know, it was a lot of work)
* I am planning on a public release of this script via a webapp at some point in the future, but it will be a while
There are a lot of things I have yet to explain but I didn't want to bloat this out any further. Let me know what you think! How will the Vikings do in simulation land compared to how they actually played?
* The only user input needed is two files: A PLAY file (player database) and DCHT file (depth chart database) into the script. These can be taken from a Madden franchise or roster file. For this article, I will be using Rogerjinx's NFL 2021 files (for Madden 08, of course).
* Select two teams to play each other, and run the script. One entire game will be simulated in about 2-3 seconds.
What exactly is simulated, you ask? Let's look through a sample, one drive from a Vikings vs Bills game.
(note that the Yardline goes from 100 to 0, with 100 being the offense's goal line and 0 being the defense's goal line. So the 70 yard line is the offense's own 30)
The Python script will call plays depending on the situation, and also can be influenced by certain "slider" spreadsheets that can be edited by the user. Here are a few things that happened in the plays above:
* On 3rd and 1, the Vikings opt to go with a run with Cook, which is a base 45% chance plus 20% because it is 3rd and 1. As of now, that boost is universal among all teams
* Later on a 3rd and 5, the chances drop by 25%, meaning that our run % is down to 20%. The script chooses to throw intermediate (10-15 yards) to Osborn instead of a shorter throw. I have it so that all QBs will try to throw to the sticks or very close, and checkdowns are rare... perhaps for realism, I should find a way to increase futile passes on 3rd down?
* And then on a 3rd and 8, Kirk throws short to Jefferson for 5 yards. The odds on 3rd and 8 are 35% short, 58% intermediate, and 7% deep. It seems the script understands what Kirk would do here!
* Also, the odds of going for it on 4th & 3 in a tie game is 15%. This decreases the closer the team is to their own endzone, of course.
Each team has a few sliders that are unique to it: RunPassRatio is one of them, in which the Vikings are at 45% (which is the chance of a run on a neutral play). The pass-happy Bills are at 36%. Other sliders include runner and receiver usage, which for example sets a base 27% chance Jefferson is targeted and 21% for Thielen, and so on.
--------
Now that I've finished the brief summary of the script, let's go through an entire game with the Vikings vs Bills. Here we go!
Another missed FG! Ugh. This time we see a deep shot completed to Dede Westbrook, but then Kirk checks down on 3rd and 8 again.
The Bills' first drive:
Hey hey, a 3 and out! Allen got aggressive and went deep on 3rd and 12.
The Vikings' second drive:
A couple nice passes to Thielen puts the Vikings in position for a 10 yard score for Jefferson. They did well to overcome the sack on 2nd down... and we'll be seeing Kirk get sacked a lot with how Madden rates our OL so poorly.
Later on:
After a couple of punts, the Bills get down the field and tie the game up. They love to pass the ball as much as they do in real life.
The game continues to stay close, as they trade FGs. Mattison broke off a big 31 yarder against a good run defense, and Allen hit a big deep ball to Isaiah McKenzie, their 5th receiver. He only has a 5% chance of getting targeted on a play, so he took advantage of his chance!
Now for the 2 minute drill and how my script handles these scenarios:
The Vikings score quickly and use a timeout, leaving too much time for Allen. Coding ideal behavior in these situations that perfectly balance how much time to leave on the clock is difficult - I let the offense focus on trying to score before the end of the half so that points aren't thrown away due to time management gaffes.
But then the irony strikes - Allen goes 3 and out, and the Cousins & Co. start driving down the field, just to throw a Pick 6.
---
Let's cut to the final few drives of the game, where the score is 27-27 at the 2 minute warning:
Some issues have begun to pop up in the script - Kirk gets sacked on 3rd down, resulting in 4th and 22. The Vikings stupidly call a timeout, which is what the Bills should be doing. Clearly I need to fix the logic here.
We also see a bizarre issue where the Bills get an extra play with 0:00 left, and instead of punting like they should, they go for it on their own 28 yard line. I legitimately do not know why this happened.
Overtime time!
There is nothing stopping the Bills from passing the ball to Diggs as much as they want - it's all reliant on the odds. Eventually I may add individual defensive ratings so a top-notch CB may be able to shut down a receiver like Diggs, but that would be an advanced enhancement that I simply don't have time for.
The Vikings have to at least kick a FG, but need to go TD with so little time left.
And that's the game! A disappointing finish, but yet another close game - that's what the 2021 Vikings are all about!
A few notes to close this out:
* I will be updating this thread regularly, going through the whole 2021 schedule. I will incorporate the exact same injuries / players in and out of the lineup
* One thing that are not present are penalties. I have them on my to-do list, but they were tricky to integrate in with how they vary (pre-snap penalties, post-play penalties, etc)
* Player performance is based upon the Madden ratings. Things like Kirk's accuracy, Thielen's hands, our run defense, pass protection, and everything else is reliant on the player ratings that were assigned to each player. This is the crux of how well each team plays - I've carefully crafted the script to adjust for the best and worst play at each position (there is even an extra script that examines the PLAY file for what the max/min/avg/median are for each position. Yeah, I know, it was a lot of work)
* I am planning on a public release of this script via a webapp at some point in the future, but it will be a while
There are a lot of things I have yet to explain but I didn't want to bloat this out any further. Let me know what you think! How will the Vikings do in simulation land compared to how they actually played?