-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPawn.cpp
More file actions
77 lines (67 loc) · 1.82 KB
/
Pawn.cpp
File metadata and controls
77 lines (67 loc) · 1.82 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
#include "Pawn.h"
CPawn::CPawn()
:CPiece(PAWN)
{
}
//-----------------------------------------------------------------
CPawn::CPawn(int aPosX, int aPosY, eColor aColor)
: CPiece(aPosX, aPosY, aColor,PAWN)
{
};
//-----------------------------------------------------------------
CPawn::~CPawn()
{
}
//-----------------------------------------------------------------
eMove CPawn::_move(int tempX, int tempY, vector<vector<sCell>>* aBoard)
{
if(tempX == x)
{
if(color == WHITE)
{
if(tempY == 1 && (*aBoard)[tempX][tempY].idPiece == idEmpty)
return CONVERT_PAWN;
if(y == 7 && tempY == 5 && (*aBoard)[tempX][tempY].idPiece == idEmpty && (*aBoard)[tempX][tempY + 1].idPiece == idEmpty)
return LEGAL;
if(y - tempY == 1 && (*aBoard)[tempX][tempY].idPiece == idEmpty)
return LEGAL;
}
else
{
if(tempY == 8 && (*aBoard)[tempX][tempY].idPiece == idEmpty)
return CONVERT_PAWN;
if(y == 2 && tempY == 4 && (*aBoard)[tempX][tempY].idPiece == idEmpty && (*aBoard)[tempX][tempY - 1].idPiece == idEmpty)
return LEGAL;
if(tempY - y == 1 && (*aBoard)[tempX][tempY].idPiece == idEmpty)
return LEGAL;
}
}
else if(tempX - 1 == x || tempX + 1 == x)
{
if(color == WHITE)
{
if(y - tempY == 1)
{
if(tempY == 1 && (*aBoard)[tempX][tempY].idPiece >= idBlackKing)
return SHOOT_CONVERT_PAWN;
if((*aBoard)[tempX][tempY].idPiece >= idBlackKing)
return SHOOT;
else
return ILLEGAL;
}
}
else
{
if(tempY - y == 1)
{
if(tempY == 8 && (*aBoard)[tempX][tempY].idPiece >= idWhiteKing && (*aBoard)[tempX][tempY].idPiece < idBlackKing)
return SHOOT_CONVERT_PAWN;
if((*aBoard)[tempX][tempY].idPiece < idBlackKing && (*aBoard)[tempX][tempY].idPiece > idEmpty)
return SHOOT;
else
return ILLEGAL;
}
}
}
return ILLEGAL;
};