internal static AtomicBond Create(Atom atom, Atom other) { var bond = new AtomicBond(); bond.SetBond(atom, other); return(bond); }
public bool TryAddBond(Atom other, int bondStrength = 1) { if (freeElectrons >= bondStrength && currentBondingGroups > 0 && other.freeElectrons >= bondStrength && other.maxBondingGroups > 0) { freeElectrons -= bondStrength; other.freeElectrons -= bondStrength; ClearElectronBondingGroups(); bool ok = false; for (int i = 0; i < maxBondingGroups; ++i) { for (int j = 0; j < other.maxBondingGroups; ++j) { if (bondingGroups[i] == null && other.bondingGroups[j] == null) { bondingGroups[i] = bondingGroups[j] = AtomicBond.Create(this, other); ok = true; break; } } } if (!ok) { freeElectrons += bondStrength; other.freeElectrons += bondStrength; } SetupDefaultElectronGroups(); return(ok); } return(false); }
public bool TryCreateBond(Atom other, AtomicBond bond) { if (!CanFormBondWith(other)) { return(false); } this.currentBondingGroups -= 1; return(true); }
void SetupDefaultElectronGroups() { int n = freeElectrons; currentBondingGroups = maxBondingGroups; for (int i = 0; i < maxBondingGroups && n-- > 0; ++i) { if (bondingGroups[i] == null) { bondingGroups[i] = AtomicBond.MakeElectronGroup(); } } if (n > 0) { for (int i = 0; i < maxBondingGroups && n-- > 0; ++i) { bondingGroups[i].SetElectronCount(2); freeElectrons -= 2; --maxBondingGroups; } } }
public void UncreateBond(Atom other, AtomicBond bond) { this.currentBondingGroups += 1; }