-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
66 lines (50 loc) · 1.4 KB
/
Board.cpp
File metadata and controls
66 lines (50 loc) · 1.4 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
62
63
64
65
66
#include "Board.h"
Board::Board()
{
maxRows = 0;
guessLen = 0;
emptyBoard();
}
Board::Board(short maxGuesses, short codeLength)
{
maxRows = maxGuesses;
guessLen = codeLength;
emptyBoard();
}
// Destructor
Board::~Board() {}
// ACCESSOR FUNCTIONS
const std::vector<BoardRow>& Board::getAllRows() const { return allRows; }
// Returns the length of a guess
size_t Board::getGuessLen() const { return guessLen; }
// Returns the current number of rows in the board
short Board::getCurrentRows() const { return currentRows; }
// Returns maximum number of rows
short Board::getMaxRows() const { return maxRows; }
// Returns number of unused guesses (empty rows)
short Board::getUnusedGuesses() const
{
return maxRows - currentRows;
}
// MUTATOR FUNCTIONS
void Board::addRow(BoardRow newRow)
{
if (currentRows < maxRows and isValidRow(newRow)) {
allRows.push_back(newRow);
currentRows++;
}
}
// Empties the board for a new round
void Board::emptyBoard()
{
allRows.clear();
currentRows = 0;
}
// PRIVATE FUNCTIONS
// check if row is valid for current board setup
bool Board::isValidRow(BoardRow row)
{
std::string guess = row.getGuess();
Feedback feedback = row.getFeedback();
return (guess.length() == guessLen) and (feedback.getRightSlots() + feedback.getWrongSlots() <= guessLen);
}