A simulator simulating a 3D variant of Factorio

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
H. H. P. M. P. Cole
Posts: 330
Joined: July 15th, 2023, 9:36 pm

A simulator simulating a 3D variant of Factorio

Post by H. H. P. M. P. Cole » August 27th, 2024, 12:38 am

This is a script used to simulate user-specified patterns in a 3D variant of Factorio (R3,C2,S2,B3,N+), using a 3D variant of the Cross neighbourhood. The birth/survival conditions remain the same.

Specifically, it simulates this rule in a bounded 3-torus (whose size is given by the variable arraysize).

This script is written completely in Python 3. Feel free to ask questions about the script.

Code: Select all

import random

arraysize = 16
ticks = 256
oscdetection = True
maxperiod = 256
alivecells = [[0,0,1],[0,1,0],[1,0,0],[1,1,1]]

array = []

for i in range(0, arraysize):
    newplane = []
    for j in range(0, arraysize):
        newrow = []
        for k in range(0, arraysize):
            if [k,j,i] in alivecells:
                newrow.append(1)
            else:
                newrow.append(0)
        newplane.append(newrow)
    array.append(newplane)

def runforonetick(array):
    arraytortured = []
    newarray = []
    for i in range(0, arraysize):
        newplane = []
        for j in range(0, arraysize):
            newrow = []
            for k in range(0, arraysize):
                nb = 0
                for b in [-3,-2,-1,1,2,3]:
                    nb = nb + array[(i+b)%arraysize][j][k]
                    nb = nb + array[i][(j+b)%arraysize][k]
                    nb = nb + array[i][j][(k+b)%arraysize]
                state = array[i][j][k]
                if state == 1 and nb == 2:
                    newrow.append(1)
                elif state == 0 and nb == 3:
                    newrow.append(1)
                else:
                    newrow.append(0)
            newplane.append(newrow)
        newarray.append(newplane)
    return newarray

def formarray(array):
    s = ''
    for i in range(0, arraysize):
        for j in range(0, arraysize):
            for k in range(0, arraysize):
                if array[i][j][k] == 1:
                    s = s + '*'
                if array[i][j][k] == 0:
                    s = s + '.'
            s = s + '\n'
        s = s + '\n\n\n\n\n'
    return s

if oscdetection == False:
    for a in range(0, ticks):
        print(a)
        array = runforonetick(array)

if oscdetection == True:
    soup = array
    arraylist = [soup]
    for i in range(0, maxperiod):
        array = runforonetick(array)
        arraylist.append(array)
    isosc = False
    p = []
    for i in range(0, maxperiod):
        index = maxperiod-i-1
        if arraylist[index] == arraylist[-1]:
            isosc = True
            p.append(maxperiod-index)
    if isosc == True:
        print('Configuration evolves to an oscillator with period '+str(p[0])+'.')
    if isosc == False:
        print('Configuration is either a high-period oscillator or a methuselah.')
Harfordson Parker-Cole

Factorio
Speciation (by NimbleRogue)

Post Reply