-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
56 lines (47 loc) · 1.36 KB
/
Player.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
56
#include "Player.h"
namespace chess {
Player::Player(Board* _board, Color _color) : board(_board) {
color = _color;
if (color == White) {
myPieceSquares = board->whitePieceSquares;
yourPieceSquares = board->blackPieceSquares;
myPiecesStr = board->whitePiecesStr;
yourPiecesStr = board->blackPiecesStr;
king = 'K';
}
else {
myPieceSquares = board->blackPieceSquares;
yourPieceSquares = board->whitePieceSquares;
myPiecesStr = board->blackPiecesStr;
yourPiecesStr = board->whitePiecesStr;
king = 'k';
}
}
Tree* Player::legalMoves() {
return board->findLegalMoves(myPieceSquares, yourPieceSquares, myPiecesStr, yourPiecesStr, king);
}
Tree* Player::availableMoves() {
return board->findAvailableMoves(myPieceSquares, yourPiecesStr);
}
bool Player::executeMove(Move* move) {
return board->executeMove(move, myPieceSquares, yourPieceSquares);
}
bool Player::revertMove(Move* move) {
return board->revertMove(move, myPieceSquares, yourPieceSquares);
}
bool Player::isKingInCheck() {
Tree* opponentMoves = board->findAvailableMoves(yourPieceSquares, myPiecesStr);
if (board->isKingInCheck(opponentMoves, king)) {
return true;
}
return false;
}
bool Player::isKingInCheck(Tree* opponentMoves) {
if (board->isKingInCheck(opponentMoves, king)) {
return true;
}
return false;
}
Player::~Player() {
}
}