-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadvancedbot.cpp
75 lines (61 loc) · 2.09 KB
/
advancedbot.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
#include "advancedbot.h"
AdvancedBot::AdvancedBot() { }
QString AdvancedBot::name()
{
return "AdvancedBot";
}
void AdvancedBot::setTurnTime(int miliseconds)
{
turnTime = miliseconds;
}
void AdvancedBot::setColor(CellState c)
{
color = c;
}
CellState AdvancedBot::getColor()
{
return color;
}
void AdvancedBot::processClick(Position)
{
}
void AdvancedBot::turnStart(Match input)
{
turnNumber++;
QVector<Position> best;
unsigned bestScore = 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 score = input.count(getColor());
//In early game play minimum and check the crosshairs
if(turnNumber > midGameTurn)
{
score = 45 - score;
for(char k = 1; k <= 8; ++k) if(n.get(Position(4, k)) == getColor()) score++;
for(char k = 1; k <= 8; ++k) if(n.get(Position(5, k)) == getColor()) score++;
for(int j = 1; j <= 8; ++j) if(n.get(Position(j, 4)) == getColor()) score++;
for(int j = 1; j <= 8; ++j) if(n.get(Position(j, 5)) == getColor()) score++;
}
//Corners
if(n.get(Position(1, 8)) == getColor()) score += 5;
if(n.get(Position(8, 8)) == getColor()) score += 5;
if(n.get(Position(1, 1)) == getColor()) score += 5;
if(n.get(Position(8, 1)) == getColor()) score += 5;
if(score > bestScore)
{
bestScore=score;
best.clear();
best.push_back(p);
}
else if (score == bestScore)
best.push_back(p);
}
}
Position result = best[QRandomGenerator::global()->bounded(best.size())];
QTimer::singleShot(turnTime, [this, result]() { emit turnFinished(this, result); } );
}