News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

Programming a word web

Farted by zl, May 24, 2013, 09:06:06 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zl

So for the game I'm working on, I want to have a web of related word concepts.

So if you click on "animals" you get "pig" and "cow" and "dog"

if you click on "pig" you get "slop" and "bacon" and "livestock"

if you click on "bacon" you get "food" and "fat" and "delicious"

and so on.  These are just related words, not increasingly specific ones.  It's meant to simulate a chain of thoughts.

I'm not aiming for this being comprehensive.  I imagine a vocabulary of maybe 200-500 words.  Not every word needs three connections - some could even be dead ends.

I'm programming in AS3, and trying to find a good structure for this.  I'd appreciate any thoughts!

Slash

A dictionary with lists as values and strings as keys should work I think.
The lists would contain strings with all the related words to the key.

TropicanaClock


RomanClock

Luckily, AS3 supports Associative arrays. This lets you define a position in an array using a string:

var list:Array = new Array();
list["Animal"]=["Cow","Pig","Chicken"];
list["Pig"]=["Bacon","Farm"];
list["Cow"]=["Beef","Steak"];
list["Bacon"]=["Food","Fat"];
list["Beef"]=["Food","Burger"];
list["Food"]=["Animal","Plant"];

for (var s:String in list)
{
trace(s + " --> " +list[s]);
}


Food --> Animal,Plant
Beef --> Food,Burger
Cow --> Beef,Steak
Bacon --> Food,Fat
Pig --> Bacon,Farm
Animal --> Cow,Pig,Chicken


Say you are using "Animal". At position "Animal" there is an array of strings associated with "Animal". So if you want to go to "Pig" you could get there with list[list["Animal"][1]]; which resolves to list["Pig"];
lemayo lol :soups:

AstronautClock

I'm glad roman is back when I see this post

zl

Quote from: RomanClock;1948889Luckily, AS3 supports Associative arrays. This lets you define a position in an array using a string:

Say you are using "Animal". At position "Animal" there is an array of strings associated with "Animal". So if you want to go to "Pig" you could get there with list[list["Animal"][1]]; which resolves to list["Pig"];

This is awesome! I like the recursive structure of your example.

If I wanted these words to carry some extra information though - like "pig" could be offensive, or "unicorn" is fanciful, or "champagne" is a word you don't know yet - I imagine making a custom Word object with these variables.

Could I define array positions with my custom object?
like:
list[new Word("unicorn",["fanciful","childlike","unlearned"])] = [new Word("horse"),new Word("magic",["fanciful","childlike"])];
edit: but the recursive calls couldn't work with objects being generated in the lists =\

RomanClock

You can modify the previous code to create generic objects:

var list:Array = new Array();
list["Animal"]={links:["Cow","Pig","Chicken"],info:"General"};
list["Pig"]={links:["Bacon","Farm"],slang:"Offensive"};
list["Cow"]={links:["Beef","Steak"],sounds:"Says moo"};
list["Bacon"]={links:["Food","Fat"],sounds:"Sizzles"};
list["Beef"]={links:["Food","Burger"]};
list["Food"]={links:["Animal","Plant"]};

for (var s:String in list)
{
trace(s);
for (var q:* in list[s])
{
trace("\t"+q+": "+list[s][q]);
}
}


Pig
slang: Offensive
links: Bacon,Farm
Beef
links: Food,Burger
Food
links: Animal,Plant
Bacon
links: Food,Fat
sounds: Sizzles
Cow
links: Beef,Steak
sounds: Says moo
Animal
info: General
links: Cow,Pig,Chicken


Thus, if you want to traverse to a new object you would do list[list["Animal"].links[0]]; which resolves to list["Pig"];
lemayo lol :soups:

zl

Quote from: RomanClock;1948904You can modify the previous code to create generic objects:

Thus, if you want to traverse to a new object you would do list[list["Animal"].links[0]]; which resolves to list["Pig"];

I could kiss you :O

RomanClock

Quote from: Zombie Lincoln;1948916I could kiss you :O

<3
Just spreading the knowledge sir!
lemayo lol :soups:

AbbaZabaClock

Quote from: RomanClock;1948929<3
Just spreading the knowledge sir!

Damn you guys come back AND help people out.


:golfclap:
We\'ll be back shortly.