-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroker.cpp
113 lines (98 loc) · 2.46 KB
/
broker.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "broker.h"
Broker* Broker::m_Instance = NULL;
Broker::Broker()
{
gameBoard.initializeBoard();
QObject::connect(this, SIGNAL(gameStart()),
SLOT(onGameStart()));
currentGame = NULL;
}
Game *Broker::getCurrentGame() const
{
return currentGame;
}
void Broker::setCurrentGame(Game *value)
{
currentGame = value;
}
int Broker::getColor(int i, int j)
{
return (int)gameBoard.getColor(i,j);
}
void Broker::printBoard()
{
gameBoard.printBoard();
}
int Broker::getBoardSize(){
return BOARD_SIZE;
}
void Broker::setColor(int i, int j ,int c)
{
gameBoard.updateColor(i,j,c);
}
bool Broker::someoneWon()
{
return currentGame->someoneWon();
}
bool Broker::createGame(int blacktype, int whitetype, int blackalg, int whitealg, int blackdep, int whitedep)
{
currentGame = new Game(blacktype,whitetype,blackalg,whitealg,blackdep,whitedep);
currentGame->setGameBoard(&gameBoard);
updatePossible();
emit gameStart();
}
void Broker::onGameStart()
{
if(currentGame->getTurnType() == Constants::PC){
currentGame->pcMove(currentGame->getTurn());
cout<<"in ongamestart slot"<<endl;
flipTurn();
}
}
void Broker::gotInput(int i, int j )
{
std::cout<<"now im in got input"<<endl;
currentGame->gameBoard->checkBoard(Move(i,j),currentGame->getTurn());
emit updateBoard(); //at end of pc thinking
flipTurn();
}
void Broker::flipTurn()
{
if (currentGame->getTurn() == Constants::BLACK)
currentGame->setTurn(Constants::WHITE);
else
currentGame->setTurn(Constants::BLACK);
if(someoneWon()){
QCoreApplication::processEvents();
emit updateBoard();
emit gameEnd();
QCoreApplication::processEvents();
return;
}
cout<<"**************************************"<<endl;
printBoard();
emit updateBoard();
QCoreApplication::processEvents();
if(currentGame->getGameBoard()->noPossibleMove()){
cout<<"no possible move !"<<endl;
emit noPossible();
sleep(1);
QCoreApplication::processEvents();
sleep(2);
flipTurn();
return;
}
if (currentGame->getTurnType() == Constants::PC){
currentGame->pcMove(currentGame->getTurn());
QCoreApplication::processEvents();
flipTurn();
return;
}
emit updateBoard();
}
void Broker::endCurrentGame()
{
delete currentGame;
gameBoard.initializeBoard();
emit gameRestart();
}