-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.cpp
More file actions
49 lines (44 loc) · 1.14 KB
/
Bishop.cpp
File metadata and controls
49 lines (44 loc) · 1.14 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
#include "pch.h"
#include "Bishop.h"
#include "Board.h"
bool Bishop::move(Piece* boardMove[8][8], int srcX, int srcY, int destX, int destY)
{
Piece* src = boardMove[srcX][srcY];
Piece* dest = boardMove[destX][destY];
bool invalid = false;
if (abs(srcX - destX) == abs(srcY - destY))
{
int xIncrement = (destX - srcX) / (abs(destX - srcX));
int yIncrement = (destY - srcY) / (abs(destY - srcY));
for (int i = 1; i < abs(srcX - destX); i++)
{
if (boardMove[srcX + xIncrement * i][srcY + yIncrement * i]->getColor() != 'N')
return false;
}
}
else
return false;
/*if (invalid == false)
{*/
if (src->getColor() == 'W') //if piece is white
{
delete boardMove[srcX][srcY];
delete boardMove[destX][destY];
boardMove[srcX][srcY] = new EmptyCell('N', 'E');
boardMove[destX][destY] = new Rook('W', 'B');
return true;
}
else //if piece is black
{
delete boardMove[srcX][srcY];
delete boardMove[destX][destY];
boardMove[srcX][srcY] = new EmptyCell('N', 'E');
boardMove[destX][destY] = new Rook('B', 'B');
return true;
}
//}
//else
//{
// return false;
//}
}