Search the web for "natural language parsers." Many MUDs have very complex input parsers nowadays that let you do things like:
> get the first green sword in the 2nd wood crate
> sell it to bob
Everquest's system is actually very, very simple. It could be easily copied with simple code like the following:
And a sample run:
std::string sayto(std::string msg)
std::map<std::string, std::string>::iterator itr = responses.begin();
for( ; itr != responses.end(); ++itr)
if(msg.find(itr->first) != std::string::npos)
return "I do not understand.";
void add_response(std::string key, std::string resp)
responses[key] = resp;
std::map<std::string, std::string> responses;
r.add_response("hail", "Hello traveller! Hrm, now where did I put those [rusty swords]?");
r.add_response("rusty sword", "Bring me rusty swords and I'll give you a [prize]!");
r.add_response("prize", "Shh! I can't tell you abou that!");
std::cout << "Type 'hail' to start and 'quit' to quit." << std::endl;
std::cout << "Say what? " << std::flush;
if(s != "quit")
std::string response = r.sayto(s);
std::cout << "Bob says, '" << response << "'" << std::endl;
} while(s != "quit");
Type 'hail' to start and 'quit' to quit.
Say what? hail
Bob says, 'Hello traveller! Hrm, now where did I put those [rusty swords]?'
Say what? What rusty swords are you talking about?
Bob says, 'Bring me rusty swords and I'll give you a [prize]!'
Say what? Wow?! What type of prize?
Bob says, 'Shh! I can't tell you abou that!'
Say what? quit
Hope that helps.