# How does an atom decide what to bond to?

Given for example, a Hydrogen atom (that can only have 1 bond max), that is sitting on a bonder next to two other atoms that are also on bonders and have available bonding slots, how is it determined which atom the Hydrogen ends up bonding to? I've tried experimenting with it being a priority order of directions, but that doesn't seem to be correct.

I'm afraid there's no real science behind this. Each bonder has a priority number likely based on the internal data structure (array, linked list, whatever). The game just processes this list in a first through last order. So the bonding order in game is just how the bonders happen to be arranged. I would be nice if they were labeled, but as far as I know there's no way to get their priority in game. So with two bonders linked, it just goes through the list sequentially. For example, with 4 bonders the list of checked links would look something like this:

1. (1, 2)
2. (1, 3)
3. (1, 4)
4. (2, 3)
5. (2, 4)
6. (3, 4)

Which is simply an ordered list of the pairs of priority numbers. With that knowledge, you just need to know which bonder has which priority. Though experimentation I've found that:

For 4 bonders in a fresh level the bonder priority numbers are:

``````1 - 2
| . |
4 - 3
``````

For a fresh level with 8 bonders the bonder priority numbers are:

``````1 - 2
| . |
4 - 3
| . |
5 - 6
| . |
8 - 7
``````
• No real science needed, but this looks promising as a definitive answer. I'll try it out tonight to verify that it matches my experience. Commented Dec 22, 2011 at 17:36
• In a game where one does not need to concern themselves with stereochemistry, induction effects, kinetics, or thermodynamics, science doesn't play much of a role. Commented Dec 24, 2011 at 0:12
• Great answer, there really should be an in-game way to determine this apart from remembering the original configuration. Commented Dec 26, 2012 at 2:37
• What if the eight bonders are initially in a horizontal layout? Commented Jan 31, 2013 at 7:04
• An option was added to the options menu that allows you to "Show Bonder Priority" which adds numbers to the bonders and makes this much easier to keep track of now. Commented Sep 17, 2019 at 11:08

I don't think that there is a strict order of bonder preference; it is based on something else.

I did the following experiment: three bonders in a horizontal row, with an unbonded H at each one. I recorded the results of the six combinations of bonders.

``````#    order    result    side
a    1 2 3    H-H H      L
b    3 2 1    H-H H      L
c    2 3 1    H H-H      R
d    1 3 2    H-H H      L
e    3 1 2    H H-H      R
f    2 1 3    H H-H      R
``````

I reran this many times, and there was always a 50% split with one group preferring 'L' bonding, one group preferring 'R' bonding, and one group being split. (Each group is identified by the bonder in the middle.)

So there is evidently some structure to the evaluation, but each of these six cases is contradicted by another one (if we assume the bonders evaluate in order); i.e., if (a) is the correct order, then why in (b) does the bonder prefer (2,3) over (1,2)? This is true for every case.

The mouse wheel trick seems to be doing something (it made a click and I assume processed an action), but I could not change the output of (a).

• If your bonders 1, 2 and 3 have priorities 1, 3 and 2, respectively, then Timbo's answer would explain this. Commented Jun 19, 2014 at 20:39

I used a few hours testing. The result is that there is a hidden priority, but the bonder only checks the bonder right and under it. That means if there are 4 bonders build up the following way:

``````2 3 1
4
``````

First bonder 1 will check below and right of it and can't find anything to bond. The second step is that bonder 2 will bond with bonder 3 and 4. Afterwards bonder 3 bonds with 1 and last bonder 4 doesn't find anything to bond.

If a bonder has two possible connections (right and under it), then it will bond first with the bonder with the higher priority (lower number). That means the second step bonder 2 will first bond with 3 and then with 4.

Some of the other answers are wrong, and it bugs me that the rest is split over multiple posts, so based on thorough research here is my definitive list of how bonding works:

1. Each bonder has an invisible priority number, 1-8. This number is determined by its initial position in the reactor.
2. Bonding proceeds with an outer loop across all the bonders and an inner loop across all the bonders. So if there are 4 bonders, the order it checks is (1,1), (1,2), (1,3), (1,4), (2,1), (2,2), (2,3), (2,4), (3,1), (3,2), (3,3), (3,4), (4,1), (4,2), (4,3), (4,4).
3. However, bonding only occurs if the second bonder is directly below or to the right of the first bonder. (Credit to Timbo for figuring this out.) This is why the list above doesn't lead to double-bonding: If the layout is 2-1, then the entry (1,2) in the list above doesn't trigger, since 2 (the second bonder) is to the right of the first bonder.
4. Bonder order is not affected by mouse-wheeling on the bonders, at least not in the latest version. Yes, it makes a clicking sound, but I could not get the bond order to change on my test molecule of BO2 no matter how I mouse-wheeled. This is supported by the fact that mouse-wheel clicks are not saved in the undo history like everything else.
5. The bonder order is different for different reactor types:

Standard/Sensor

``````1 3
2 4
``````

Assembly/Fusion/Nuclear/Research (4)

``````1 2
3 4
``````

Research (2) (Presumably, can't verify)

``````1 2
``````

Research (8)

``````1 2
3 4
5 6
7 8
``````

Super-Bonder/Sandbox

``````5 1 3 7
6 2 4 8
``````

Yes, there are two different layouts for the "standard" 2x2 square, and yes, the Super-Bonder really is that weird.

Lastly, here are some practical tips for how to debug a balky design:

Let's say you're trying to make the molecule HP≡CO, in a bent configuration. You make a 2x2 square of bonders and your input looks like this:

``````P=C

H O
``````

But when you bond it, it comes out like this:

``````P≡C
|
H-O
``````

Given how bonding works, we can deduce that the lower-left bonder is running before the upper-left bonder, so swapping them will fix it. The relative priority of the other two bonders doesn't matter.

``````H P
| ⦀
O-C
``````

In this case, the lower-left is before the upper-right, and you have to swap diagonally. The priority of the two bonders on the opposite diagonal doesn't matter. The difference in the two examples comes from the rule that bonds only form to the down and right.

• Thanks for this late but more comprehensive answer, it should be the accepted one. Just a comment -- your steps (2) and (3) can be restated as there is a single loop over all bonders in priority order. For each bonder, it tries to bond with the square to the right and the square below. If there is a bonder in both squares, priority breaks the tie. Commented Jun 3, 2017 at 10:08
• Thanks! Yes, I agree that what you said is equivalent, and it's definitely shorter to say it that way. I laid out the algorithm the way I did because that's the way that's most precise and makes the most sense to me; in particular, I suspect that's how it's actually coded in the game. Commented Jun 4, 2017 at 2:18
• Actually while I agree your way is clearer to understand, I would hope that the way it's actually coded in the game is what I said. A double loop over all pairs of reactors would be inefficient, an O(n^2) algorithm, whereas mine is O(n). A trained programmer should know not to do a double loop when a single loop would work. Commented Jun 4, 2017 at 8:38
• This is getting into the weeds, but... It's possible that there isn't a convenient map from position to bonder object. It really depends on how the internals of the game work, which obviously we can only speculate at. What I do know is that an O(N^2) algorithm is no big deal when N has a maximum value of 8. Commented Jun 5, 2017 at 4:45
• Largely agree, but 64 vs 8 is definitely a big deal since this is in the critical section of the code. Could be that that level of optimization was necessary to get the highest speed setting to go as incredibly fast as it does. Anyway let's exit the weeds ;) Commented Jun 5, 2017 at 4:54

The bonders each have a "hidden priority", where they will try the other bonders in a certain order. If it's not doing what you want, you can swap the bonder's position around.

Sorry, can't find a good source to cite for this.

• There appears to be some kind of hidden order, but it's WEIRD. I laid out C, H, C on 3 bonders horizontally and tried bonding. For the 6 combinations of those 3 bonders, half bonded C-H C and half bonded C H-C, but any pattern is not clear at all. Commented Nov 29, 2011 at 21:39
• @lilserf As far as I can tell, the logic is something like "Determine what the user is trying to do, then come up with a way to do something else". :p Commented Nov 29, 2011 at 22:16

Apparently, if you 'mouse over' the bonder and roll the mouse wheel up/down, the bond order of the bonders changes. It worked for me.