The algorithm proceeds in phases organized by the type of action.
- Hydrogen Removals and Shunts fire together. These go in Beam Emitter order, although this only matters when multiple emitters target the same atom and it runs out of Hydrogens.
- Hydrogen Additions fire. You would think these would get lumped in with the removals, but they definitely process after. (Observable when removals and additions target the same atom with no pre-existing Hydrogen.) There is no way these can conflict, so no observable in-phase ordering.
- Pushes, pulls and rotates fire. This is a two-step process: First, the targets are determined by seeing which molecules the emitters are hitting (and for rotates, the center of rotation). If two emitters target the same molecule, the lower number wins. Then, all affected molecules are rotated/slid simultaneously into their new positions. This means that a push and a pull can cooperate, or (in extremely precise circumstances) you can push a molecule through the teeth of another one that's turning, like a gear.
- Bond fixup: New bonds are made, old ones are broken if the current state is not stable. This is the exciting (and most complicated) part, and gets its own section below.
- Trashing and outputting: Much like the push/pull phase, targets are determined and then the result happens. If two (or more) emitters target the same molecule, the lowest one wins. This only really matters if you target the same molecule for both trashing and outputting.
- Emitter left/right movement occurs. This can't conflict with anything else, so it's technically unordered with respect to the others, but I'm arbitrarily putting it last.
Knowing the details of the above let you do some non-intuitive tricks, like adding or removing Hydrogens in the same step as the molecule gets moved. This works even when the addition splits the moved molecule in two, because movement happens before bond fixup. Sometimes this is the best way to get the bonds you want.
I haven't fully cracked the details of Bond Fixup yet. Here's what is known for sure, for simple cases:
- I'm fairly certain that unbonding happens before bonding. This can lead to non-local bond changes (bonds forming between two atoms when neither atom was touched this step).
- When bonding, single bonds are preferred to double bonds are preferred to triple bonds. Unbonding works in the reverse order (break triple bonds first).
- When the above is tied, bonds prefer specific atoms. Cl < F < S < O < P < N < C (Carbon is most preferred), and the opposite for unbonding. (F and P are specific to the extra puzzles.)
- For individual atoms, when dealing with the same bond order and type of atom, bonding starts clockwise from the line of the Emitter Beam, and when unbonding it goes counterclockwise. So, for example, adding a single hydrogen to Cyclohexane will always unbond the bond CCW around the ring, because if you start tracing from the atom along the line of the Emitter Beam and continue CCW, that's the first atom you'll encounter. However, this doesn't seem to generalize when multiple bonds are happening:
Changing the angles on emitters can change which bond is chosen in this case, but in other cases it will always chose the same one of the two, no matter what. Also, if all three events don't happen at the same time, the interaction becomes simpler and follows the rules above.