Main Menu

The molecule game

Started by ShadowCentaur, July 15, 2008, 10:25:33 AM

Previous topic - Next topic

ShadowCentaur

I'm trying to make something of a chemistry-based game, where there are several brightly colored atoms bouncing around the screen, and when two atoms of the correct types collide with decent speed, they form a bond. the user will gains points by forming two of the same molecule and colliding them. They blow up and give the user some points and goodies. however, i'm having some trouble figuring out a routine to figure out if two molecules are indeed the same. an object of type atom has an element id , and atoms are connected to one another by objects of type spring (bonds), which stores the indexes of the two atoms it connects as fields. suppose atoms 1,2, and 3 are H,O,H and are connected by bonds 3 and 7. atoms 4,5 and 6 are also H,O,H connected by bonds 2 and 4. suppose atoms 3 and 5 come into contact, how can i write a routine that runsthrough the bonds and atoms to figure out if all the connections are the same? Here's a version with just collision and properly working damped spring bonds, and a twisted mockery of the octet rule. Use the left mouse button to exert a spring force on an atom. any suggestions you think might be fun for this sort of game?
If you ever need me, click your heels three times and press Ctrl + Alt + Del.

Rembrandt Q Einstein

have you played valence?  http://www.digipen.edu/main/Gallery_Games_2001#Valence.  I played it maybe 3 or 4 years ago and thought it was very orignal and fun.  It might give you some ideas.  Obviously you're taking the idea in a different direction, but it doesn't hurt to see what's been done. 

You're getting involved in a complicated part of chemistry called stereoisomers, atoms with the same atoms arranged differently.  Even if you're not considering 3d objects and doube bonds, stereoisomers can get pretty complicated.  For example, a 3d atom linked to four different atoms has two stereoisomers, which are mirror images.  Scientists have very long names for atoms to account for all the different stereoisomers there can be.  With the name, you can draw the exact configuration of the molecule. 

You might want to come up with a similar method of making chemical names for your molecules.  Make an algorithm that examines a molecule and then turns it into a simple string, and then compare strings for matches.  So maybe water would be O(H,H) and ethane would be C(H,H,H),C(H,H,H).  You need rules to determine which atom you start with, and which way you go when it branches, like in organic chemistry.  These rules can be based on which atom is closest to the highest value atom, where H < C < N < O etc...  Without the rules, strings that should match will not.  For the game, you can ignore the chirality issue I talked about above.

It won't be easy, but you should be able to do it with some thinking.  Pointers and recursion would help, but...

O-chem ftw!

ShadowCentaur

I tried Valence out, thanks for the suggestion. According to my browsing of the net, the field of mathematics known as graph theory can offer some assistance. A graph is set of vertices (like the atoms) connected by a set of edges( like the bonds). A molecule is just a vertex-labeled, simple, connected graph. Online chem databases use this all the time. Unfortunately, finding whether two graphs (or molecules) are isomophic (the same) is a lot more difficult than it sounds. I'm trying to write a decent backtracking brute-force algorithm that will compare them. Brute force is normally O(n!) but it is possible to get it down to O(n^4 log n) for vertex labled graphs. For the small n i will be using (3-10 atoms) an inefficient one shouldn't be a big deal. does anyone have any insight into graph isomorphism algorithms that they're begging to share? anyone? and i haven't even put the proper octet rule in yet for the chem part if it... Hurrah for math!
If you ever need me, click your heels three times and press Ctrl + Alt + Del.

ShadowCentaur

Here's the latest version of my little game. Use the mouse to drag things around. Stable bonds are red, unstable ones are blue. Try to form two of the same molecule and match them up for points. Writing on the left can be ignored. It's not super stable just yet, but it resembles something that works. I took the easy route on both the chemistry and graph theory. The atoms form simple organic bonds (ie, carbon need 4, oxygen needs 2, etc) rather than doing something more complicated. The "are the same" routine just checks if there are the same number of atoms of each type and same number of bonds. So it doesn't check for isomers, but making something more than 4 atoms is actually pretty tough anyway. still need to put in a spawning routine and a menu. tell me what'tcha think of it.
If you ever need me, click your heels three times and press Ctrl + Alt + Del.

ATLUS


ShadowCentaur

Here's the first version that somewhat resembles a game. Press the number keys to spawn atoms of your choosing, use the left mouse to select atoms and drag them around, and right click while dragging to tear an atom from all it's bonds. Match two of the same molecule for points. Now that the physics/chemistry part is out of the way, i'm going to start working on game balance and features, like maybe a routine that checks which atoms are in play and spawns atoms that will make it easy for you to make matches. Atoms are labeled with the number of bonds they need. I'm thinking that some powerups and goodies are more than in order, and perhaps makeing rewards for making the molecule that the game asks for, or a puzzle/challenge to eliminate all atoms with nothing left over. Maybe an atom that spawns in and destroys molecules, or disrupts things, or a special shiney thing that somehow helps the player. If you have suggestions i'd like to hear them
If you ever need me, click your heels three times and press Ctrl + Alt + Del.

kevin


  I dunno what i'm doing, but it looks good...

ATLUS


thaaks

It's fun to look at those spinning electrons and their floating atoms. And like Kevin I wonder why two atoms connect and others don't  ;D

To make it a game it must become more obvious which atoms can connect to what other atoms preferably. And the player needs to know what target molecules are to be built. Why do two atoms loose their connection again? Too much movement forces?

I think it's a nice idea to work on - but it needs more game play clarification to be understandable.

Cheers,
Tommy

ShadowCentaur

Thanks, I think the only one who understands it is me right now. >.< I threw in a few splash screens in the start up that might explain the jist of it. Two atoms will connect if they both still need more bonds. The number of bonds an atom needs is the number in the center. When every atom in a given molecule has exactly the same number of bonds as the number in its center. Clack two of the same molecule together to get points. Atoms will lose their bonds if they are moving to fast and get too far apart, or if they are in an unstable atom, they will degrade after a few seconds. come to think of it, i should probably put a little flashing color on bonds that are about to blow up or something like that. Here's the latest one. Use number keys to spawn whatever atoms you want. There is only one target atom right now (it's always water) but i'll add some more simple ones and it will pick a new one when you accomplish it. If you have some ideas how I could make it a little more clear what is going on i'd like to hear 'em. No use making a game that nobody understands, eh?
If you ever need me, click your heels three times and press Ctrl + Alt + Del.

Makeii Runoru

That could be useful for a Chemistry class or something. That is if you're deciding to use real elements like Hydrogen or Zinc or something.
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.