-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathking.cpp
55 lines (45 loc) · 1.06 KB
/
king.cpp
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
#include "king.h"
#include "Board.h"
#include "Spot.h"
King::King(bool white) : Piece(white)
{
}
bool King::isCastlingDone()
{
return this->castlingDone == true;
}
void King::setCastlingDone(bool castlingDone)
{
this->castlingDone = castlingDone;
}
bool King::canMove(Board *board, Spot *start, Spot *end)
{
// we can't move the piece to a Spot that
// has a piece of the same color
if (end->getPiece()->isWhite() == this->isWhite())
{
return false;
}
int x = std::abs(start->getX() - end->getX());
int y = std::abs(start->getY() - end->getY());
if (x + y == 1)
{
// check if this move will not result in the king
// being attacked if so return true
return true;
}
return this->isValidCastling(board, start, end);
}
bool King::isValidCastling(Board *board, Spot *start, Spot *end)
{
if (this->isCastlingDone())
{
return false;
}
// Logic for returning true or false
}
bool King::isCastlingMove(Spot *start, Spot *end)
{
// check if the starting and
// ending position are correct
}