-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.cpp
More file actions
58 lines (50 loc) · 1.75 KB
/
Bishop.cpp
File metadata and controls
58 lines (50 loc) · 1.75 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
#include "Bishop.h"
CBishop::CBishop()
:CPiece(BISHOP)
{
}
//-----------------------------------------------------------------
CBishop::CBishop(int aPosX, int aPosY, eColor aColor)
: CPiece(aPosX, aPosY, aColor, BISHOP)
{
}
//-----------------------------------------------------------------
CBishop::~CBishop()
{
}
//-----------------------------------------------------------------
eMove CBishop::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if(tempX - x == tempY - y) // it is a diagornal (1,1 and 8,8 secondary diagonal)
{
int delta = (tempX - x > 0) ? 1 : -1;
for(int i = x + delta, j = y + delta; i != tempX; i += delta, j += delta)
if((*aBoard)[i][j].idPiece != idEmpty)
return ILLEGAL;
if((*aBoard)[tempX][tempY].idPiece == idEmpty)
return LEGAL;
else if(color == WHITE && ((*aBoard)[tempX][tempY].idPiece >= idBlackKing))
return SHOOT;
else if(color == BLACK && ((*aBoard)[tempX][tempY].idPiece < idBlackKing))
return SHOOT;
else
return ILLEGAL;
}
else if(x - tempX == tempY - y) // it is a diagonal (1,8 adn 8 , 1)
{
int dx = ((tempX - x ) > 0) ? 1 : -1;
for(int i = x + dx, j = y - dx; i != tempX; i += dx, j -= dx)
if((*aBoard)[i][j].idPiece != idEmpty)
return ILLEGAL;
if((*aBoard)[tempX][tempY].idPiece == idEmpty)
return LEGAL;
else if(color == WHITE && (*aBoard)[tempX][tempY].idPiece >= idBlackKing)
return SHOOT;
else if(color == BLACK && (*aBoard)[tempX][tempY].idPiece < idBlackKing)
return SHOOT;
else
return ILLEGAL;
}
else
return ILLEGAL;
};