-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiece.h
More file actions
62 lines (46 loc) · 1.7 KB
/
piece.h
File metadata and controls
62 lines (46 loc) · 1.7 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
#ifndef PIECE_H
#define PIECE_H
#include "helper.h"
#include "ChessBoard.h"
#include<string>
class ChessBoard;
class Piece {
protected:
colour side;
bool hasMoved;
ChessBoard* board_;
/*Checks for any interposing pieces on a diagonal line between the
moving (origin piece and its ultimate destination).
Returns false if an obstacle is encountered.*/
bool diagonalCheck(int originRow, int originColumn, int destinationRow,
int destinationColumn);
/*Checks for any interposing pieces on a straight line between the
moving (origin piece and its ultimate destination).
Returns false if an obstacle is encountered.*/
bool straightCheck(int originRow, int originColumn, int destinationRow,
int destinationColumn);
public:
/*Piece constructor:
Initialises piece colour, hasMoved and a pointer to the board*/
Piece(colour side, ChessBoard* board_) : side(side), hasMoved(false),
board_(board_) {};
//Virtual piece destructor
virtual ~Piece(){};
/*Pure virtual checks move validity with respect to:
1. The range of the relevant piece.
2. Whether there are any obstructions in its path (knight exempt).*/
virtual bool isMoveValid(int originColumn, int originRow,
int destinationColumn, int destinationRow) = 0;
//Pure virtual: returns name in form of string
virtual std::string getName() = 0;
//Returns side (Black or White) in form of colour enum
colour getSide() const {return side;}
//Returns side (Black or White) in form of string
std::string printSide();
//Returns boolean variable 'hasMoved' to show if a piece has previously
//moved.
bool getMoved() const {return hasMoved;}
//Sets 'hasMoved' to true after a piece's first and subsequent moves
void setMoved();
};
#endif