-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatisticsKeeper.cpp
More file actions
78 lines (61 loc) · 3.13 KB
/
Copy pathStatisticsKeeper.cpp
File metadata and controls
78 lines (61 loc) · 3.13 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
#include "StatisticsKeeper.h"
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include "Game.h"
StatisticsKeeper::StatisticsKeeper() : accumulatedRounds(0), accumulatedPlayers(0)
{
for (int i = 0; i < 4; i++)
losers[i] = 0;
}
void StatisticsKeeper::printStats(ofstream& outFile)
{
int myWidth = 30;
outFile.fill('.');
outFile << "\n\n\n##############---Final Statistics---#############\n" << endl;
outFile << left << setw(myWidth) << "Games played: " << " " << numGames << endl;
outFile << setw(myWidth) << "Rounds Played: " << " " << accumulatedRounds << endl;
outFile << setw(myWidth) << "Average Rounds Per Game: " << " " << fixed << setprecision(1) << accumulatedRounds / (double)numGames << endl;
outFile << setw(myWidth) << "Players Generated : " << " " << accumulatedPlayers << endl;
outFile << setw(myWidth) << "Average Players Per Game: " << " " << accumulatedPlayers / (double)numGames << endl;
cout << "\n\n\n##############---Final Statistics---#############\n" << endl;
cout << left << setw(myWidth) << "Games played: " << " " << numGames << endl;
cout << setw(myWidth) << "Rounds Played: " << " " << accumulatedRounds << endl;
cout << setw(myWidth) << "Average Rounds Per Game: " << " " << fixed << setprecision(1) << accumulatedRounds / (double)numGames << endl;
cout << setw(myWidth) << "Players Generated : " << " " << accumulatedPlayers << endl;
cout << setw(myWidth) << "Average Players Per Game: " << " " << accumulatedPlayers / (double)numGames << endl;
double totalLosers = numGames;
double leftPercent = losers[Player::LEFT_PICKER] / totalLosers * 100;
double rightPercent = losers[Player::RIGHT_PICKER] / totalLosers * 100;
double randomPercent = losers[Player::RANDOM_PICKER] / totalLosers * 100;
double shufflerPercent = losers[Player::SHUFFLER] / totalLosers * 100;
outFile << "\n------Loser Statistics------\n";
outFile << setw(myWidth) << left << "Left Picker" << " " << setprecision(1) << fixed << leftPercent << "%" << endl;
outFile << setw(myWidth) << "Right Picker" << " " << rightPercent << "%" << endl;
outFile << setw(myWidth) << "Random Picker" << " " << randomPercent << "%" << endl;
outFile << setw(myWidth) << "Shuffler Picker" << " " << shufflerPercent << "%" << endl;
outFile << "\n#################################################" << endl;
cout << "\n------Loser Statistics------\n";
cout << setw(myWidth) << left << "Left Picker" << " " << setprecision(1) << fixed << leftPercent << "%" << endl;
cout << setw(myWidth) << "Right Picker" << " " << rightPercent << "%" << endl;
cout << setw(myWidth) << "Random Picker" << " " << randomPercent << "%" << endl;
cout << setw(myWidth) << "Shuffler Picker" << " " << shufflerPercent << "%" << endl;
cout << "\n#################################################" << endl;
}
void StatisticsKeeper::setNumGames(int gameCount)
{
numGames = gameCount;
}
void StatisticsKeeper::addLoser(Player::LoserType loser)
{
losers[loser]++;
}
void StatisticsKeeper::accumulateRounds(int currRounds)
{
accumulatedRounds += currRounds;
}
void StatisticsKeeper::accumulatePlayers(int currPlayers)
{
accumulatedPlayers += currPlayers;
}