-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.h
67 lines (53 loc) · 1.92 KB
/
Board.h
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
/*
Julian Chow cchow11
Dhruv Dubey ddubey1
Fabio Fernandez ffernan9
*/
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include <map>
#include "Piece.h"
#include "Pawn.h"
#include "Rook.h"
#include "Knight.h"
#include "Bishop.h"
#include "Queen.h"
#include "King.h"
#include "Mystery.h"
typedef std::map<Chess::Position, Chess::Piece *>::const_iterator occIterator;
namespace Chess
{
class Board {
// Throughout, we will be accessing board positions using Position defined in Piece.h.
// The assumption is that the first value is the column with values in
// {'A','B','C','D','E','F','G','H'} (all caps)
// and the second is the row, with values in {'1','2','3','4','5','6','7','8'}
public:
// Default constructor
Board();
// Copy constructor
Board( const Board& brd );
// Destructor
~Board();
// Returns a const pointer to the piece at a prescribed location if it exists,
// or nullptr if there is nothing there.
const Piece* operator() (const Position& position) const;
// Attempts to add a new piece with the specified designator, at the given position.
// Throw exception for the following cases:
// -- the designator is invalid, throw exception with error message "invalid designator"
// -- the specified position is not on the board, throw exception with error message "invalid position"
// -- if the specified position is occupied, throw exception with error message "position is occupied"
void add_piece(const Position& position, const char& piece_designator);
// Displays the board by printing it to stdout
void display() const;
// Returns true if the board has the right number of kings on it
bool has_valid_kings() const;
private:
// The sparse map storing the pieces, keyed off locations
std::map<Position, Piece*> occ;
// Write the board state to an output stream
friend std::ostream& operator<< (std::ostream& os, const Board& board);
};
}
#endif // BOARD_H