-
Notifications
You must be signed in to change notification settings - Fork 2
/
wwf_piece_source.cpp
85 lines (79 loc) · 3.26 KB
/
wwf_piece_source.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
#include "wwf_piece_source.hpp"
#include "scrabble_point_map.hpp"
#include <cstdlib>
#include <ctime>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
Wwf_Piece_Source::Wwf_Piece_Source(const Scrabble_Game& parent)
: Piece_Source(parent)
////////////////////////////////////////////////////////////////////////////////
{
m_source.reserve(104);
const auto& wwf_pm = get_point_map();
//create and add the pieces to the vector
for (unsigned i = 13; i > 0; i--) {
m_source.push_back(new Scrabble_Piece(m_parent, 'E', wwf_pm));
if (i <= 9) {
m_source.push_back(new Scrabble_Piece(m_parent, 'A', wwf_pm));
}
if (i <= 8) {
m_source.push_back(new Scrabble_Piece(m_parent, 'I', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'O', wwf_pm));
}
if (i <= 7) {
m_source.push_back(new Scrabble_Piece(m_parent, 'T', wwf_pm));
}
if (i <= 6) {
m_source.push_back(new Scrabble_Piece(m_parent, 'R', wwf_pm));
}
if (i <= 5) {
m_source.push_back(new Scrabble_Piece(m_parent, 'D', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'N', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'S', wwf_pm));
}
if (i <= 4) {
m_source.push_back(new Scrabble_Piece(m_parent, 'H', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'L', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'U', wwf_pm));
}
if (i <= 3) {
m_source.push_back(new Scrabble_Piece(m_parent, 'G', wwf_pm));
}
if (i <= 2) {
m_source.push_back(new Scrabble_Piece(m_parent, 'B', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'C', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'F', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'M', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'P', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'V', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'W', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'Y', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, '-', wwf_pm));
}
if (i == 1) {
m_source.push_back(new Scrabble_Piece(m_parent, 'J', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'K', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'Q', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'X', wwf_pm));
m_source.push_back(new Scrabble_Piece(m_parent, 'Z', wwf_pm));
}
}
my_static_assert(m_source.size() == 104,
std::string("m_source is size ") + obj_to_str(m_source.size()) +
", expected size 104");
//do a couple shuffles
for (unsigned j = 0; j < 2; j++) {
for (unsigned i = 0; i < m_source.size(); i++) {
unsigned rand_idx = rand() % m_source.size();
const Scrabble_Piece* tmp = m_source[rand_idx];
m_source[rand_idx] = m_source[i];
m_source[i] = tmp;
}
}
}
////////////////////////////////////////////////////////////////////////////////
const Point_Map& Wwf_Piece_Source::get_point_map() const
////////////////////////////////////////////////////////////////////////////////
{
return Wwf_Point_Map::instance();
}