+EOF
+}
+
+sub print_footer {
+ print <<"EOF";
+ </body>
+</html>
+EOF
+}
+
+my $locale = wloh_common::get_locale($cgi);
+my $aux_parms = wloh_common::get_auxillary_parameters($dbh, $locale);
+my $match_stddev = $aux_parms->{'score_stddev'} * sqrt(2.0);
+
+my $division = $cgi->param('divisjon') // -1;
+my $subdivision = $cgi->param('avdeling') // -1;
+my $match_player = $cgi->param('spiller');
+my $match_position = $cgi->param('posisjon');
+
+my $season = wloh_common::get_max_season($dbh, $locale);
+die "Nonexistent locale!" if (!defined($season));
+
+my @divisions = get_divisions($dbh, $locale, $season);
+$division = $divisions[0] if (!grep { $_ == $division } @divisions);
+my @subdivisions = get_subdivisions($dbh, $locale, $season, $division);
+$subdivision = $subdivisions[0] if (!grep { $_ == $subdivision } @subdivisions);
+
+get_players_and_ratings($dbh, $locale, $season, $division, $subdivision);
+@matches = get_matches($dbh, $locale, $season, $division, $subdivision);
+my $cov = get_covariance_matrix($dbh, keys %players);
+
+print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning');
+
+if (defined($match_player) && defined($match_position)) {
+ my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, \%ratings, $cov);
+
+ --$match_player;
+ --$match_position;
+
+ my @scenario = ();
+ open MCCALC, "$config::base_dir/mcwordfeud $trials $match_player $match_position < $tmpnam |"
+ or die "mccalc: $!";
+ while (<MCCALC>) {
+ /(\d+) (\d+) (-?\d+)/ or next;
+ chomp;
+ push @scenario, [ $1, $2, $3 ];
+ }
+ close MCCALC;
+ unlink $tmpnam;
+
+ my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players;
+ my $player_name = $players{$sorted_players[$match_player]};
+
+ if (scalar @scenario == 0) {
+ printf " <p>Fant ingen måte <strong>%s</strong> kan ende på <strong>%d.</strong> plass på.</p>\n",
+ $player_name, ($match_position + 1);
+ } else {
+ printf " <p>Scenario der <strong>%s</strong> ender på <strong>%d.</strong> plass:</p>\n",
+ $player_name, ($match_position + 1);
+ print " <ul>\n";
+ for my $m (@scenario) {
+ printf " <li>%s – %s: %+d</li>\n", $players{$m->[0]}, $players{$m->[1]}, $m->[2];
+ }
+ print " </ul>\n";
+ }
+} else {
+ POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8');
+ printf <<"EOF", $match_stddev;