CAViewer - A Cellular Automaton Simulator written in Java

For scripts to aid with computation or simulation in cellular automata.
Apollyon094
Posts: 3
Joined: March 4th, 2020, 11:19 am

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by Apollyon094 »

Are Margolus neighborhoods supported?
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Your 'number of states is incorrect' error message is displayed by simply loading rule '../Others/Rule_4' and then loading a pattern from that rule. To determine what is happening do the following:

After a request is made to load a rule, write the name of the requested rule together with its number of states to the cmd window.

After a request is made to load a pattern, write the name of the requested pattern together with the required number of states and the name of the current rule and the current number of states to the cmd window.
I have added the requested information to the error message.
However, I am unable to reproduce this error. Could you share with me which pattern you loaded?
Are Margolus neighborhoods supported?
They can be supported through the use of alternating neighbourhoods.
However, I don't think that block cellular automaton is supported.
Attachments
CAViewer.zip
(2.26 MiB) Downloaded 185 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Here is a screen shot after loading rule ../Others/Rule_4 and then loading pattern Oscillator:

Error.png
Error.png (1.29 MiB) Viewed 7891 times

If you had done what I suggested rather than change your error dialog we would have got more useful information.

Brian Prentice
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Here is screen shot after loading rule ../Others/Rule_1 and then loading pattern Gun:

Error2.png
Error2.png (1.22 MiB) Viewed 7883 times

Notice that the shape of the gun is correct but the state colors are incorrect.

Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Could you upload the contents of transFunc.py here for the incorrect state colours?
And does the simulation still run?
Here is a screen shot after loading rule ../Others/Rule_4 and then loading pattern Oscillator
Also for this, the error dialog says that the current rule is Rule_1 while the pattern's rule is Rule_4.
Last edited by lemon41625 on April 16th, 2020, 11:25 pm, edited 2 times in total.
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Copy of file transFunc.py from ../Others/Rule_1:

Code: Select all

rule_table_string = """
0,0,0,0,0,3,1,0,0,0,3,0,0,2,0,0,0,2,0,0,0,0,0,0,0,3,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0
2,2,2,2,2,2,2,2,1,2,2,1,2,2,1,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,3,2,1,1,2,2,2,2,1,2,2,2,1,2,1,2,2,2,3,1,1,2,1,1,1,1,1,2,2,2,2,2,2,2,1,2,2,2,2,1,2,2,2,1,1,2,2,1,2
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"""

lst = []
rule_table = []
for i in rule_table_string.split("\n")[1:]:
    lst = []
    for j in i.split(",")[:-1]:
        lst.append(int(j))

    rule_table.append(lst)


# Information about the Rule (Must be filled)
n_states = len(rule_table)  # Number of States
alternating_period = 1  # For alternating rules / neighbourhoods
colour_palette = None  # Colours of the different states
rule_name = "Rule_1"  # Rule Name


# Neighbourhood of the Rule (Relative Distance from Central Cell)
def get_neighbourhood(generation):  # Note (y, x) not (x, y)
    return [(2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
            (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
            (0, -2), (0, -1), (0, 0), (0, 1), (0, 2),
            (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
            (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)]


# Transition Function of Rule, Last Element of Neighbours is the Central Cell
def transition_func(neighbours, generation):
    n = 0
    weights = [1, 2, 3, 2, 1,
               2, 4, 6, 4, 2,
               3, 6, 9, 6, 3,
               2, 4, 6, 4, 2,
               1, 2, 3, 2, 1]
    state_weights = [0, 1, 0, 0, 0]

    for i in range(len(neighbours) - 1):
        n += weights[i] * state_weights[neighbours[i]]

    try:
        if n >= 0:
            return rule_table[neighbours[-1]][n]
        else:
            return 0
    except IndexError:
        return 0


# Does the next state of the cell depend on its neighbours?
# If yes, return next state
# If no, return -1
def depend_on_neighbours(state, generation):
    return -1
Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

There is no problem with the file.
Perhaps you should check if the transFunc.py inside the same folder as Main.py has the contents of Rule_4 or Rule_1. I am only able to replicate this error if Rule_4 is loaded instead of Rule_1.

I have added logging of the rule file into log.log instead of cmd as it would get too cluttered. When reporting bugs in future, please upload log.log as well.
Attachments
CAViewer.zip
(2.26 MiB) Downloaded 186 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

An important fact that I have not mentioned is that the behavior of a rule seems to depend on prior activity. All of the example problems that are documented above are intermittent. Sometimes the rules work correctly and sometimes they don't.

I will try your new version tomorrow.

Brian Prentice
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Tried the new version. Loading rule ../Others/Rule_4 and then loading pattern Oscillator produced the same error dialog as shown above.

Here is log.log:

Code: Select all

INFO:root:==========APPLICATION STARTING==========
INFO:root:Changed Mode to Selecting
INFO:root:Start selecting at (34, 41)
INFO:root:Stopped selecting at (90, 88)
INFO:root:Start selecting at (31, 107)
INFO:root:Stopped selecting at (31, 106)
INFO:root:Start selecting at (36, 42)
INFO:root:Stopped selecting at (93, 81)
INFO:root:Start selecting at (25, 100)
INFO:root:Stopped selecting at (25, 100)
INFO:root:Start selecting at (38, 68)
INFO:root:Stopped selecting at (93, 101)
INFO:root:Generating Single-state Soup of density 0.5 and symmetry C1
INFO:root:Start selecting at (142, 122)
INFO:root:Stopped selecting at (141, 122)
INFO:root:Start selecting at (63, 61)
INFO:root:Stopped selecting at (271, 168)
INFO:root:Start selecting at (86, 44)
INFO:root:Stopped selecting at (178, 137)
INFO:root:Generating Single-state Soup of density 0.5 and symmetry C1
INFO:root:Start selecting at (57, 85)
INFO:root:Stopped selecting at (57, 84)
INFO:root:Changed Mode to Selecting
INFO:root:Start selecting at (144, 93)
INFO:root:Stopped selecting at (187, 153)
INFO:root:Start selecting at (58, 173)
INFO:root:Stopped selecting at (58, 174)
INFO:root:==========APPLICATION STARTING==========
INFO:root:Opening Pattern...
INFO:root:Drawing at with state 1(60, 90)
INFO:root:Drawing at with state 1(60, 90)
INFO:root:Changed Mode to Selecting
INFO:root:Start selecting at (100, 58)
INFO:root:Stopped selecting at (145, 103)
INFO:root:Generating Single-state Soup of density 0.5 and symmetry C1
INFO:root:==========APPLICATION STARTING==========
INFO:root:Opening Pattern...
INFO:root:Changed Mode to Selecting
INFO:root:Start selecting at (17, 9)
INFO:root:Stopped selecting at (60, 45)
INFO:root:rule_table_string = """
0,0,0,0,0,0,1,0,0,3,0,2,9,0,0,0,0,3,0,0,0,0,0,1,1,5,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2,2,2,2,2,1,2,1,1,3,2,2,6,2,1,2,2,1,2,2,1,2,2,2,3,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,2,9,2,9,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
4,4,4,4,4,4,4,4,4,4,4,4,1,4,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,4,6,4,4,4,4,4,4,4,4,4,4,4,4
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,1,1,1,5,5,5,5,1,5,5,5,5,5,9,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
6,6,6,6,6,6,6,6,6,6,6,2,6,6,6,6,6,6,6,6,6,1,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
7,7,7,7,7,7,7,7,7,7,7,7,7,1,7,1,3,7,7,5,7,7,7,2,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7,7,7,1,7,1,7,7,2,7,2,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,5,8,5,4,8,8,8,8,8,5,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
9,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9
0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"""

lst = []
rule_table = []
for i in rule_table_string.split("\n")[1:]:
    lst = []
    for j in i.split(",")[:-1]:
        lst.append(int(j))

    rule_table.append(lst)

# Information about the Rule (Must be filled)
n_states = len(rule_table)  # Number of States
alternating_period = 1  # For alternating rules / neighbourhoods
colour_palette = None  # Colours of the different states
rule_name = "Rule_4"  # Rule Name


# Neighbourhood of the Rule (Relative Distance from Central Cell)
def get_neighbourhood(generation):  # Note (y, x) not (x, y)
    return [(2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
            (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
            (0, -2), (0, -1), (0, 0), (0, 1), (0, 2),
            (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
            (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)]


# Transition Function of Rule, Last Element of Neighbours is the Central Cell
def transition_func(neighbours, generation):
    n = 0
    weights = [1, 2, 2, 2, 1,
               2, 5, 6, 5, 2,
               2, 6, 9, 6, 2,
               2, 5, 6, 5, 2,
               1, 2, 2, 2, 1]
    state_weights = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

    for i in range(len(neighbours) - 1):
        n += weights[i] * state_weights[neighbours[i]]

    try:
        if n >= 0:
            return rule_table[neighbours[-1]][n]
        else:
            return 0
    except IndexError:
        return 0


# Does the next state of the cell depend on its neighbours?
# If yes, return next state
# If no, return -1
def depend_on_neighbours(state, generation):
    return -1

INFO:root:==========APPLICATION STARTING==========
INFO:root:rule_table_string = """
0,0,0,0,0,0,1,0,0,3,0,2,9,0,0,0,0,3,0,0,0,0,0,1,1,5,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2,2,2,2,2,1,2,1,1,3,2,2,6,2,1,2,2,1,2,2,1,2,2,2,3,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,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9,9,9,9,9,9,9,9,9,9,9,9,9,9,9
0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"""

lst = []
rule_table = []
for i in rule_table_string.split("\n")[1:]:
    lst = []
    for j in i.split(",")[:-1]:
        lst.append(int(j))

    rule_table.append(lst)

# Information about the Rule (Must be filled)
n_states = len(rule_table)  # Number of States
alternating_period = 1  # For alternating rules / neighbourhoods
colour_palette = None  # Colours of the different states
rule_name = "Rule_4"  # Rule Name


# Neighbourhood of the Rule (Relative Distance from Central Cell)
def get_neighbourhood(generation):  # Note (y, x) not (x, y)
    return [(2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
            (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
            (0, -2), (0, -1), (0, 0), (0, 1), (0, 2),
            (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
            (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)]


# Transition Function of Rule, Last Element of Neighbours is the Central Cell
def transition_func(neighbours, generation):
    n = 0
    weights = [1, 2, 2, 2, 1,
               2, 5, 6, 5, 2,
               2, 6, 9, 6, 2,
               2, 5, 6, 5, 2,
               1, 2, 2, 2, 1]
    state_weights = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

    for i in range(len(neighbours) - 1):
        n += weights[i] * state_weights[neighbours[i]]

    try:
        if n >= 0:
            return rule_table[neighbours[-1]][n]
        else:
            return 0
    except IndexError:
        return 0


# Does the next state of the cell depend on its neighbours?
# If yes, return next state
# If no, return -1
def depend_on_neighbours(state, generation):
    return -1

INFO:root:==========APPLICATION STARTING==========
INFO:root:Opening Pattern...
INFO:root:rule_table_string = """
0,0,0,0,0,3,1,0,0,0,3,0,0,2,0,0,0,2,0,0,0,0,0,0,0,3,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0
2,2,2,2,2,2,2,2,1,2,2,1,2,2,1,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,3,2,1,1,2,2,2,2,1,2,2,2,1,2,1,2,2,2,3,1,1,2,1,1,1,1,1,2,2,2,2,2,2,2,1,2,2,2,2,1,2,2,2,1,1,2,2,1,2
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"""

lst = []
rule_table = []
for i in rule_table_string.split("\n")[1:]:
    lst = []
    for j in i.split(",")[:-1]:
        lst.append(int(j))

    rule_table.append(lst)


# Information about the Rule (Must be filled)
n_states = len(rule_table)  # Number of States
alternating_period = 1  # For alternating rules / neighbourhoods
colour_palette = None  # Colours of the different states
rule_name = "Rule_1"  # Rule Name


# Neighbourhood of the Rule (Relative Distance from Central Cell)
def get_neighbourhood(generation):  # Note (y, x) not (x, y)
    return [(2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
            (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
            (0, -2), (0, -1), (0, 0), (0, 1), (0, 2),
            (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
            (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)]


# Transition Function of Rule, Last Element of Neighbours is the Central Cell
def transition_func(neighbours, generation):
    n = 0
    weights = [1, 2, 3, 2, 1,
               2, 4, 6, 4, 2,
               3, 6, 9, 6, 3,
               2, 4, 6, 4, 2,
               1, 2, 3, 2, 1]
    state_weights = [0, 1, 0, 0, 0]

    for i in range(len(neighbours) - 1):
        n += weights[i] * state_weights[neighbours[i]]

    try:
        if n >= 0:
            return rule_table[neighbours[-1]][n]
        else:
            return 0
    except IndexError:
        return 0


# Does the next state of the cell depend on its neighbours?
# If yes, return next state
# If no, return -1
def depend_on_neighbours(state, generation):
    return -1

INFO:root:==========APPLICATION STARTING==========
INFO:root:Changed Mode to Selecting
INFO:root:Start selecting at (57, 46)
INFO:root:Stopped selecting at (84, 69)
INFO:root:Start selecting at (16, 107)
INFO:root:Stopped selecting at (16, 106)
INFO:root:Start selecting at (44, 47)
INFO:root:Stopped selecting at (89, 88)
INFO:root:Generating Single-state Soup of density 0.5 and symmetry C1
INFO:root:==========APPLICATION STARTING==========
INFO:root:Opening Pattern...
INFO:root:Cancelled Operation
INFO:root:rule_table_string = """
0,0,0,0,0,0,1,0,0,3,0,2,9,0,0,0,0,3,0,0,0,0,0,1,1,5,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2,2,2,2,2,1,2,1,1,3,2,2,6,2,1,2,2,1,2,2,1,2,2,2,3,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,2,9,2,9,2,2,2,3,3,3,3,3,3,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0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"""

lst = []
rule_table = []
for i in rule_table_string.split("\n")[1:]:
    lst = []
    for j in i.split(",")[:-1]:
        lst.append(int(j))

    rule_table.append(lst)

# Information about the Rule (Must be filled)
n_states = len(rule_table)  # Number of States
alternating_period = 1  # For alternating rules / neighbourhoods
colour_palette = None  # Colours of the different states
rule_name = "Rule_4"  # Rule Name


# Neighbourhood of the Rule (Relative Distance from Central Cell)
def get_neighbourhood(generation):  # Note (y, x) not (x, y)
    return [(2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
            (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
            (0, -2), (0, -1), (0, 0), (0, 1), (0, 2),
            (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
            (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)]


# Transition Function of Rule, Last Element of Neighbours is the Central Cell
def transition_func(neighbours, generation):
    n = 0
    weights = [1, 2, 2, 2, 1,
               2, 5, 6, 5, 2,
               2, 6, 9, 6, 2,
               2, 5, 6, 5, 2,
               1, 2, 2, 2, 1]
    state_weights = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

    for i in range(len(neighbours) - 1):
        n += weights[i] * state_weights[neighbours[i]]

    try:
        if n >= 0:
            return rule_table[neighbours[-1]][n]
        else:
            return 0
    except IndexError:
        return 0


# Does the next state of the cell depend on its neighbours?
# If yes, return next state
# If no, return -1
def depend_on_neighbours(state, generation):
    return -1

INFO:root:Opening Pattern...
Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

I have managed to recreate the error.
When a new rule is opened, a message pops up to say that you have to reload the application before the rule updates.

I believe you did not reload the application. I hope this helps. Please inform me of any other bugs.
I will add this to the README.md.
Pic.png
Pic.png (35.99 KiB) Viewed 7813 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Requiring the user to close the cmd window, execute RunMain.bat, reposition and resize the cmd and application windows in order to successfully change rules is a serious inconvenience. Your software should do all the required initializing. The 'load rule' command is not even necessary. The 'load pattern' command has all the information needed to check the current rule, replace it with the correct rule if necessary, clear the display if the current and new number of states differ and perform any required initialization before loading the pattern.

Consider centering a new pattern in the display when loading. Placing them in the top left corner causes a ship to be quickly lost if it is moving up or left.

Do you plan to implement pattern editing such as rotating and flipping?

Why are two buttons necessary to set a selection to a random state? A single button could simply use the current number of states to perform the operation correctly.

Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Update v1.6:

Added Random Rule Generation - "?" for random transition in rulestring (b3s?,3) -> New Rule in File Menu
Note: Random Generation of Neighbourhood Weights is not Isotropic Yet (Working on it)
Removed need to reload application after loading rule
When opening pattern, it is now lower and further to the left. However, it is still not centred. For that, I will need window size.
The 'load pattern' command has all the information needed to check the current rule, replace it with the correct rule if necessary, clear the display if the current and new number of states differ and perform any required initialization before loading the pattern.
Working on it. Will take a while though.
Do you plan to implement pattern editing such as rotating and flipping?
Yes, probably next update.
Why are two buttons necessary to set a selection to a random state? A single button could simply use the current number of states to perform the operation correctly.
One button is for a Single State Random Soup and the other is for a Multi State Random Soup.

Source Code + WinPython Installation Here:
https://github.com/jedlimlx/Cellular-Automaton-Viewer

Source Code Only is as attached
Attachments
CAViewer.zip
(2.27 MiB) Downloaded 199 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

Big improvement, well done!
lemon41625 wrote: April 17th, 2020, 9:44 pm One button is for a Single State Random Soup and the other is for a Multi State Random Soup.
You could add a widget to the 'random soup settings' dialog which displays the current rule's state colors and allows the user to select which ones should be included in the soup.

Consider keyboard short cuts for starting and stopping the simulation (return key), stepping the simulation (space bar)

It would be nice if the current rule name, pattern name and number of state's were displayed.

Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Update v1.7:

Added Keyboard Shortcuts for Stepping 1 Generation (Space) and Pausing / Running Simulation (Return)
Now replaces current rule with required rule when pattern is loaded
Added Rotating and Flipping Selection
Displays Pattern Name and Rule Name as well as number of states
Random Generation of Neighbourhood Weights is now Isotropic

In transFunc.py, there is a script that implements range 2 isotropic non totalistic von neumann rulespace. I have fixed it.
It still does not simulate the SkewLife correctly. I am not sure it is because I did something wrong or the rulestring is wrong.

Also I am looking for suggestions on how to identify patterns such as rakes, puffers, breeders and replicators as well as find their speed.

Source Code + WinPython Installation here:
https://github.com/jedlimlx/Cellular-Automaton-Viewer

Source Code is as attached
Attachments
CAViewer.zip
(2.35 MiB) Downloaded 173 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Update v1.8:

Added options for choosing what states to include in random soup.
Added identification for replicators (It is somewhat reliable, does not working for moving replicators and quadratic replicators yet).
- Also does not work for replicators that produce debris.
- Does not always work. Tested it on Brian Prentice's Oblique Replicator https://conwaylife.com/forums/viewtopic ... 7&start=25
(Did not work)

Added more rules to Rules Folder:
WeighedGenerations_Rule_10 - It is non-isotropic and has oblique wickstrecher and spaceship.


Picture of Replicator Identification in PigsReverseGenerationsVariant
Pic.png
Pic.png (44.31 KiB) Viewed 7624 times
Source Code + WinPython Installation: https://github.com/jedlimlx/Cellular-Automaton-Viewer
Source Code is attached:
Attachments
CAViewer.zip
(2.37 MiB) Downloaded 184 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

To simplify and reduce the number of your transition functions consider a design that uses python classes to implement rule families.

An object created from the base rule class reads and writes the pattern specification which is common to all rules. Objects created from inherited rule classes implement a specific rule family. Methods in these inherited classes use dialogs to display and obtain rule parameters and options. Methods are also provided to generate and test new rules.

All pattern files contain a complete description of their associated rule. This would include the rule parameters and options.

As an example a single rule family using dialogs like these which specify the Star Wars rule:

d1.png
d1.png (104.66 KiB) Viewed 7608 times
d2.png
d2.png (61.99 KiB) Viewed 7608 times

could be used to specify your Outer Totalistic (normal and weighted) rules, Generations (normal and weighted) rules and Rule_1 thru Rule_4 in your Others directory. As a bonus such a rule family supports the Wire World rule and variants.

As a test of your pattern editing implementation construct this pattern from a single cell:

p.png
p.png (242.58 KiB) Viewed 7608 times


Brian Prentice
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

I have already done something similar here:
Pic.png
Pic.png (44.31 KiB) Viewed 7588 times
However, custom rule families are not yet supported. I will get it done soon.
Next update, I will also add BokaBB's Semi Totalistic Larger then Life and my regenerating generations rulespace.
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
User avatar
yujh
Posts: 3153
Joined: February 27th, 2020, 11:23 pm
Location: I'm not sure where I am, so please tell me if you know
Contact:

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by yujh »

Are you going to try something like apgsearch there?
Rule modifier

B34kz5e7c8/S23-a4ityz5k
b2n3-q5y6cn7s23-k4c8
B3-kq6cn8/S2-i3-a4ciyz8
B3-kq4z5e7c8/S2-ci3-a4ciq5ek6eik7

Bored of Conway's Game of Life? Try Pedestrian Life -- not pedestrian at all!
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

I will eventually get to it. However, it would be really slow unless I find a way to optimize that algorithm.
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
User avatar
yujh
Posts: 3153
Joined: February 27th, 2020, 11:23 pm
Location: I'm not sure where I am, so please tell me if you know
Contact:

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by yujh »

Oh and where can I download the wpy64 thing?( original site)
Rule modifier

B34kz5e7c8/S23-a4ityz5k
b2n3-q5y6cn7s23-k4c8
B3-kq6cn8/S2-i3-a4ciyz8
B3-kq4z5e7c8/S2-ci3-a4ciq5ek6eik7

Bored of Conway's Game of Life? Try Pedestrian Life -- not pedestrian at all!
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Download here: https://winpython.github.io/ (Download the one with Python 3.something only)

But you probably will just need python 3.6.

So, download python 3.6 or higher here: https://www.python.org/downloads/.
When installing, click the checkbox add to PATH.

After installation, go to cmd and run:
pip3 install PyQt5
pip3 install pyperclip
pip3 install numpy
pip3 install pillow

If pip3 does not work, you can just use pip.
After which, you should be able to run Main.py without issues.
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
User avatar
yujh
Posts: 3153
Joined: February 27th, 2020, 11:23 pm
Location: I'm not sure where I am, so please tell me if you know
Contact:

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by yujh »

lemon41625 wrote: April 23rd, 2020, 5:07 am Download here: https://winpython.github.io/ (Download the one with Python 3.something only)

But you probably will just need python 3.6.

So, download python 3.6 or higher here: https://www.python.org/downloads/.
When installing, click the checkbox add to PATH.

After installation, go to cmd and run:
pip3 install PyQt5
pip3 install pyperclip
pip3 install numpy
pip3 install pillow

If pip3 does not work, you can just use pip.
After which, you should be able to run Main.py without issues.
Can I use p2.x and p3.x at the same time?
Rule modifier

B34kz5e7c8/S23-a4ityz5k
b2n3-q5y6cn7s23-k4c8
B3-kq6cn8/S2-i3-a4ciyz8
B3-kq4z5e7c8/S2-ci3-a4ciq5ek6eik7

Bored of Conway's Game of Life? Try Pedestrian Life -- not pedestrian at all!
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Yes. If Python 2.x is added to your PATH already, do not add Python 3.x to your PATH.

Instead to install the packages you will have to 'cd' into the Python 3.x installation folder and pip install from there.

However, I think it would be better if you installed https://winpython.github.io/ if that is the case.
Download WinPython64-3.7.7.0dot from https://sourceforge.net/projects/winpyt ... 7/3.7.7.0/.

After downloading, there is an .exe that will unzip into the installation.
Move the folders into the CAViewer folder.

Run the pip commands I mentioned above in the WinPython Command Prompt.
Afterwards, you should be able to run Main.bat and the program should start.
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
lemon41625
Posts: 370
Joined: January 24th, 2020, 7:39 am
Location: 小红点 (if you know where that is)

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by lemon41625 »

Update v1.9:

Added BokaBB's Semi Totalistic Rulespace (For now it is avaliable as a b/s condition for single state and extended generations rules)
Added Regenerating Generations Rulespace
Added Some Sample Rules using the 2 Rulespaces to Rules Folder

If you have any feedback about the application or problems running it, please let me know.

Note: There was a major bug in the previous release of v1.9, I have uploaded the fixed copy.

Update v1.9.1:
Just a small update with minor improvements.
BokaBB Rulespace Simulation is Now Faster (Supporting Various Neighbourhoods and Weights)

Added Some Sample Rules using BokaBB B/S Condition (In the application, it is called BokaBB until it gets a proper name)
GIF of one of the rules:
BokaBB2.gif
BokaBB2.gif (991.65 KiB) Viewed 7460 times
Source Code + WinPython Installation: https://github.com/jedlimlx/Cellular-Automaton-Viewer
Source Code as Attached:
Attachments
CAViewer.zip
(2.55 MiB) Downloaded 143 times
Download CAViewer: https://github.com/jedlimlx/Cellular-Automaton-Viewer

Supports:
BSFKL, Extended Generations, Regenerating Generations, Naive Rules, R1 Moore, R2 Cross and R2 Von Neumann INT
And some others...
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: CAViewer - A Cellular Automaton Simulator written in Python

Post by bprentice »

How are rules GenerationsBokaBB_Rule_1 and GenerationsBokaBB_Rule_2 loaded?

The expected transFunc.py file has been replaced by a rule.ca_rule file in their directories.


Brian Prentice
Post Reply