-
Notifications
You must be signed in to change notification settings - Fork 0
/
elomatchmaker.cpp
60 lines (51 loc) · 1.61 KB
/
elomatchmaker.cpp
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
#include "stdafx.h"
#include "elomatchmaker.h"
#include "player.h"
elomatchmaker::elomatchmaker()
{
}
elomatchmaker::~elomatchmaker()
{
}
const float elomatchmaker::LogRating(const float rating) const
{
return std::powf(10.f, rating / 400);
}
const float elomatchmaker::Expectation(const float first, const float second) const
{
float Ri = LogRating(first);
return Ri / (Ri + LogRating(second));
}
void elomatchmaker::ReportMatch(match* match_ended, const unsigned short winner)
{
float team_avg[2] =
{
match_ended->GetTeam(0)->GetAvgRating(),
match_ended->GetTeam(1)->GetAvgRating(),
};
for (size_t iteam = 0; iteam < 2; ++iteam)
{
for (size_t iplayer = 0; iplayer < 5; ++iplayer)
{
auto player_ptr = match_ended->GetTeam(iteam)->GetPlayer(iplayer).get();
float expected = Expectation(player_ptr->GetRating(), team_avg[1 - iteam]);
if (k * ((winner == iteam) - expected) < 0 && winner == iteam)
std::cout << "WTF?!";
player_ptr->UpdateRating(k * ((winner == iteam) - expected));
player_ptr->UpdateTilt(0.1f * (2 * (winner == iteam) - 1));
}
}
static short count = 0;
if (++count == 100 || (std::abs(team_avg[0] - team_avg[1]) > 100.f && (team_avg[0] > team_avg[1]) != (winner == 0)))
{
count = 0;
std::cout << team_avg[0] << (winner == 0 ? "(W)" : "") << " v. "
<< team_avg[1] << (winner == 1 ? "(W)" : "");
if (std::abs(team_avg[0] - team_avg[1]) > 200.f && (team_avg[0] > team_avg[1]) != (winner == 0))
std::cout << "!!! => ";
else
std::cout << " => ";
std::cout << match_ended->GetTeam(0)->GetAvgRating() << " v. "
<< match_ended->GetTeam(1)->GetAvgRating() << '\n';
}
}