zasim.cagen.computations

Inheritance diagram of zasim.cagen.computations

class zasim.cagen.computations.ElementaryCellularAutomatonBase(rule=None, **kwargs)[source]

Bases: zasim.cagen.bases.Computation

Infer a ‘Gödel numbering’ from the used Neighbourhood and create a computation that corresponds to the rule’th possible combination of values for the neighbourhood cells.

This works with any number of dimensions.

Create the computation.

Supply None as the rule to get a random one.

digits_and_values = []

This list stores a list of dictionaries that for each combination of values for the neighbourhood cells stores the ‘result_value’, too.

rule = 0

The elementary cellular automaton rule to use.

See visit() for details on how it’s used.

visit()[source]

Get the rule’th cellular automaton for the given neighbourhood.

First, find out, how many possible combinations there are. That’s simply the nuber of cells in the neighbourhood as the exponent of the number of possible_values. Then, normalise the neighbourhood cells by sorting their positions first by X, then by Y axis. Finally, create code, that sums up all the values and looks up the target value from the rule lookup array.

init_once()[source]

Generate the rule lookup array and a pretty printer.

pretty_print()[source]

This method is generated upon init_once and pretty-prints the rules that this elementary cellular automaton uses for local steps.

build_name(parts)[source]
class zasim.cagen.computations.CountBasedComputationBase[source]

Bases: zasim.cagen.bases.Computation

This base class counts the amount of nonzero neighbours excluding the center cell and offers the result as a local variable called nonzerocount of type int.

The name of the central neighbour will be provided as self.central_name.

visit()[source]

Generate code that calculates nonzerocount from all neighbourhood values.

class zasim.cagen.computations.LifeCellularAutomatonBase(reproduce_min=3, reproduce_max=3, stay_alive_min=2, stay_alive_max=3, **kwargs)[source]

Bases: zasim.cagen.computations.CountBasedComputationBase

This computation base is useful for any game-of-life-like step function in which the number of ones in the neighbourhood of a cell are counted to decide wether to change a 0 into a 1 or the other way around.

Parameters:
  • reproduce_min – The minimal number of alive cells needed to reproduce to this cell.
  • reproduce_max – The maximal number of alive cells that still cause a reproduction.
  • stay_alive_min – The minimal number of alive neighbours needed for a cell to survive.
  • stay_alive_max – The maximal number of alive neighbours that still allow the cell to survive.
visit()[source]

Generates the code that turns a 0 into a 1 if nonzerocount exceeds reproduce_min and doesn’t exceed reproduce_max and turns a 1 into a 0 if nonzerocount is lower than stay_alive_min or higher than stay_alive_max.

build_name(parts)[source]
class zasim.cagen.computations.PasteComputation(c_code=None, py_code=None, name=None)[source]

Bases: zasim.cagen.bases.Computation

visit()[source]

Previous topic

zasim.cagen.border - Handling borders

Next topic

zasim.cagen.dualrule - Using two elementary rules at once

This Page