summaryrefslogtreecommitdiff
path: root/npc/functions
diff options
context:
space:
mode:
Diffstat (limited to 'npc/functions')
-rw-r--r--npc/functions/riddle.txt35
1 files changed, 15 insertions, 20 deletions
diff --git a/npc/functions/riddle.txt b/npc/functions/riddle.txt
index fb503e3b3..4ccde67d8 100644
--- a/npc/functions/riddle.txt
+++ b/npc/functions/riddle.txt
@@ -12,9 +12,9 @@
// TODO: levenshtein(), similar_text(), and maybe even soundex()
function script riddlevalidation {
- .@answer$ = strtolower(getarg(0));
- .@good$ = strtolower(getarg(1));
- .@good_translated$ = strtolower(getarg(2));
+ .@answer$ = strip(strtolower(getarg(0)));
+ .@good$ = strip(strtolower(getarg(1)));
+ .@good_translated$ = strip(strtolower(getarg(2)));
.@size_answer = getstrlen(.@answer$);
.@size_good = getstrlen(.@good$);
@@ -23,14 +23,15 @@ function script riddlevalidation {
.@max = max(.@size_answer, .@size_good_translated, .@size_good);
// Input is too long.
- if (.@max > 20)
- {
+ if (.@max > 30) {
return false;
}
- .@size_good *= 70;
- .@size_good_translated *= 70;
+ // if 90% of the word is correct
+ .@size_good *= 90;
+ .@size_good_translated *= 90;
+ freeloop(true);
for (.@i = 0; .@i < .@max; .@i++)
{
.@correct = 0;
@@ -38,24 +39,17 @@ function script riddlevalidation {
for (.@k = .@k_translated = .@j = .@i; .@j < .@max; .@j++)
{
- if (charat(.@answer$, .@j) == charat(.@good$, .@k))
- {
+ if (charat(.@answer$, .@j) == charat(.@good$, .@k)) {
.@correct++;
.@k++;
- }
- else
- {
+ } else {
.@correct--;
}
- if (charat(.@answer$, .@j) ==
- charat(.@good_translated$, .@k_translated))
- {
+ if (charat(.@answer$, .@j) == charat(.@good_translated$, .@k_translated)) {
.@correct_translated++;
.@k_translated++;
- }
- else
- {
+ } else {
.@correct_translated--;
}
}
@@ -64,11 +58,12 @@ function script riddlevalidation {
.@correct_translated *= 100;
if (.@correct >= .@size_good ||
- .@correct_translated >= .@size_good_translated)
- {
+ .@correct_translated >= .@size_good_translated) {
+ freeloop(false);
return true;
}
}
+ freeloop(false);
return false;
}