-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.cpp
More file actions
44 lines (42 loc) · 1.19 KB
/
Knight.cpp
File metadata and controls
44 lines (42 loc) · 1.19 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
#include "Knight.h"
CKnight::CKnight()
:CPiece(KNIGHT)
{
}
//-----------------------------------------------------------------
CKnight::CKnight(int aPosX, int aPosY, eColor aColor)
: CPiece(aPosX, aPosY, aColor, KNIGHT)
{
}
//-----------------------------------------------------------------
CKnight::~CKnight()
{
}
//-----------------------------------------------------------------
eMove CKnight::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if((tempX - x == 2 || x - tempX == 2) && (tempY - y == 1 || y - tempY == 1))
{
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((tempY - y == 2 || y - tempY == 2) && (tempX - x == 1 || x - tempX == 1))
{
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;
};