42 lines · 1.2 KB
Raw Download
1
<?php
2
/**
3
 * Sanity-check the weight table.
4
 *
5
 *   php tools/simulate.php [runs] [year]
6
 *
7
 * Prints how often each seed and each region takes the title. 1 seeds should
8
 * dominate, 16 seeds should essentially never appear, and no region should be
9
 * favoured now that all four share one weight table.
10
 */
11
12
require_once __DIR__ . '/../src/bracket.php';
13
14
$runs = (int) ($argv[1] ?? 10000);
15
$data = bracket_load($argv[2] ?? null);
16
17
$bySeed = array_fill_keys(range(1, 16), 0);
18
$byRegion = [];
19
20
for ($i = 0; $i < $runs; $i++) {
21
    $result = simulate_tournament($data);
22
    $champ  = $result['champion'];
23
    $bySeed[$champ['seed']]++;
24
25
    foreach ($result['regions'] as $region) {
26
        if ($region['rounds'][4][0] === $champ) {
27
            $byRegion[$region['label']] = ($byRegion[$region['label']] ?? 0) + 1;
28
            break;
29
        }
30
    }
31
}
32
33
printf("%d tournaments, %d data\n\nChampion by seed\n", $runs, $data['year']);
34
foreach ($bySeed as $seed => $wins) {
35
    printf("  %2d  %6.2f%%  %s\n", $seed, 100 * $wins / $runs, str_repeat('#', (int) round(60 * $wins / $runs)));
36
}
37
38
printf("\nChampion by region (expect roughly even)\n");
39
foreach ($byRegion as $label => $wins) {
40
    printf("  %-8s %6.2f%%\n", $label, 100 * $wins / $runs);
41
}
42