-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (62 loc) · 2.07 KB
/
Program.cs
File metadata and controls
70 lines (62 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Predictions;
var cts = new CancellationTokenSource();
var nrOfSims = 1000000;
Console.CancelKeyPress += (s, e) =>
{
cts.Cancel(true);
e.Cancel = true;
};
var database = await Data.ReadRankings(cts.Token);
var groups = await Data.ReadGroups(cts.Token);
var random = new GausianRandom();
var points = database.ToDictionary(x => x.Key, x => 0.0);
foreach (var group in groups)
{
var pairs = GetPairs(group);
foreach (var pair in pairs)
{
var countryA = database[pair.CountryA];
var countryB = database[pair.CountryB];
var matchPointsA = 0.0;
var matchPointsB = 0.0;
for (var i = 0; i < nrOfSims; i++)
{
var strengthA = random.Next(countryA);
var strengthB = random.Next(countryB);
var normalizedA = strengthA / (strengthA + strengthB);
var normalizedB = strengthB / (strengthA + strengthB);
if (Math.Abs(normalizedB - normalizedA) < 0.05)
{
matchPointsA += 1;
matchPointsB += 1;
}
else if (normalizedA > normalizedB)
{
matchPointsA += 3;
}
else
{
matchPointsB += 3;
}
}
points[pair.CountryA] += matchPointsA / nrOfSims;
points[pair.CountryB] += matchPointsB / nrOfSims;
}
Console.WriteLine("Group:");
var sortedGroup = group.Select(x => (x, points[x])).OrderByDescending(x => x.Item2);
foreach (var country in sortedGroup)
Console.WriteLine($"{country.Item1}: {Math.Round(country.Item2, 6)}");
}
if (cts.Token.IsCancellationRequested)
return;
Console.WriteLine("Finished");
Console.ReadLine();
static IEnumerable<(string CountryA, string CountryB)> GetPairs(IEnumerable<string> countries)
{
var count = countries.Count();
var sorted = countries.OrderBy(x => x).ToArray();
Console.WriteLine(string.Join(", ", sorted));
for (var i = 0; i < count - 1; i++)
for (var j = i + 1; j < count; j++)
yield return (sorted[i], sorted[j]);
}