-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscrabble_word.hpp
91 lines (74 loc) · 3.21 KB
/
scrabble_word.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
#ifndef scrabble_word_h
#define scrabble_word_h
#include "scrabble_square.hpp"
#include "scrabble_piece.hpp"
#include <iostream>
#include <algorithm>
#include <string>
/**
* This class represents a word that has been (or will be) formed on the board.
* Scrabble_Words are usually associated with a piece-sequence on the board.
* This class knows how to add to itself based on incoming pieces. It knows how
* to score itself and transform itself into a standard string.
*
* An important concept for this class is the "order" of a piece within a
* Scrabble_Word. Recall that, in scrabble, words always read from top to
* bottom for vertical words and left to right for horizontal words. So, for
* vertical words, we use a piece's row-position as it's order; for horizontal
* words, we use it's column-position. Therefore, if we sort pieces of a word
* from lowest to highest order, the string produced will be the real word that
* is created.
*/
////////////////////////////////////////////////////////////////////////////////
class Scrabble_Word
////////////////////////////////////////////////////////////////////////////////
{
public:
/**
* Constructor
*/
Scrabble_Word() {}
/**
* Destructor
*/
~Scrabble_Word() {}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////// PRIMARY INTERFACE ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* add_component - Adds to this word. Note that components can be added in any
* order, just make sure the order arg is correct.
*
* piece - The piece that's being added as a part of this word
* bonus - The bonus associated with this part of the word
* order - The order of the piece (see class description if this doesnt make sense)
*/
void add_component(const Scrabble_Piece* piece, Bonus bonus, unsigned order);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// QUERIES /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* score - Returns the score that would be earned if this word were created.
*/
unsigned score() const;
/**
* get_word_str - Returns the word in string form.
*/
std::string get_word_str() const;
/**
* has_piece - Returns true if the word has a piece with a certain order
*/
bool has_piece(unsigned order) const { return m_word.find(order) != m_word.end(); }
/**
* operator<< - Produces output for this Scrabble_Word
*/
std::ostream& operator<<(std::ostream& out) const;
private: // ================== PRIVATE INTERFACE ==============================
//////////////////////////////////////////////////////////////////////////////
///////////////////////////// DATA MEMBERS ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// m_word - Maps order to the respective piece and associated bonus
std::map<unsigned, std::pair<const Scrabble_Piece*, Bonus> > m_word;
};
std::ostream& operator<<(std::ostream& out, const Scrabble_Word& sw);
#endif