-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.cpp
More file actions
62 lines (57 loc) · 1.45 KB
/
Copy pathKing.cpp
File metadata and controls
62 lines (57 loc) · 1.45 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
56
57
58
59
60
61
#include "King.h"
CKing::CKing()
:CPiece(KING)
,flagMove(false)
{
}
//-----------------------------------------------------------------
CKing::CKing(int aPosX, int aPosY, eColor aColor)
: CPiece(aPosX, aPosY, aColor, KING)
,flagMove(false)
{
};
//-----------------------------------------------------------------
CKing::~CKing(void)
{
}
//-----------------------------------------------------------------
void CKing::setFlagMove(bool aMove)
{
flagMove = aMove;
}
//-----------------------------------------------------------------
bool CKing:: isChack(vector<CPiece*> & aVector, vector<vector<sCell>>* aBoard)
{
int sizeVector = aVector.size();
for(int i = 0; i < sizeVector; i ++)
{
if(aVector[i]->getLive() == true && (aVector[i]->move(x * sizeCell, y * sizeCell, aBoard)) == SHOOT)
{
return true;
}
}
return false;
};
//-----------------------------------------------------------------
eMove CKing::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if(abs(x - tempX) <= 1 && abs(y - tempY) <= 1 )
{
int k = tempX - 1;
int m = tempY - 1;
if((*aBoard)[tempX][tempY].idPiece == idEmpty)
return LEGAL;
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(!flagMove && abs(x - tempX) == 2 && y == tempY)
{
return CASTLING;
}
else
return ILLEGAL;
};