-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.cpp
More file actions
59 lines (52 loc) · 1.18 KB
/
bot.cpp
File metadata and controls
59 lines (52 loc) · 1.18 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
52
53
54
55
56
57
58
59
#include "bot.h"
Bot::Bot(QObject *parent) :
QObject(parent),
easyBot(new EasyBot)
{
isBuildNow = false;
finishCreator = false;
tmpWords.clear();
}
Bot::~Bot()
{
delete easyBot;
if (finishCreator)
delete nyashBot;
if (isBuildNow)
{
delete tGenerator;
}
tmpWords.clear();
}
vector<Cell> Bot::nextTurn(int level, Field *field, Vocabulary *vocabulary)
{
if (rand() % 100 < 2)
level = 100;
// the catch with love
if (!isBuildNow && level >= EasyLevel)
{
isBuildNow = true;
tGenerator = new TrieCreator(vocabulary->getTrie());
connect(tGenerator, SIGNAL(resultReady(Trie*)), this, SLOT(createNyashBot(Trie*)));
}
if (level <= EasyLevel || (!finishCreator))
return easyBot->nextTurn(field, vocabulary);
else
{
while ((int)tmpWords.size() > 0)
{
nyashBot->addWord(tmpWords.back());
tmpWords.pop_back();
}
return nyashBot->nextTurn(field, vocabulary);
}
}
void Bot::createNyashBot(Trie *t)
{
finishCreator = true;
nyashBot = new NyashBot(t);
}
void Bot::addWord(string const &word)
{
tmpWords.push_back(word);
}