-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRook.cpp
More file actions
47 lines (42 loc) · 1.04 KB
/
Copy pathRook.cpp
File metadata and controls
47 lines (42 loc) · 1.04 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
#include "Rook.h"
Rook::Rook(Position pos, char type, Board* board) : Piece(pos, type, board)
{
}
Rook::~Rook()
{
}
bool Rook::checkMove(const Position& pos) const
{
int moveBy;
if (pos.getNumber() == _index.getNumber())
{
if (pos.getLetter() < _index.getLetter())
moveBy = -1;
else
moveBy = 1;
for (unsigned int i = _index.getIntLetter() + moveBy; i != pos.getIntLetter(); i += moveBy)
{
Position curr('a' + i, _index.getNumber() + 1);
if ((*_board)[curr] != nullptr && !(curr == pos))
return false;
}
return true;
}
else if (pos.getLetter() == _index.getLetter())
{
if (_index.getNumber() < pos.getNumber())
moveBy = 1;
else
moveBy = -1;
for (unsigned int i = _index.getNumber() + moveBy; i != pos.getNumber(); i += moveBy)
{
Position curr(_index.getLetter(), i + 1);
if ((*_board)[curr] != nullptr && !(curr==pos))
return false;
}
return true;
}
// If the destination is not in the same columm or row, it is an illegal move
else
return false;
}