Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- homesshots = 0; homegoals = 0; homebehinds = 0;
- awaysshots = 0; awaygoals = 0; awaybehinds = 0;
- % These are the variables set at the start of each match - obviously, games
- % start with a 0-0 score and this means we don't have to remember it before
- % each one (which would've come in handy if we were automating it).
- homescorepercent = homemargin*0.0023 + 0.5;
- % Based on the results of the 2021 AFLM season - teams that win games have
- % more than 50% of the total points scored in a game, and proportion
- % increases (surprisingly, for typical margins, more or less linearly) as
- % overall margin does.
- sshots = round(((log((1/((1/(rand()))-1))))*(10/3))+44);
- % This is working backwards from a formula described in the text of the
- % article to randomly decide how many scoring shots there are in our
- % simulation - 44 is the average number, this decides how low or high it
- % is.
- for k = 1:sshots
- if rand() < homescorepercent
- homesshots = homesshots + 1;
- else
- awaysshots = awaysshots + 1;
- end
- end
- % This is based around the assumption that the pattern of scoring shots is
- % random, which won't be true but still holds together well enough. Based
- % on the proportion of scores derived above, we essentially toss a weighted
- % coin once for each scoring shot in the game.
- for x = 1:homesshots
- if rand() < 0.5237
- homegoals = homegoals + 1;
- else
- homebehinds = homebehinds + 1;
- end
- end
- for y = 1:awaysshots
- if rand() < 0.5237
- awaygoals = awaygoals + 1;
- else
- awaybehinds = awaybehinds + 1;
- end
- end
- % 0.5237 is the proportion of scoring shots that were goals in the 2021
- % season - again, we're assuming that goals and behinds are randomly
- % distributed.
- homescore = homegoals*6 + homebehinds;
- awayscore = awaygoals*6 + awaybehinds;
- % Pretty self-explanatory, just converting our scores into a sum that would
- % make it easier to determine who won - and see where that goes for the
- % ladder.
- if homescore > awayscore
- homepoints = 4;
- elseif homescore == awayscore
- homepoints = 2;
- awaypoints = 2;
- else
- awaypoints = 4;
- end
- % MATLAB does point out to me that these values are unused, which is
- % because I'm not very good at getting variables out of a function and into
- % the main simulation program! Either way, this would go on a simulated
- % ladder across the season.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement