-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.cpp
74 lines (65 loc) · 1.36 KB
/
score.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
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* score.cpp
*
* Implementation of the score. Handles calculating of score for different
* power systems.
*
* by: Ashton Stephens
* date: 12-18-17
* documented: 3-23-19
*
*/
#include "score.h"
Score::~Score()
{
}
// adds the index created to the score vector
void Score::operator += (int index)
{
// Increase the size of the score vector if the index doesn't
while (score_vector_.size() <= index) score_vector_.push_back(0);
score_vector_.at(index) += 1;
updated_ = true;
}
void Score::set_power (int power)
{
if (power != power_) {
updated_ = true;
power_ = power;
}
}
std::string Score::get_string ()
{
if (updated_) {
updated_ = false;
value_ = calculated_score();
str_ = std::to_string(value_);
}
return str_;
}
int Score::get_value ()
{
if (updated_) {
updated_ = false;
value_ = calculated_score();
str_ = std::to_string(value_);
}
return value_;
}
// returns val to the power of pow
int power_opp (const int val, const int pow)
{
int ret = 1;
for (int i = 0; i < val; ++i)
ret *= pow;
return ret;
}
int Score::calculated_score ()
{
int calc_score = 0;
int size = score_vector_.size();
for (int i = 0; i < size; ++i) {
calc_score += score_vector_[i] * power_opp (i,power_);
}
return calc_score;
}