Script? analysis.
Hey.
I don`t know what forum this is best posted in, but I think it would be close to what AI stuff does.
Heres what I`m trying to do, in user terms.
Take a sentance and produce a effect based on that sentance.
Now for more technical terms.
I have a sentance, in a fairly rigid syntax.
It is of variable length, with 3 different types of words.
I need to be able to read each word, determine its id and type, store its id/type, and then take all the words together and do something with them.
I`m trying to write a little text program to take the words of a spell(in a spell lang i made up myself), read them, and output the result to the screen, in text.
What I can do right now is read a sentance and send each word to a anaylzing function.
So I can read a word and reconize individual words.
But how to I get my computer to read the sentance as a whole and act on it ?
I really don`t want to hack out 3 pages of case-switches for all the possible combos. I could, but it doenst seem like a good way.
Bugle4d
~V'lionBugle4d
It sounds a bit like the AI scripts I got for a Spaceship AI.
Basicly, it has a sentence:
do ACTION on TARGET until VARIABLE is BIGGER/SMALLER then VALUE.
So I just send ATTACK CLOSEST_ENEMY until DISTANCE_TO_ENEMY is SMALLER then 10. When I disassemble this, it first checks the last part: is DISTANCE_TO_ENEMY smaller then 10? If so, go to next command, if not, do this command. ATTACK on CLOSEST_ENEMY? Okay, load the attack() function, and pass TARGET to it.
No big switch statement needed ^_^
In your case, I think that your spells are more or less modular. For instance, in your grammar the first word might be ELEMENT (fire, water, wind, earth), the second might be TYPE (ball, blast, cone, shield), the third might be TARGET (person, area), the fourth might be SIZE, if appliable (is translated to a number of feet), the fifth word might be DURATION (is translated to a number of seconds). The sixth might be STRENGHT (translated to damage) Or they may have any order at all.
Now, to disassemble that into a spell, basicly translate each part into an ID code, and use that to fill a structure. Then, have a cSpell class that analyzes your structure. First, you would need to find the spells type, or types. Iterate through your structure, and look for the ID codes that correspond with a TYPE. (for example, numbers 1 to 4). So your spell might be a blast. Next, find out how big it is supposed to be. Look for the first translation to a number (might be ID''s 5 to 15?). This is neat. Now, for the graphics, you need to know the element. Iterate through your structure, and set a flag for each ELEMENT ID you find. So your spell might be a combo of FIRE and WATER. Next, try to find the DURATION, TARGET, and STRENGHT of the spell by iterating again, and finding those values.
Now you got a filled in cSpell class, that knows the Element, Size, Duration, Damage, and Type of the spell. Run a quick check to see if it is a valid spell (does it have an element? Does it do damage?). If so, cast the spell. Get the Element(s), draw a spell image of that sort, calculate the casting time from probable Damage & Duration & Number-of-Elements & Type. Once the casting is done, either send a blob of the right color (for a BALL), or create a spray of the right color (for a CONE), or a shield of the right color (for a SHIELD). Let''s say it is a BALL, and arrives at the location. Then, get the SIZE, and draw a ball of the right size there. Get the STRENGHT, and calculate the damage for everyone in that ball.
The end
Basicly, it has a sentence:
do ACTION on TARGET until VARIABLE is BIGGER/SMALLER then VALUE.
So I just send ATTACK CLOSEST_ENEMY until DISTANCE_TO_ENEMY is SMALLER then 10. When I disassemble this, it first checks the last part: is DISTANCE_TO_ENEMY smaller then 10? If so, go to next command, if not, do this command. ATTACK on CLOSEST_ENEMY? Okay, load the attack() function, and pass TARGET to it.
No big switch statement needed ^_^
In your case, I think that your spells are more or less modular. For instance, in your grammar the first word might be ELEMENT (fire, water, wind, earth), the second might be TYPE (ball, blast, cone, shield), the third might be TARGET (person, area), the fourth might be SIZE, if appliable (is translated to a number of feet), the fifth word might be DURATION (is translated to a number of seconds). The sixth might be STRENGHT (translated to damage) Or they may have any order at all.
Now, to disassemble that into a spell, basicly translate each part into an ID code, and use that to fill a structure. Then, have a cSpell class that analyzes your structure. First, you would need to find the spells type, or types. Iterate through your structure, and look for the ID codes that correspond with a TYPE. (for example, numbers 1 to 4). So your spell might be a blast. Next, find out how big it is supposed to be. Look for the first translation to a number (might be ID''s 5 to 15?). This is neat. Now, for the graphics, you need to know the element. Iterate through your structure, and set a flag for each ELEMENT ID you find. So your spell might be a combo of FIRE and WATER. Next, try to find the DURATION, TARGET, and STRENGHT of the spell by iterating again, and finding those values.
Now you got a filled in cSpell class, that knows the Element, Size, Duration, Damage, and Type of the spell. Run a quick check to see if it is a valid spell (does it have an element? Does it do damage?). If so, cast the spell. Get the Element(s), draw a spell image of that sort, calculate the casting time from probable Damage & Duration & Number-of-Elements & Type. Once the casting is done, either send a blob of the right color (for a BALL), or create a spray of the right color (for a CONE), or a shield of the right color (for a SHIELD). Let''s say it is a BALL, and arrives at the location. Then, get the SIZE, and draw a ball of the right size there. Get the STRENGHT, and calculate the damage for everyone in that ball.
The end
Well, it doesn''t sound much like AI to me, unless you have some degree of ambiguity, in which case you''re in NLP (Natural Language Processing) territory. With your own language, only 3 types of words, and a very rigid syntax, understanding what has been ''written'' is pretty trivial. You read in a word, check it''s of the correct type, and then move on to the next. Providing all words were of the correct type and in the correct order (that''s your syntactical check), you might need an extra check to ensure the combination makes sense (the semantic check). After that though, how you implement it is entirely down to what features your system offers. Ronin_54 gave one good way of doing this sort of thing.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
One point not mentioned is that you will need a database of spells to compare the sentence to... this may be directly encoded as a list of spells to check against, or a multi-dimensional database where the spell acts as the indexing key and the result of the spell is stored at that indexed location. Alternatively, you could go overboard and learn a mapping from sentences to spells using a pattern recognition system (neural net, clustering algorithm... even a decision tree!). That, of course, would be overkill, but it''s possible.
Cheers,
Timkin
Cheers,
Timkin
If you want to get _REALLY_ fancy, you could learn MacLisp, decypher the source code for this(http://hci.stanford.edu/~winograd/shrdlu/) program, and have one of the best natural language processing engines around. =-)
"The Requested Information Is Unknown Or Classified" -Anonymous
"The Requested Information Is Unknown Or Classified" -Anonymous
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
I really don`t want to type out a database of spells and compare my cSpell structure to all of them.
The goal is for the user to be able to create his own spells.
Heres a part of my draft language
Essentially, the Espello lanuge is made up of three types;
-variable- = varies.
-connector- = sigals change-of-operand
-operator- = does something with a -variable-
Syntax:
-element1-( e -element2-) la -size-(e la -size-) (del -object- (le -objectpart)) eso -action- muso -intensity- (y -element1-( e -element2-))...
I won`t run on and describe all of it, but basically I desire to be able to type out spells, and in the same command, type out more spells, so I can end-up with paragraphs-long spells, with the whole paragraph parsed.
So theres ambiguity in that there is great flexibility.
With the small number and types variables I have in it right now, I could spend weeks writing a database of spells for all the possible combinations. I want to like have a small dtatebase on what each variable does and acts, and simply use that to build the effects.
But thats the goal.
I think Ronin_54 answered my immidiate question as how to go onto my next step.
Thank you everyone.
Bugle4d
[edited by - Vlion on August 20, 2002 2:33:02 PM]
The goal is for the user to be able to create his own spells.
Heres a part of my draft language
Essentially, the Espello lanuge is made up of three types;
-variable- = varies.
-connector- = sigals change-of-operand
-operator- = does something with a -variable-
Syntax:
-element1-( e -element2-) la -size-(e la -size-) (del -object- (le -objectpart)) eso -action- muso -intensity- (y -element1-( e -element2-))...
I won`t run on and describe all of it, but basically I desire to be able to type out spells, and in the same command, type out more spells, so I can end-up with paragraphs-long spells, with the whole paragraph parsed.
So theres ambiguity in that there is great flexibility.
With the small number and types variables I have in it right now, I could spend weeks writing a database of spells for all the possible combinations. I want to like have a small dtatebase on what each variable does and acts, and simply use that to build the effects.
But thats the goal.
I think Ronin_54 answered my immidiate question as how to go onto my next step.
Thank you everyone.
Bugle4d
[edited by - Vlion on August 20, 2002 2:33:02 PM]
~V'lionBugle4d
well presumably you have a set number of syntax keywords, and a set number of components to make spells with, thus you have a certain number of possible spells. So lets say u got 3 potential spots for syntax keyword per spell, and have 25 differnt components (assuming order of key words makes the same spell) to place in those 3 slots (5 elements, 10 physical components, and 10 magical components or something) you get a finite number of combinations that result in a given amount of spells. however if you have the order make a differnce then you need to parse them in a function that returns a spell class object. im thining the latter is what your doing here soo, you may want a function that loads a matrix or vector of spell components and what effect they have on the spell being made such as
the vectors could be for differnt colors/animation shapes in a single spell such as fiery ice bomb or something where the ice is a rigid solid shape and the fire is a flame shape, each with respective colors. then to simplify things instead of having to create spells on the fly based on a look up table or parsing function you could have a save spell function that takes a spell as its argument and a character too and save it to that characters spell book or memory.
cSpell getSpell(paramaters here probably the parsed syntax in a meaning ful repreentation){ cSpell temp; temp.spellAnimate[0] = drawShape(values here); temp.damage = calculationFunction(values); temp.spellColor[0] = colorSet(r,g,b); return temp;}
the vectors could be for differnt colors/animation shapes in a single spell such as fiery ice bomb or something where the ice is a rigid solid shape and the fire is a flame shape, each with respective colors. then to simplify things instead of having to create spells on the fly based on a look up table or parsing function you could have a save spell function that takes a spell as its argument and a character too and save it to that characters spell book or memory.
What you are really talking about is a scripting language. Address all your issues to that end, and the quality of responses will be better. (unless someone says, "Search the forums." A scripting language is a mini language you will create. (like you''ve already done) Now it sounds like you need help writing a good parser to make sense of your script. The above responses are pretty right on so i can''t be of much help there, however, having written a prog similar to yours, think carefully about all of the elements you must distinguish to actually encapsulate and contrast a spell. Your language must include all of these. Just wait till you try to go visual in 3d, then it''s time to create a huge library of visual effects.
Best of Luck
Dreddnafious Maelstrom
"If i saw farther, it was because I stood on the shoulders of giants."
Sir Isaac Newton
Best of Luck
Dreddnafious Maelstrom
"If i saw farther, it was because I stood on the shoulders of giants."
Sir Isaac Newton
"Let Us Now Try Liberty"-- Frederick Bastiat
D.M.
Yes, I think that about sums it up.
When I`ve gotten settled into dorm life, I''ll resume work.
I really don`t plan to take it to the level of graphics- I`m just planning on doing text output.
That way it simplifies things considerably.
But thank you, everyone.
-V''lion
Bugle4d
Yes, I think that about sums it up.
When I`ve gotten settled into dorm life, I''ll resume work.
I really don`t plan to take it to the level of graphics- I`m just planning on doing text output.
That way it simplifies things considerably.
But thank you, everyone.
-V''lion
Bugle4d
~V'lionBugle4d
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement