David Brunton
Friday, April 20, 2007
  Deus Ex Automatis, Part V(b)
We've already got code for rules from last post. Now we need a grid.
class Grid {
has Int $.diameter is rw;
has Bool @.state is rw;

submethod BUILD (:$.diameter) {
@.state = 1,;
@.state.push( 0 xx ($.diameter-1) );
}
}

Fairly simple, takes one argument: diameter. Building a new grid is done like so:
pugs> my Grid $grid .= new( :diameter(10));
pugs> say $grid.state;
1000000000
Once again, we've taken some shortcuts. The grid code assumes a single dimension, with a second, emergent dimension (often called "time") that happens when you apply the rule.

Now that we've got a rule, and got a grid, we can put them together into a cellular automaton, and discover some more syntactic (and semantic) sugar from Perl 6.

Labels: , ,

 


Links to this post:

Create a Link



<< Home
A journal covering primarily technical topics.

Name: David Brunton
Location: Washington, DC, United States
Archives
January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / December 2007 / January 2008 / February 2008 / March 2008 /


Powered by Blogger

Subscribe to
Posts [Atom]