-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cc
98 lines (79 loc) · 2.09 KB
/
Player.cc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Player.cc
// chess
//
// Created by User on 2015-11-30.
// Copyright (c) 2015 Jonah Librach. All rights reserved.
//
#include "Player.h"
Player::Player(int playerNumber){
check = false;
rsgned = false;
game = NULL;
this -> playerNumber = playerNumber;
pieces = new std::set<Piece*>;
}
Player::~Player(){
}
int Player::getPlayerID() const{
return playerNumber;
}
Game* Player::getGame() const{
return game;
}
Piece* Player::getKing() const{
std::set<Piece*>::iterator it;
for(it = pieces -> begin(); it != pieces -> end(); ++it){
if((*it) -> getPieceID() == 'K' || (*it) -> getPieceID() == 'k')
return *it;
}
return NULL;
}
void Player::destroy(Piece* toDestroy){
if(toDestroy){
pieces -> erase(toDestroy);
delete toDestroy;
}
}
void Player::addPiece(Piece* p){
//std::cout << p -> getPieceID() << " assigned to player " << getPlayerID() << std::endl;
pieces -> insert(p);
}
void Player::setGame(Game* game){
this -> game = game;
}
bool Player::inCheck() const{
return check;
}
bool Player::resigned() const{
return rsgned;
}
void Player::calibrate(){
// std::cout << "Calibrating player " << getPlayerID() << std::endl;
// if(forward){
std::set<Piece*>::iterator it;
for(it = pieces -> begin(); it != pieces -> end(); ++it){
(*it) -> reset();
(*it) -> calibrate();
/* }
}else{
std::set<Piece*>::reverse_iterator rit;
for(rit = pieces -> rbegin(); rit != pieces -> rend(); ++rit)
(*rit) -> calibrate();
}*/
}
}
std::set<Move*>* Player::getMoveList(){
std::set<Move*>* moveList = new std::set<Move*>;
std::set<Piece*>::iterator it;
for(it = pieces -> begin(); it != pieces -> end(); ++it){
std::set<Move*>* pieceMoves = (*it) -> getLegalMoves();
if((*it) -> getColor() != getPlayerID()){
while(true){
cout << "YOU HAVE A BUG!" << endl;
}
}
moveList -> insert(pieceMoves -> begin(), pieceMoves -> end());
}
return moveList;
}