WFL Statistical Script

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
Extrementhusiast
Posts: 1966
Joined: June 16th, 2009, 11:24 pm
Location: USA

WFL Statistical Script

Post by Extrementhusiast » January 25th, 2014, 6:40 pm

(Interestingly enough, this is actually my first post in the Scripts subforum!)

I have been thinking about making a script for a statistical question I came up with. However, as I know pretty much no Python (I have mainly been working in Lua, and I am currently only set up for Python scripts), I am putting this request out there.

What I am looking for:
  1. Check to see if there is room for a new layer
  2. Clear the current layer
  3. Prompt for number of samples
  4. Change to a particular rule that I have already created
  5. Make a 50% dense, 201x201 random soup of state 1 in that layer
  6. Set the central cell to state 3
  7. Run the pattern until stabilization (there is no chance of oscillation in this particular rule), or until a cutoff of 1000 generations (at which point it displays an error)
  8. Change to another particular rule that I have already created
  9. Run the pattern for one step
  10. Record the pattern population
  11. Increment the (population)th entry in a table by one
  12. Repeat from step 3 until the number of samples is reached
  13. Create a new layer
  14. Plot the results cell-by-cell in the other (currently unused) layer (in which the pattern is free to extend beyond the edge of the screen)
In pseudocode:

Code: Select all

-- Step 1:
if num_layers=10 then
   print(error_message)
end
-- Step 2:
new_pattern()
-- Step 3:
prompt(number_of_samples)
-- Some variable declarations:
data={}
var pop=0
var max_pop=0
var prevmax_pop=0
-- To be repeated:
for i=1,number_of_samples do
   -- Step 4:
   set_rule_to(WFLanalyze-1)
   -- Step 5:
   random_soup({0,0},{200,200},1,{50,50}) -- corner, opposite corner, maximum state number, percentage table
   -- Step 6:
   set_cell({100,100},3) -- location, state
   -- Step 7:
   step()
   if population(time) != population(time-1) then
      if time>1000 then
         print(error_message)
      else
         step()
      end
   end
   -- Step 8:
   set_rule_to(WFLanalyze-2)
   -- Step 9:
   step()
   -- Step 10:
   set pop=current_population
   -- Autofills used section of table with zeroes (to prevent an error)
   if pop>max_pop+1 then
      set prevmax_pop=max_pop
      set max_pop=pop
      for j=prevmax_pop+1,max_pop do
         data[j]=0
      end
   end
   -- Step 11:
   data[pop]=data[pop]+1
   -- Resets back to time 0:
   reset()
end
-- Step 13:
create_new_layer()
-- Step 14:
for k=0,num_entries(data) do
   set_cell({k,data[k]},1)
end
And just for reference, the two (very simple) rules:
#1 (to floodfill):

Code: Select all

n_states:4
neighborhood:vonNeumann
symmetries:permute

var a={2,3}
var b={0,1,2,3}
var c={b}
var d={b}

0,a,b,c,d,2
#2 (to delete extraneous cells):

Code: Select all

n_states:4
neighborhood:vonNeumann
symmetries:permute

var a={0,1}
var b={a}
var c={a}
var d={a}

1,a,b,c,d,0
I Like My Heisenburps! (and others)

Post Reply