forked from ZXCroon/Wordable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.cpp
executable file
·108 lines (85 loc) · 2.14 KB
/
strategy.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
#include "strategy.h"
SelectStrategy::SelectStrategy(Env* env) : env(env), diffi(0) {
srand(time(0));
}
string SelectStrategy::next(int& difficulty) {
difficulty = diffi = chooseDifficulty();
int nowTimestamp = env->basic->getTimestamp();
for (int i = 1;; ++i) {
string word = env->vocList[diffi]->getItem(i);
Progress prog(env->fsbProg, word);
if (nowTimestamp - prog.getTimestamp() > gap(prog.getFamilarity())) {
return word;
}
}
}
void FormStrategy::setWord(const string& word) {
this->word = word;
str::clearEnds(this->word);
}
bool FormStrategy::isLegal() {
return legal;
}
bool FormStrategy::isOK() {
return ok;
}
// ------------------------
SmartSelection::SmartSelection(Env* env) : SelectStrategy(env) {
}
int SmartSelection::chooseDifficulty() {
int level = env->basic->getLevel();
int basicDiffi = level / (LEVEL_MAX / DIFFI_NUM), diffi;
srand(time(0));
int t = rand() % 10;
if (t == 0) diffi = basicDiffi - 2;
if (t >= 1 && t <= 2) diffi = basicDiffi - 1;
if (t >= 3 && t <= 6) diffi = basicDiffi;
if (t >= 7 && t <= 8) diffi = basicDiffi + 1;
if (t == 9) diffi = basicDiffi + 2;
if (diffi < 0) diffi = 0;
if (diffi >= DIFFI_NUM) diffi = DIFFI_NUM - 1;
return diffi;
}
FixedSelection::FixedSelection(Env* env, int fixedDiffi) :
SelectStrategy(env),
fixedDiffi(fixedDiffi) {
}
int FixedSelection::chooseDifficulty() {
return fixedDiffi;
}
RandomSelection::RandomSelection(Env* env) : SelectStrategy(env) {
}
int RandomSelection::chooseDifficulty() {
return rand() % DIFFI_NUM;
}
string RemOrNotForm::display() {
string res = "\n ";
for (int i = 1; i <= word.length() + 2; ++i) {
res += "-";
}
res += " \n| ";
res += word;
res += " |\n ";
for (int i = 1; i <= word.length() + 2; ++i) {
res += "-";
}
res += " \n\n";
res += " Remember or not? [y/n]:\n ";
return res;
}
void RemOrNotForm::rcvResponse(const string& resp) {
string s = resp;
str::clearEnds(s);
if (s == "y" || s == "Y") {
legal = true;
ok = true;
return;
}
if (s == "n" || s == "N") {
legal = true;
ok = false;
return;
}
legal = false;
ok = false;
}