-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindv_play.hpp
153 lines (121 loc) · 4.6 KB
/
indv_play.hpp
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
147
148
149
150
151
152
153
#ifndef indv_play_h
#define indv_play_h
#include "scrabble_piece.hpp"
#include "standard_board_builder.hpp"
#include <algorithm>
#include <iostream>
#include <vector>
/**
* This class represents a single play in the game of scrabble. A single play
* consists of 0 or more piece placements. A single piece-placement has three
* pieces of information: row, column, and piece. So, this class simply has
* three vectors to hold the information of the placements. Equality of index
* in these vectors implies association with the same placement.
*/
////////////////////////////////////////////////////////////////////////////////
class Indv_Play
////////////////////////////////////////////////////////////////////////////////
{
public:
/**
* Constructor - Simply reserves memory in the three vectors.
*/
Indv_Play()
{
//Note: it is not possible to have a play larger than the dimensions of the board
m_rows.reserve(Standard_Board_Builder::BOARD_DIM);
m_cols.reserve(Standard_Board_Builder::BOARD_DIM);
m_pieces.reserve(Standard_Board_Builder::BOARD_DIM);
m_force = false;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////// PRIMARY INTERFACE ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* place_piece - Adds a piece-placement to this play
*/
void place_piece(unsigned row, unsigned col, const Scrabble_Piece* placed_piece)
{
my_assert(placed_piece, "Tried to play a NULL piece");
m_rows.push_back(row);
m_cols.push_back(col);
m_pieces.push_back(placed_piece);
}
/**
* clear - Reset the state of the play to the empty play
*/
void clear()
{
m_rows.clear();
m_cols.clear();
m_pieces.clear();
m_force = false;
}
/**
* force - Set up play to not check word
*/
void force() { m_force = true; }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// QUERIES /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
bool is_forced() const { return m_force; }
/**
* get_size - Return the number of piece-placements involved in this play
*/
unsigned get_size() const
{
my_assert(m_rows.size() == m_cols.size(), "Row, col vectors out of sync");
my_assert(m_rows.size() == m_pieces.size(), "Row, piece vectors out of sync");
return m_rows.size();
}
/**
* get_ith_row - Return the row component of the i-th piece placement
*/
unsigned get_ith_row(unsigned idx) const
{
my_assert(idx < get_size(), "Recieved out of bounds index");
return m_rows[idx];
}
/**
* get_ith_col - Return the col component of the i-th piece placement
*/
unsigned get_ith_col(unsigned idx) const
{
my_assert(idx < get_size(), "Recieved out of bounds index");
return m_cols[idx];
}
/**
* get_ith_piece - Return the piece component of the i-th piece placement
*/
const Scrabble_Piece* get_ith_piece(unsigned idx) const
{
my_assert(idx < get_size(), "Recieved out of bounds index");
return m_pieces[idx];
}
/**
* operator<< - Produce a nice-looking output of this play
*/
std::ostream& operator<<(std::ostream& out) const;
Indv_Play& operator=(const Indv_Play& rhs) = default;
private: // ================ PRIVATE INTERFACE ================================
//////////////////////////////////////////////////////////////////////////////
////////////////////////// FORBIDDEN METHODS /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Indv_Play(const Indv_Play&);
//////////////////////////////////////////////////////////////////////////////
///////////////////////////// DATA MEMBERS ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//m_rows - The row components of the piece-placements
std::vector<unsigned> m_rows;
//m_cols - The col components of the piece-placements
std::vector<unsigned> m_cols;
//m_pieces - The piece components of the piece-placements
std::vector<const Scrabble_Piece*> m_pieces;
//m_force - Do not check word
bool m_force;
};
////////////////////////////////////////////////////////////////////////////////
///////////////////////// ASSCOCIATED OPERATIONS ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream& out, const Indv_Play& ip);
#endif