-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRook.cpp
More file actions
81 lines (73 loc) · 1.51 KB
/
Rook.cpp
File metadata and controls
81 lines (73 loc) · 1.51 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Rook.h"
CRook::CRook()
:CPiece(ROOK)
,flagMove(false)
{
}
//-----------------------------------------------------------------
CRook::CRook(int aPosX, int aPosY, eColor aColor)
: CPiece(aPosX, aPosY, aColor, ROOK)
,flagMove(false)
{
}
//-----------------------------------------------------------------
CRook::~CRook()
{
}
//-----------------------------------------------------------------
void CRook::setFlagMove(bool aMove)
{
flagMove = aMove;
};
//-----------------------------------------------------------------
eMove CRook::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if(x == tempX)
{
int dy = (y < tempY) ? 1 : -1;
for(int i = y + dy; i != tempY; i += dy)
{
if((*aBoard)[x][i].idPiece != idEmpty)
return ILLEGAL;
}
if((*aBoard)[x][tempY].idPiece == idEmpty)
{
return LEGAL;
}
if(color == WHITE && (*aBoard)[x][tempY].idPiece >= idBlackKing)
{
return SHOOT;
}
else if(color == BLACK && (*aBoard)[x][tempY].idPiece < idBlackKing)
{
return SHOOT;
}
else
return ILLEGAL;
}
else if(y == tempY)
{
int dx = (x < tempX) ? 1 : -1;
for(int i = x + dx; i != tempX; i += dx)
{
if((*aBoard)[i][y].idPiece != idEmpty)
return ILLEGAL;
}
if((*aBoard)[tempX][y].idPiece == idEmpty)
{
return LEGAL;
}
if(color == WHITE && (*aBoard)[tempX][y].idPiece >= idBlackKing)
{
return SHOOT;
}
else if(color == BLACK && (*aBoard)[tempX][y].idPiece < idBlackKing)
{
return SHOOT;
}
else
return ILLEGAL;
}
else
return ILLEGAL;
};