-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueen.cpp
More file actions
83 lines (70 loc) · 1.78 KB
/
Queen.cpp
File metadata and controls
83 lines (70 loc) · 1.78 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
#include "pch.h"
#include "Queen.h"
#include "board.h"
bool Queen::move(Piece* boardMove[8][8], int srcX, int srcY, int destX, int destY)
{
Piece* src = boardMove[srcX][srcY];
Piece* dest = boardMove[destX][destY];
int yIncrement;
int xIncrement;
bool invalid = false;
if (srcX != destX || srcY != destY)
{
if (srcX == destX)
{
yIncrement = (destY - srcY) / (abs(destY - srcY));
for (int i = srcY + yIncrement; i != destY; i += yIncrement)
{
if (boardMove[destX][i]->getColor() != 'N')
return false;
}
}
else
if (srcY == destY)
{
xIncrement = (destX - srcX) / (abs(destX - srcX));
for (int i = srcX + xIncrement; i != destX; i += xIncrement)
{
if (boardMove[i][destY]->getColor() != 'N')
return false;
}
}
else
if (abs(srcX - destX) == abs(srcY - destY))
{
xIncrement = (destX - srcX) / (abs(destX - srcX));
yIncrement = (destY - srcY) / (abs(destY - srcY));
for (int i = 1; i < abs(srcX - destX); i++)
{
std::cout << "It got here somehow";
if (boardMove[srcX + xIncrement * i][srcY + yIncrement * i]->getColor() != 'N')
return false;
}
}
else
return false;
}
if (invalid == false)
{
if (src->getColor() == 'W') //if piece is white
{
delete boardMove[srcX][srcY];
delete boardMove[destX][destY];
boardMove[srcX][srcY] = new EmptyCell('N', 'E');
boardMove[destX][destY] = new Rook('W', 'Q');
return true;
}
else //if piece is black
{
delete boardMove[srcX][srcY];
delete boardMove[destX][destY];
boardMove[srcX][srcY] = new EmptyCell('N', 'E');
boardMove[destX][destY] = new Rook('B', 'Q');
return true;
}
}
else
{
return false;
}
}