コード例 #1
0
    private void LogRuleBits()
    {
        var output = "";

        for (byte i = 0; i < 8; i++)
        {
            var bit = BitUtils.GetShortBit(rule, i);
            output += bit ? 1 : 0;
        }
        Debug.Log("rule bits: " + output);
    }
コード例 #2
0
    /// <summary>
    /// The main part is here
    /// </summary>
    private void UpdateCA()
    {
        var nextState    = 0ul;
        var currentState = history[history.Count - 1];

        for (byte i = 1; i < longBitsNum - 1; i++)
        {
            byte neigbhd = 0;
            ///!@ set 3 bits representing the number of a bit in the rule
            for (sbyte b = -1; b <= 1; b++)
            {
                if (BitUtils.GetULongBit(currentState, i + b))
                {
                    neigbhd |= (byte)(1 << b + 1);
                }
            }
            ///!@ set i-th bit of the next state
            if (BitUtils.GetShortBit(rule, neigbhd))
            {
                nextState |= 1ul << i;
            }
        }
        history.Add(nextState);
    }