-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimplebot.cpp
More file actions
51 lines (44 loc) · 1.23 KB
/
simplebot.cpp
File metadata and controls
51 lines (44 loc) · 1.23 KB
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
#include "simplebot.h"
SimpleBot::SimpleBot() { }
void SimpleBot::setTurnTime(int miliseconds)
{
turnTime = miliseconds;
}
void SimpleBot::setColor(CellState c)
{
color = c;
}
CellState SimpleBot::getColor()
{
return color;
}
QString SimpleBot::name()
{
return "Simple Bot";
}
void SimpleBot::turnStart(Match input)
{
QVector<Position> best;
unsigned max = 0;
for(char i = 1; i <= 8; ++i)
for(int j = 1; j <= 8; ++j)
{
Position p(j, i);
Match n(input);
if(n.get(p) == CellState::empty && n.makeTurn(p, getColor())) //Checking all available cells
{
unsigned profitCount = n.count(getColor());
if(profitCount > max) //Selecting cells with best score after turn
{
best.clear();
best.push_back(p);
max = profitCount;
}
else if(profitCount == max)
best.push_back(p);
}
}
Position result = best[QRandomGenerator::global()->bounded(best.size())];
QTimer::singleShot(turnTime, [this, result]() { emit turnFinished(this, result); } );
}
void SimpleBot::processClick(Position) {}