예제 #1
0
    void MakeBondWith(Atomic otherAtom, Collision collision)
    {
        // calculate collision force. The amount determines energy required for bond order.
        int bondEnergyOrder = BondOrderEnergy(collision.impulse);

        // TODO is this a race condition for collision messages?
        // Return if we've already bonded with this atom
        if (this.bondedAtoms.ContainsKey(otherAtom))
        {
            Debug.Log("Already bonded to atom");
            return;
        }

        // who wants more electrons based on electronegativity?
        if (this.electronegativity > otherAtom.electronegativity)
        {
            // this atom wants to get electrons
            // how many electrons can I recv and how many can other give?
            if (this.ShareableHoles() > 0 && otherAtom.ShareableElectrons() > 0)
            {
                int bondOrder = Enumerable.Min(new int[] { bondEnergyOrder, this.ShareableHoles(), otherAtom.ShareableElectrons() });
                CreateBond(bondOrder, otherAtom);
            }
            else
            {
                Debug.Log(string.Format("Want Get electron, but this.holes: {0} :: other: {1}", this.ShareableHoles(), otherAtom.ShareableElectrons()));
            }
        }
        else if (this.electronegativity < otherAtom.electronegativity)
        {
            // this atom wants to give electrons
            // how many electrons can I give and how many can other get?
            if (this.ShareableElectrons() > 0 && otherAtom.ShareableHoles() > 0)
            {
                int bondOrder = Enumerable.Min(new int[] { bondEnergyOrder, this.ShareableElectrons(), otherAtom.ShareableHoles() });
                CreateBond(bondOrder, otherAtom);
            }
            else
            {
                Debug.Log(string.Format("Want Give electron, but this.holes: {0} :: other: {1}", this.ShareableElectrons(), otherAtom.ShareableHoles()));
            }
        }
        else
        {
            // both atoms have the same electronegativity
            if (this.ShareableElectrons() > 0 && this.ShareableHoles() > 0 &&
                otherAtom.ShareableElectrons() > 0 && otherAtom.ShareableHoles() > 0)
            {
                int bondOrder = 0;
                // 2.3 just is an electronegativity boundary that seems to divide between
                // those that want electrons vs those that give electrons
                if (this.electronegativity > 2.3f)
                {
                    // wants to get electrons
                    bondOrder = Enumerable.Min(new int[] { bondEnergyOrder, this.ShareableHoles(), otherAtom.ShareableElectrons() });
                }
                else
                {
                    // wants to give electrons
                    bondOrder = Enumerable.Min(new int[] { bondEnergyOrder, this.ShareableElectrons(), otherAtom.ShareableHoles() });
                }

                CreateBond(bondOrder, otherAtom);
            }
            else
            {
                Debug.Log("no shareable electrons or holes in either atom");
            }
        }
    }