How does the step algorithm work in Molek-Syntez?

There are various places that discuss the bonding priority for a single atom in Molek-Syntez, which is often enough to get by for simple cases, but for optimizing complicated setups you need to be aware of the global rules: What happens when multiple Hydrogens are being added/removed in a single step, molecules are being pushed while hydrogenated, etc.

I'm looking for a total outline of the algorithm that's used to process a single step in the game, as far as that's possible to reverse-engineer by looking at the results of actions.


The algorithm proceeds in phases organized by the type of action.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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:

  1. 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).
  2. When bonding, single bonds are preferred to double bonds are preferred to triple bonds. Unbonding works in the reverse order (break triple bonds first).
  3. 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.)
  4. 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:

Weird interaction example 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.