Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Searching a string...

Author
Message
Mister Fuzzy
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location: XNA
Posted: 6th Apr 2012 01:34 Edited at: 6th Apr 2012 01:36
I'm working on a program that waits for user input, then checks the input text for "keywords" that relate to in-game objects. From there, keywords are assembled into a kind of pseudo-sentence used to convey basic thoughts and ideas to a computer-controlled character, triggering appropriate responses to a query or command. The structure of the "sentence" is SUBJECT_VERB_DIRECTIVE_TIME. Subject can be the USER, it could be the CURR_NCP, or it could be someone else's name, such as GUARD_CAPTN or KING. The Verb would be something like GOTO, WENT, BUY, TRAVEL, ect. The Directive is optional, and would conclude sentences such as "YOU_GOTO_CASTLE." Similarly, the TIME is optional as well, and in the case of the previous sentence, could tell the NPC "YOU_GOTO_CASTLE_TOMORROW."

This "uniquely unoriginal" idea has hit a roadblock: I can't figure out how to analyse a string such as "Where can I buy a potion?" to output "USER_BUY_POTION". Any Ideas?

(Also, it would be nice if anyone knows a better structure for the sentences to be compiled in. My structure, although effective, is a bit too limited...)

Tunnel vision yet? Have a carrot!
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Apr 2012 02:07
I think you're going to need a massive list of subjects (char* [] or string[]), and the same for verbs, directives and different time strings. There's no other way for the comp to determine if they are what we know they are. I suppose you'll be able to fill these data structures up over time as you add more content to the game. So for example, when you add a room with a Vase and a Key, you add Vase and Key to your Subject list. Probably best to read it from a text file.

After that, you'll want to split your input sentence into substrings, using ' ' spaces as the separator. Then trim off the punctuation. I wrote this substring function a few days ago. It may help, it may not!


Once you've split your input string, you can check each returned string against your lists of subjects/verbs etc. with the old strcmp() command. You may want to enforce some rules like:
- User enters 2 verbs, respond with "I can't do two things at once!"
- User enters 2 subjects, respond with "Let's deal with one thing at a time"

When you have one subject and one verb matched, if you want to reconstruct it into a new string (is there any point? Maybe just call some functions passing in the matched subjects/verbs etc), strcpy and strcat are you friends if you do use char*.

Sounds like a tall order, but doable. Good luck!

Mister Fuzzy
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location: XNA
Posted: 6th Apr 2012 10:15
Thanks for the input, Fallout!

Quote: "Sounds like a tall order, but doable. Good luck!"
If it doesn't challenge my abilities, then it's not worth doing. What's the point of coding if it's not to learn? (Don't answer that.)

Anyway, yes; I have considered the problems that may arise if the user attempts to input too complex of a sentence (Such as "The King went to Norway(?), Abraham Lincoln came back from the dead and Chuck Norris lent me his beard. Also I have an arrow in my knee." The CPU would read this as complete garbage (And whoever the player was talking to would assault them for making a freaking 'arrow to the knee' reference) and the function would return something like "REPEAT," prompting the NPC to say something like "I'm sorry, I didn't understand a word of that."

Punctuation and filler words that the computer has no reason to proccess (Such as "and," "the," "but," "Jello," ect, will be ignored by the checker. If the core of the sentence amounts to gibberish (i.e. ONLY a subject, ONLY a verb) a "REPEAT" command will be returned.

Quote: "So for example, when you add a room with a Vase and a Key, you add Vase and Key to your Subject list."
YES. The only reason I would have to add a keyword is if a particular resource is incorporated in the game. So if I don't have Abraham Lincoln in the game, I wouldn't have an Abraham Lincoln keyword stored.

However, there are some problems I can forsee already: If someone responds with a double negative or in passive voice, for example, the function might respond with a "NO" when the user meant "YES."

Oh well. I'll figure out that passive voice crap when it becomes relevant. Until then, I need to work out a simple demo conversation with a NPC in a 3D environment.

Tunnel vision yet? Have a carrot!
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Apr 2012 13:15
Quote: "If it doesn't challenge my abilities, then it's not worth doing. What's the point of coding if it's not to learn?"


Well ...

Quote: "(Don't answer that.)"


Oh, ok then.

Yeah, you will have lots of problems with double negatives and things. I remember the old games like this where they would constantly misinterpret what you'd written. I think it's something you're going to have to live with, with a system like this, short of writing an uber clever language learning matrices of brain juice.

I think generally, after people have had fun fooling around typing random comments, they generally fall back onto simple logic. "PICK UP THE KEY", "HIT BARBARIAN" etc.

Remember to parse for swear words though. Someone will inevitably write "OH F-YOU" at which point you can respond "Language like that hurts my feelings!!!" then shut down the game.

xix psycho xix
15
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 7th Apr 2012 16:16
Quote: "Remember to parse for swear words though. Someone will inevitably write "OH F-YOU" at which point you can respond "Language like that hurts my feelings!!!" then shut down the game."


Lolol. Yeah I would be writing "Well F-u too!!!" then terminating the game and all it's save files lolol...
Mister Fuzzy
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location: XNA
Posted: 8th Apr 2012 18:48
Quote: "Remember to parse for swear words though. Someone will inevitably write "OH F-YOU" at which point you can respond "Language like that hurts my feelings!!!" then shut down the game."


Heh. Or it could ramp the difficulty, rendering a simple room nearly impossible to complete.

Tunnel vision yet? Have a carrot!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Apr 2012 03:29 Edited at: 17th Apr 2012 03:31
Quote: ""Where can I buy a potion?" to output "USER_BUY_POTION""


Strip out the words "where, can, a, the, etc." and punctuation and replace "I, me" with "user" and you get:

"User buy potion"

This should work fairly often and is very easy to code. You may want to treat question words such as "where, when, how, who, etc." specially to make sure you answer correctly.

[b]

Login to post a reply

Server time is: 2024-04-26 02:23:51
Your offset time is: 2024-04-26 02:23:51