Originally Posted by
rogster001
Just thinking of this 'allow user to freetype commands without seeing any menus - without using a regex library also - could something like Levenshtein distance algorithm be useful. - As long as the user knows that the total game commands are say: pick up, walk, open, use : And the user is also aware of the names of the
items available in the current room - The available actions in each room would have to be internalised - then when user types "pick up lantern" - This would then have to be matched against the current rooms available actions and if the distance algorithm returns a close enough match (by a pre set threshold) then play is actioned. If not error 'you cant do that here' or whatever.
Using a Levenshtein distance algorithm sounds interesting. It could probably be interesting to use a combination of all methods in series. That is, first apply a "preprocessing function" that removes punctuation (.,!?) and flattens the any upcase characters. Then apply a Levenshtein distance algorithm to allow a generous match and spell correction then use regular expressions to allow synonyms and omission of parts of the sentence.
Originally Posted by
.RK
I suppose it does answer my question in that sadly there is no method in C that can truly do it. But the library idea is something I will definitely explore, and this distance algorithm sounds similar to what I had in mind. In fact I had seen a couple of things about this algorithm floating around during my search, but wasn't entirely sure if it was what I needed. So it's good to know it might be viable.
It depends, if you are on a POSIX box you probably have regex.h, otherwise get pcre. A regular expression is imo probably best suitable to allow variations in the input and synonyms. For example a regex string like this:
Code:
const char *woods = "^((go|travel) to (the |teh )?)?(forrest|woods)$";
Would allow for some variation in the input, including the lazy single "woods" "forrest" answer. If you also pre-process the string to flatten the case and get rid of punctuation and multiple whitespace, even more so.