blob: b7fd2c58b897e64a60eec936ff7f099b1166c171 (
plain) (
blame)
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
|
// Evol functions.
// Author:
// Reid
// Description:
// Riddle enigma validator
//
// Arguments
// 0 PC answer
// 1 English correct answer
// 2 Translated correct answer
// TODO: levenshtein(), similar_text(), and maybe even soundex()
function script riddlevalidation {
.@answer$ = strip(strtolower(getarg(0)));
.@good$ = strip(strtolower(getarg(1)));
.@good_translated$ = strip(strtolower(getarg(2)));
.@size_answer = getstrlen(.@answer$);
.@size_good = getstrlen(.@good$);
.@size_good_translated = getstrlen(.@good_translated$);
.@max = max(.@size_answer, .@size_good_translated, .@size_good);
// Input is too long.
if (.@max > 30) {
return false;
}
// if 90% of the word is correct
.@size_good *= 90;
.@size_good_translated *= 90;
freeloop(true);
for (.@i = 0; .@i < .@max; .@i++)
{
.@correct = 0;
.@correct_translated = 0;
for (.@k = .@k_translated = .@j = .@i; .@j < .@max; .@j++)
{
if (charat(.@answer$, .@j) == charat(.@good$, .@k)) {
.@correct++;
.@k++;
} else {
.@correct--;
}
if (charat(.@answer$, .@j) == charat(.@good_translated$, .@k_translated)) {
.@correct_translated++;
.@k_translated++;
} else {
.@correct_translated--;
}
}
// if most of the word is correct. (White spaces can and will mess you up!)
.@correct *= 100;
.@correct_translated *= 100;
if (.@correct >= .@size_good ||
.@correct_translated >= .@size_good_translated) {
freeloop(false);
return true;
}
}
freeloop(false);
return false;
}
|