Exemplo n.º 1
0
Arquivo: main.py Projeto: B-Rich/zasim
def main():
    tape = TuringTapeSimulator()
    painter = MultilineOneDimConsolePainter(tape, compact_boxes=True)

    painter.after_step()
    print

    for i in range(10):
        tape.step()
        print
Exemplo n.º 2
0
Arquivo: main.py Projeto: B-Rich/zasim
"""This module implements a cellular automaton, that models moving data along
the tape of a turing machine."""

from zasim.display.console import MultilineOneDimConsolePainter
from zasim.simulator import SimulatorInterface, TargetProxy
from zasim.config import RandomConfiguration

palette = [[" a", " a", " a", " a", " b", " b", " b", " b", " c", " c", " c", " c"],
           ["<a", "<b", "<c", "  ", "<a", "<b", "<c", "  ", "<a", "<b", "<c", "  "]]
values  =  [ 0,    1,    2,    3,    4,    5,    6,    7,    8,    9,    10,   11]
probabs =  [0.1,   0,    0,   0.23,  0,  0.1,    0,   0.23,  0,    0,    0.1, 0.24]
palette = MultilineOneDimConsolePainter.box_art_palette(palette)
palette = MultilineOneDimConsolePainter.convert_palette(palette, values)

class TuringTapeSimulator(SimulatorInterface):
    def __init__(self):
        super(TuringTapeSimulator, self).__init__()

        self.palette_info = {
                'cboxes': palette
            }

        self.shape = (25,)
        self.cconf = RandomConfiguration(12, *probabs).generate((self.shape))
        # do not send stuff from the right border.
        self.cconf[-1] = self.cconf[-1] | 3

        self.possible_values = values

        self.target_attrs = ["cconf", "possible_values"]