-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtracker.cpp
More file actions
93 lines (79 loc) · 2.07 KB
/
tracker.cpp
File metadata and controls
93 lines (79 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Description: Win/Loss/Tie Datastructure Definition
*/
#include "tracker.hpp"
void tracker::P1_Win()
{
p1.wins += 1;
}
void tracker::P2_Win()
{
p2.wins += 1;
}
void tracker::Tie()
{
ties += 1;
}
void tracker::record_game(int result)
{
switch(result)
{
//win
case 1:
{
this->P1_Win();
break;
}
//loss
case -1:
{
this->P2_Win();
break;
}
//tie
case 0:
{
this->Tie();
break;
}
}
}
void tracker::print_results(std::string p1_name, std::string p2_name) const
{
//Prints the results after calculating the various metrics.
unsigned long rounds = p1.wins + p2.wins + ties;
long double pct_wins = (long double)p1.wins / rounds * 100;
long double pct_ties = (long double)ties / rounds * 100;
long double pct_losses = (long double)p2.wins / rounds * 100;
std::string winner, loser;
if(p1.wins > p2.wins) // normal condition, we hope
{
winner = p1_name;
loser = p2_name;
}
else if(p2.wins > p1.wins) // swap p1 and p2 stats in the event of p1 loss
{
winner = p2_name;
loser = p1_name;
long double temp = pct_wins;
pct_wins = pct_losses;
pct_losses = temp;
}
else // catches a pure tie, statistically improbable but still
{
std::cout << "It was a tie, how strange. Did someone cheat?" << std::endl;
return;
}
std::cout << std:: endl;
std::cout << "Rounds: " << rounds << std::endl;
std::cout << "Wins: " << p1.wins << " (" << pct_wins << "%)" << std::endl;
std::cout << "Ties: " << ties << " (" << pct_ties << "%)" << std::endl;
std::cout << "Losses: " << p2.wins << " (" << pct_losses << "%)" << std::endl;
std::cout << std::endl;
std::cout << "Winning Algorithm: " << winner << std::endl;
std::cout << "Win Pct: " << pct_wins << "%" << std::endl;
std::cout << "Tie Pct: " << pct_ties << "%" << std::endl << std::endl;
std::cout << "Losing Algorithm: " << loser << std::endl;
std::cout << "Win Pct: " << pct_losses << "%" << std::endl;
std::cout << "Tie Pct: " << pct_ties << "%" << std::endl << std::endl;
}