-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepo.cpp
More file actions
205 lines (164 loc) · 4.46 KB
/
Copy pathDepo.cpp
File metadata and controls
205 lines (164 loc) · 4.46 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "Depo.h"
#include <QtDebug>
#include <qmath.h>
#include <qstack.h>
Depo::Depo(QString b,QWidget *parent) : QWidget(parent)
{
size = (b.length()%2 == 0?4:5);
boardLetters = b;
ifChosen = nullptr;
qDebug() << "new file name recursion";
currentWord = "abc";
QFile qFile(":/res/EnglishWords.txt");
if (!qFile.open(QIODevice::ReadOnly)) {
throw new std::runtime_error("Resource file not found!");
}
this->lex = new Lexicon(qFile);
}
QString Depo::toWord(QStack<int> s)
{
QString word;
QStack<int> tmp;
while(!s.isEmpty()) {
word.insert(0,boardLetters.at(s.top()));
tmp.push(s.pop());
}
while(!tmp.isEmpty()) {
s.push(tmp.pop());
}
return word.toLower();
}
void Depo::setBoardLetters(QString b)
{
this->boardLetters = b;
}
void Depo::recursion()
{
if(index->isEmpty()) return;
QString temp = toWord(*index);
if(this->lex->containsPrefix(temp.toStdString())){
if(this->lex->contains(temp.toStdString())){
this->currentWord = temp;
emit isWord();
}
int ax = index->top() / size,ay = index->top() % size;
for (int i = 0;i < size*size;++i) {
int ix = i / size,iy = i % size;
if(!ifChosen[i] && ix-ax >= -1 && ix-ax <= 1 && iy-ay >= -1 && iy-ay <= 1){
index->push(i);ifChosen[i] = true;
recursion();
index->pop();ifChosen[i] = false;
}
}
}
else if(this->lex->contains(temp.toStdString())){
this->currentWord = temp;
emit isWord();
}
/* switch(WordSituation(temp))
{
case 0:
return;
case 1:
if(temp.length() > 3) {
this->currentWord = temp;
emit isWord();}
return;
case 2: case 3:
if(WordSituation(temp) == 3 && temp.length() >3){
this->currentWord = temp;
emit isWord();
}
int ax = index->top() / size,ay = index->top() % size;
for (int i = 0;i < size*size;++i) {
int ix = i / size,iy = i % size;
if(!ifChosen[i] && ix-ax >= -1 && ix-ax <= 1 && iy-ay >= -1 && iy-ay <= 1){
index->push(i);ifChosen[i] = true;
recursion();
index->pop();ifChosen[i] = false;
}
}
}
*/
}
//recursion
void Depo::addALlWords()
{
index = new QStack<int>;
ifChosen = new bool[size*size];
for(int i = 0;i < size*size;++i)
{
qDebug() << i << "recurson";
index->push(i);ifChosen[i] = true;
recursion();
index->pop();ifChosen[i] = false;
}
delete index;
}
/*
int Depo::WordSituation(QString text)
{
no such word = 0
* is a word = 1
* posible to be a word = 2
* is a word and posible to be longer = 3
if(words.contains(text+'\n')){
str = words.value(words.indexOf(text)+1);
str.resize(text.length());
if(str == text) return 3;
else return 1;
}
QString str;
int i = words.indexOf(text.left(1));
bool isWord = 0;
while(i < words.length()){
str = words.value(i);
if(str == text) isWord = 1;
else if(str > text){
str.resize(text.length());
if(str == text && isWord) return 3;
else if(str == text && !isWord) return 2;
else if(isWord) return 1;
else return 0;
}
++i;
}
return false;
bool isWord = 0;
QString flag = myfile->readLine();
flag.remove(flag.length()-1,1);
QString string;
while(string != flag){
// QByteArray line = myfile->readLine();
string = myfile->readLine();
QString str(string.remove(string.length()-1,1));
if(str == text)
isWord = 1;
else if(str > text){
str.resize(text.length());
if(str == text && isWord == 1) {
return 3;
}
else if(str == text && isWord == 0) {
return 2;
}
else if(str != text && isWord == 1) {
return 1;
}
else {
return 0;
}
}
}
return false;
if(this->lex->contains(text.toStdString()))
{
if(this->lex->containsPrefix(text.toStdString())) return 3;
else return 1;
}
else {
if(this->lex->containsPrefix(text.toStdString())) return 2;
else return 0;
}
}
*/