-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.cpp
More file actions
34 lines (27 loc) · 792 Bytes
/
Copy pathBishop.cpp
File metadata and controls
34 lines (27 loc) · 792 Bytes
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
#include "Bishop.h"
Bishop::Bishop(Position pos, char type, Board* board) : Piece(pos, type, board)
{
}
Bishop::~Bishop()
{
}
bool Bishop::checkMove(const Position& pos) const
{
int colMove, rowMove;
int letterDiff = _index.getLetter() - pos.getLetter();
int numDiff = _index.getNumber() - pos.getNumber();
if (std::abs(letterDiff) == std::abs(numDiff))
{
// Checking which direction the bishop moves to
letterDiff > 0 ? colMove = -1 : colMove = 1;
numDiff > 0 ? rowMove = -1 : rowMove = 1;
for (int i = 1; i < std::abs(letterDiff); i++)
{
Position curr(_index.getLetter() + colMove*i, _index.getNumber() + 1 + rowMove*i);
if ((*_board)[curr] != nullptr && !(curr == pos))
return false;
}
return true;
}
return false;
}