-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCAssessment.cpp
More file actions
118 lines (98 loc) · 3.75 KB
/
CAssessment.cpp
File metadata and controls
118 lines (98 loc) · 3.75 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// CAssessment.cpp
#include <iostream>
#include <cmath>
#include "CAssessment.h"
CAssessment::CAssessment(int type, const std::string &name, int cost, int achievement)
: CSpace(type, name), mMotivationalCost(cost), mAchievement(achievement), mCompleted(false)
{
}
int CAssessment::GetMotivationalCost() const
{
return mMotivationalCost;
}
int CAssessment::GetAchievement() const
{
return mAchievement;
}
bool CAssessment::IsCompleted() const
{
return mCompleted;
}
void CAssessment::SetCompleted(bool completed)
{
mCompleted = completed;
}
void CAssessment::PerformAction(CPlayer &player)
{
if (GetCompletedPlayers().empty())
{
if (player.GetMotivation() >= GetMotivationalCost())
{
player.IncreaseMotivation(-(GetMotivationalCost()));
player.IncreaseSuccess(GetAchievement());
SetCompleted(true);
AddCompletedPlayer(&player);
player.AddCompletedAssessment(player.GetYear(), this);
std::cout << player.GetName() << " completes " << GetName()
<< "for " << GetMotivationalCost()
<< " and achieves " << GetAchievement() << std::endl;
} else
{
std::cout << "Cannot do assessment due to low motivation" << std::endl;
}
} else
{
if (std::find(GetCompletedPlayers().begin(), GetCompletedPlayers().end(),
&player) != GetCompletedPlayers().end()) // check if that the current person has not completed the assessment
{
std::cout << GetName() << " has already been completed" << std::endl;
} else
{
int totalHelpCost = GetMotivationalCost(); // Shared cost
int totalHelpAchievement = GetAchievement(); // Shared achievement
int helpersCount = 1; // Including the current player
// Loop through all players who have completed this assessment to join in helping
// assumption -> the completed players' motivation does not deduct when helping
for (CPlayer *helper: GetCompletedPlayers())
{
helpersCount++;
}
// Distribute the achievement equally, rounded to the nearest whole number
int sharedAchievement = std::round(static_cast<float>(totalHelpAchievement) / helpersCount);
int sharedCost = std::round(static_cast<float>(totalHelpCost) / helpersCount);
player.IncreaseSuccess(sharedAchievement);
// Assuming that the motivation needed is divides by the helpersCount
player.IncreaseMotivation(-sharedCost); // Deduct the shared cost from the current player
for (CPlayer *helper: GetCompletedPlayers())
{
helper->IncreaseSuccess(sharedAchievement); // Award each helper their share of the success
std::cout << helper->GetName() << " helps and achieves " << sharedAchievement << std::endl;
}
AddCompletedPlayer(&player); // Mark assessment as completed for current player
player.AddCompletedAssessment(player.GetYear(), this);
}
}
}
CAssessment::CAssessment(int i, const std::string basicString)
{
}
const std::vector<CPlayer *> &CAssessment::GetCompletedPlayers() const
{
return completedPlayers;
}
void CAssessment::setCompletedPlayers(const std::vector<CPlayer *> &completedPlayers)
{
CAssessment::completedPlayers = completedPlayers;
}
void CAssessment::AddCompletedPlayer(CPlayer *player)
{
completedPlayers.push_back(player);
}
void CAssessment::RemoveCompletedPlayer(CPlayer *player)
{
auto it = std::find(completedPlayers.begin(), completedPlayers.end(), player);
if (it != completedPlayers.end())
{
completedPlayers.erase(it);
}
}