-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.h
56 lines (40 loc) · 1.49 KB
/
Piece.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
#pragma once
#include <string>
typedef enum
{
eWhite,
eBlack
} EColour;
typedef enum
{
eUnknown,
eLeftCastle, // King moves to rook on left of board and rook jumps right over King
eRightCastle // King moves to rook on right of board and rook jumps left over King
} ECastleType;
class CBoard;
class CPiece
{
public:
explicit CPiece(EColour theColour, CBoard* pBoard, short thePosition);
virtual ~CPiece(void);
bool move(std::string sourcePos, std::string targetPos);
virtual bool move(short sourceRow, short targetRow, short sourceColumn, short targetColumn);
virtual bool isMoveLegal(short xrow, short yrow, short xcolumn, short ycolumn) = 0;
virtual bool isMoveBlocked(short xrow, short yrow, short xcolumn, short ycolumn) = 0;
bool isMovePossible(short x, short y);
void setPosition(short thePosition) { position = thePosition; }
short getPositionFromRowAndColumn(short row, short column) { return ((8 * (row-1)) + column) - 1; }
CPiece* getKing(EColour theColour);
EColour getColour() { return eColour; }
protected:
bool isTargetSquareBlocked(short yrow, short ycolumn);
EColour eColour;
CBoard* pBoard;
short position;
bool movedLastTurn;
private:
bool revertMove(short sourcePos, short targetPos, CPiece* pPiece, bool occupied);
bool getRowAndColumn(std::string position, short& row, short& column);
void updateMoveRecords();
void setMovedLastTurn(bool movedLastTurnSetting) { movedLastTurn = movedLastTurnSetting; }
};