Cellular Automaton Syntax
- To: mathgroup at smc.vnet.net
- Subject: [mg123897] Cellular Automaton Syntax
- From: Mark Perrin <m.perrin at me.com>
- Date: Thu, 29 Dec 2011 02:51:45 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Hello,
I was wondering if I could get some help with syntax (if that is my
problem) for CellularAutomaton.
Rather than using the prespecified rules I want to simply replace
neighbouring cells according to a pattern.
If the cells number/color is "1" for instance, I want to change all
neighboring cells with a value of 0 to 1, and any cell with a value of
2,3,4 etc. to a number 1 higher, I also want to change the original cell
to a number higher.
Here is what I have:
(* I have an array 10x10, with a single seed *)
w = Array[0&, {10,10}];
w[[2,2]] = 1;
(* these are my neighboring cells (using a hexagonal lattice with six
neighbors) *)
n = {{0, 0}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}};
(* my replacement function; if the 'focus' cell is = 1 change it to 2
and increment all neighboring by 1, otherwise, increment all by 1 except
if they are = 0*)
f[x_]:= If[x[[1]]==1, x /. {0 -> 1, 1 -> 2, 2 -> 3, 3 -> 4}, x/.
{1 -> 2, 2 -> 3, 3 -> 4, 4->0}]
CellularAutomaton[{f[#] &, {}, n}, w, 1]
=97=97=97=97=97=97=97=97
The problem is quickly apparent that the function returns a list of the
neighboring cells which now populates the array, instead of replacing
the neighboring cells with their new value.
Question: how do I return the new values (after rule replacement) to the
array?
I am very new to cellular automata, so forgive me if I am ignoring some
basic principles.
Regards,
Mark