-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.cpp
More file actions
35 lines (31 loc) · 935 Bytes
/
King.cpp
File metadata and controls
35 lines (31 loc) · 935 Bytes
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
#include "pch.h"
#include "King.h"
#include "Board.h"
bool King::move(Piece* boardMove[8][8], int srcX, int srcY, int destX, int destY)
{
int calcRow = destX - srcX;
int calcDest = destY - srcY;
Piece* src = boardMove[srcX][srcY];
Piece* dest = boardMove[destX][destY];
if (((calcRow >= -1) && (calcRow <= 1)) && ((calcDest >= -1) && (calcDest <= 1)))
{
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 King('W', 'K');
return true;
}
else if (src->getColor() == 'B')//if piece is black
{
delete boardMove[srcX][srcY];
delete boardMove[destX][destY];
boardMove[srcX][srcY] = new EmptyCell('N', 'E');
boardMove[destX][destY] = new King('B', 'K');
return true;
}
else return false;
}
else return false;
}