-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueen.cpp
More file actions
91 lines (80 loc) · 2.45 KB
/
Queen.cpp
File metadata and controls
91 lines (80 loc) · 2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Queen.h"
CQueen::CQueen()
:CPiece(QUEEN)
{
}
//-----------------------------------------------------------------
CQueen::CQueen(int aPosX, int aPosY, eColor aColor)
:CPiece(aPosX, aPosY, aColor, QUEEN)
{
}
//-----------------------------------------------------------------
CQueen::~CQueen()
{
}
//-----------------------------------------------------------------
eMove CQueen::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if(tempX - x == tempY - y) // as bishop ---- 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) //as bishop --- 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 if (x == tempX) //------ as rook it is row
{
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) //------ as rook it is colomn
{
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;
};