-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrabble_point_map.cpp
146 lines (137 loc) · 5.14 KB
/
scrabble_point_map.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "scrabble_point_map.hpp"
#include "scrabble_common.hpp"
#include "scrabble_exception.hpp"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
const Scrabble_Point_Map& Scrabble_Point_Map::instance()
////////////////////////////////////////////////////////////////////////////////
{
static Scrabble_Point_Map glob_instance;
return glob_instance;
}
////////////////////////////////////////////////////////////////////////////////
Scrabble_Point_Map::Scrabble_Point_Map()
////////////////////////////////////////////////////////////////////////////////
{
//iterate over every valid letter (A-Z)
for (char letter = 'A'; letter <= 'Z'; letter++) {
//check if 'letter' is a 1-pt letter
if (letter == 'E' || letter == 'A' || letter == 'I' || letter == 'O' ||
letter == 'N' || letter == 'R' || letter == 'T' || letter == 'L' ||
letter == 'S' || letter == 'U') {
//add the 1-pt letters to the map
m_point_map[letter] = 1;
}
//check if 'letter' is a 2-pt letter
else if (letter == 'D' || letter == 'G') {
//add the 2-pt letters to the map
m_point_map[letter] = 2;
}
//check if 'letter' is a 3-pt letter
else if (letter == 'B' || letter == 'C' || letter == 'M' || letter == 'P') {
//add the 3-pt letters to the map
m_point_map[letter] = 3;
}
//check if 'letter' is a 4-pt letter
else if (letter == 'F' || letter == 'H' || letter == 'V' ||
letter == 'W' || letter == 'Y') {
//add the 4-pt letters to the map
m_point_map[letter] = 4;
}
//check if 'letter' is a 5-pt letter
else if (letter == 'K') {
//add the 5-pt letters to the map
m_point_map[letter] = 5;
}
//check if 'letter' is a 8-pt letter
else if (letter == 'J' || letter == 'X') {
//add the 8-pt letters to the map
m_point_map[letter] = 8;
}
//check if 'letter' is a 10-pt letter
else if (letter == 'Q' || letter == 'Z') {
//add the 10-pt letters to the map
m_point_map[letter] = 10;
}
else {
my_static_assert(false,
obj_to_str(letter) + " should have fallen into one of the above categories");
}
}
//wild-card is worth 0
m_point_map['-'] = 0;
}
////////////////////////////////////////////////////////////////////////////////
unsigned Scrabble_Point_Map::get_point_val(char letter) const
////////////////////////////////////////////////////////////////////////////////
{
my_static_assert(m_point_map.find(letter) != m_point_map.end(),
obj_to_str(letter) + " was not in the point-map.");
return m_point_map.find(letter)->second;
}
////////////////////////////////////////////////////////////////////////////////
const Wwf_Point_Map& Wwf_Point_Map::instance()
////////////////////////////////////////////////////////////////////////////////
{
static Wwf_Point_Map glob_instance;
return glob_instance;
}
////////////////////////////////////////////////////////////////////////////////
Wwf_Point_Map::Wwf_Point_Map()
////////////////////////////////////////////////////////////////////////////////
{
//iterate over every valid letter (A-Z)
for (char letter = 'A'; letter <= 'Z'; letter++) {
//check if 'letter' is a 1-pt letter
if (letter == 'A' || letter == 'E' || letter == 'I' || letter == 'O' ||
letter == 'R' || letter == 'S' || letter == 'T') {
//add the 1-pt letters to the map
m_point_map[letter] = 1;
}
//check if 'letter' is a 2-pt letter
else if (letter == 'D' || letter == 'L' || letter == 'N' || letter == 'U') {
//add the 2-pt letters to the map
m_point_map[letter] = 2;
}
//check if 'letter' is a 3-pt letter
else if (letter == 'G' || letter == 'H' || letter == 'Y') {
//add the 3-pt letters to the map
m_point_map[letter] = 3;
}
//check if 'letter' is a 4-pt letter
else if (letter == 'B' || letter == 'C' || letter == 'F' ||
letter == 'M' || letter == 'P' || letter == 'W') {
//add the 4-pt letters to the map
m_point_map[letter] = 4;
}
//check if 'letter' is a 5-pt letter
else if (letter == 'K' || letter == 'V') {
//add the 5-pt letters to the map
m_point_map[letter] = 5;
}
//check if 'letter' is a 8-pt letter
else if (letter == 'X') {
//add the 8-pt letters to the map
m_point_map[letter] = 8;
}
//check if 'letter' is a 10-pt letter
else if (letter == 'J' || letter == 'Q' || letter == 'Z') {
//add the 10-pt letters to the map
m_point_map[letter] = 10;
}
else {
my_static_assert(false,
obj_to_str(letter) + " should have fallen into one of the above categories");
}
}
//wild-card is worth 0
m_point_map['-'] = 0;
}
////////////////////////////////////////////////////////////////////////////////
unsigned Wwf_Point_Map::get_point_val(char letter) const
////////////////////////////////////////////////////////////////////////////////
{
my_static_assert(m_point_map.find(letter) != m_point_map.end(),
obj_to_str(letter) + " was not in the point-map.");
return m_point_map.find(letter)->second;
}