Exemple #1
0
Fichier : xx2.py Projet : kcsaff/CA
def _brain(X):
    
    lookup = numpy.ndarray(shape=0x10000, dtype=numpy.uint8)
    
    mdecay = 2 * (X.decay + 1)
    
    if mdecay > 256:
        mdecay = 256
    
    for i in range(0x10000):
        if i & 0x10: #alive
            if bit_count[i & 0x1EF] in X.survival:
                lookup[i] = 1
            else:
                lookup[i] = 2 % mdecay
        elif i < 0x200: #dead
            lookup[i] = bit_count[i & 0x1FF] in X.birth and 1 or 0
        else: #dying
            lookup[i] = ((i >> 9) * 2 + 2) % mdecay
            
    return algorithm('bytescan',
            evolve=evolve, 
            table=lookup, 
            states=range(2) + range(2, (X.decay + 1) * 2, 2),
            )
Exemple #2
0
Fichier : cc1.py Projet : kcsaff/CA
def _complex(X):
    lookup = list(X.moore)
    lookup.append(X.history)
    lookup.append(X.potential)
    lookup.append(X.denom)
    return algorithm('complexscan', 
                     evolve=cc1_evolve,
                     table=numpy.asarray(lookup, dtype = numpy.complex128),
                     planes=2)
Exemple #3
0
Fichier : dd1.py Projet : kcsaff/CA
def _water(X):
    lookup = list(X.moore)
    lookup.append(X.history)
    lookup.append((1.0 - X.damping) / sum(lookup))
    lookup.append((X.max + X.min) * X.damping / 2.0 + X.heat)
    lookup.extend((X.min, X.max, X.under, X.over))
    return algorithm('floatscan', 
                     evolve=dd1_evolve,
                     table=numpy.asarray(lookup, dtype = numpy.float))
Exemple #4
0
def _redox(X):
    lookup = X.copy()
    lookup.reduction = numpy.array(lookup.reduction, numpy.uint8)
    states = range(max(lookup.activation.keys()) + 1)
    return algorithm('sparse',
                     evolve=evolve,
                     table=lookup,
                     states=states)
    
Exemple #5
0
Fichier : xx2.py Projet : kcsaff/CA
def _life(X):
    
    lookup0 = []
    
    for i in range(0x200):
        if bit_count[i & 0x1EF] in (X.birth, X.survival)[(i & 0x10) and 1]:
            lookup0.append(1)
        else:
            lookup0.append(0)
            
    return algorithm('bytescan',
            evolve=evolve, 
            table=numpy.tile(numpy.asarray(lookup0, dtype = numpy.uint8), 0x80),
            states=(0,1))
Exemple #6
0
Fichier : xx6.py Projet : kcsaff/CA
def _banks(X,
           out_to_in = None): 

    birth, survival, decay = X.birth, X.survival, X.decay
    
    if out_to_in is None:
        #in order NESW, like mcell
        if len(birth) <= 16:
            out_to_in = {1 << 1:1 << 0, 
                         1 << 3:1 << 3, 
                         1 << 5:1 << 1, 
                         1 << 7:1 << 2}
        else:
            out_to_in = {1 << 0:1 << 7,
                         1 << 1:1 << 0,
                         1 << 2:1 << 1,
                         1 << 3:1 << 6,
                         1 << 5:1 << 2,
                         1 << 6:1 << 5,
                         1 << 7:1 << 4,
                         1 << 8:1 << 3}
    
    lookup = numpy.ndarray(shape=0x20000, dtype=numpy.uint8)
    
    mdecay = decay + 2
    
    if mdecay > 256:
        mdecay = 256
    
    for i in range(0x20000):
        target = 0
        for obit, ibit in out_to_in.items():
            if i & obit:
                target |= ibit
            
        if i & 0x10: #alive
            if survival[target]:
                lookup[i] = survival[target]
            else:
                lookup[i] = 2 % mdecay
        elif i < 0x200: #dead
            lookup[i] = birth[target]
        else: #dying
            lookup[i] = ((i >> 9) + 1) % mdecay
            
    return algorithm('bytescan',
                     evolve=evolve,
                     table=lookup,
                     states=range(decay + 2),
                     )
Exemple #7
0
def _rivers(X):
    lookup = list()
    return algorithm('floatscan', 
                     planes=3,
                     evolve=rivers_evolve,
                     table=numpy.asarray(lookup, dtype = numpy.float))