Advertisement
fuzzybluerain

AFLM Simulator

Mar 16th, 2022
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.37 KB | None | 0 0
  1. homesshots = 0; homegoals = 0; homebehinds = 0;
  2. awaysshots = 0; awaygoals = 0; awaybehinds = 0;
  3. % These are the variables set at the start of each match - obviously, games
  4. % start with a 0-0 score and this means we don't have to remember it before
  5. % each one (which would've come in handy if we were automating it).
  6.  
  7. homescorepercent = homemargin*0.0023 + 0.5;
  8. % Based on the results of the 2021 AFLM season - teams that win games have
  9. % more than 50% of the total points scored in a game, and proportion
  10. % increases (surprisingly, for typical margins, more or less linearly) as
  11. % overall margin does.
  12.  
  13. sshots = round(((log((1/((1/(rand()))-1))))*(10/3))+44);
  14. % This is working backwards from a formula described in the text of the
  15. % article to randomly decide how many scoring shots there are in our
  16. % simulation - 44 is the average number, this decides how low or high it
  17. % is.
  18.  
  19. for k = 1:sshots
  20.     if rand() < homescorepercent
  21.         homesshots = homesshots + 1;
  22.     else
  23.         awaysshots = awaysshots + 1;
  24.     end
  25. end
  26. % This is based around the assumption that the pattern of scoring shots is
  27. % random, which won't be true but still holds together well enough. Based
  28. % on the proportion of scores derived above, we essentially toss a weighted
  29. % coin once for each scoring shot in the game.
  30.  
  31. for x = 1:homesshots
  32.     if rand() < 0.5237
  33.         homegoals = homegoals + 1;
  34.     else
  35.         homebehinds = homebehinds + 1;
  36.     end
  37. end
  38. for y = 1:awaysshots
  39.     if rand() < 0.5237
  40.         awaygoals = awaygoals + 1;
  41.     else
  42.         awaybehinds = awaybehinds + 1;
  43.     end
  44. end
  45. % 0.5237 is the proportion of scoring shots that were goals in the 2021
  46. % season - again, we're assuming that goals and behinds are randomly
  47. % distributed.
  48.  
  49. homescore = homegoals*6 + homebehinds;
  50. awayscore = awaygoals*6 + awaybehinds;
  51. % Pretty self-explanatory, just converting our scores into a sum that would
  52. % make it easier to determine who won - and see where that goes for the
  53. % ladder.
  54.  
  55. if homescore > awayscore
  56.     homepoints = 4;
  57. elseif homescore == awayscore
  58.     homepoints = 2;
  59.     awaypoints = 2;
  60. else
  61.     awaypoints = 4;
  62. end
  63. % MATLAB does point out to me that these values are unused, which is
  64. % because I'm not very good at getting variables out of a function and into
  65. % the main simulation program! Either way, this would go on a simulated
  66. % ladder across the season.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement