-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointCounter.cpp
More file actions
61 lines (45 loc) · 1.51 KB
/
pointCounter.cpp
File metadata and controls
61 lines (45 loc) · 1.51 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
#include <map>
#include <string>
#include <vector>
int pointCounter(std::string input, std::vector<int> premiumTiles, bool allTiles){
std::map<char, int>pointValue;
//blank
pointValue['?'] = 0;
//1 point letter tiles
pointValue['a'] = 1; pointValue['e'] = 1; pointValue['i'] = 1; pointValue['l'] = 1; pointValue['n'] = 1;
pointValue['o'] = 1; pointValue['r'] = 1; pointValue['s'] = 1; pointValue['t'] = 1; pointValue['u'] = 1;
//2 point letter tiles
pointValue['d'] = 2; pointValue['g'] = 2;
//3 point letter tiles
pointValue['b'] = 3; pointValue['c'] = 3; pointValue['m'] = 3; pointValue['p'] = 3;
//4 point letter tiles
pointValue['f'] = 4; pointValue['h'] = 4; pointValue['v'] = 4; pointValue['w'] = 4; pointValue['y'] = 4;
//5 point letter tiles
pointValue['k'] = 5;
//8 point letter tiles
pointValue['j'] = 8; pointValue['x'] = 8;
//10 point letter tiles
pointValue['q'] = 10; pointValue['z'] = 10;
int totalPoints = 0, doubleWord = 0, tripleWord = 0;
for (unsigned i = 0; i <= input.length() - 1; i++){
if (premiumTiles.at(i) == 4){
doubleWord = doubleWord + 1;
}
else if (premiumTiles.at(i) == 5){
tripleWord = tripleWord + 1;
} else
totalPoints = totalPoints + (pointValue[input.at(i)]*premiumTiles.at(i));
}
while (doubleWord != 0){
totalPoints = totalPoints * 2;
doubleWord = doubleWord - 1;
}
while (tripleWord != 0){
totalPoints = totalPoints * 3;
tripleWord = tripleWord - 1;
}
if (allTiles == true){
totalPoints = totalPoints + 50;
}
return(totalPoints);
}