conway                package:simecol                R Documentation

_T_h_e _C_l_a_s_s_i_c_a_l _C_o_w_a_y'_s _G_a_m_e _o_f _L_i_f_e

_D_e_s_c_r_i_p_t_i_o_n:

     'simecol' example: This model simulates a deterministic cellular
     automaton.

_U_s_a_g_e:

     data(conway)

_F_o_r_m_a_t:

     An S4 object according to the 'gridModel' specification. The
     object contains the following slots:


     '_m_a_i_n' functions with the state transition rules.

     '_p_a_r_m_s' A list with two vector elements:

          '_s_r_v' number of neighbours, necessary to survive,

          '_g_e_n' number of neighbours, necessary to generate a new cell.


     '_t_i_m_e_s' number of time steps to be simulated,

     '_i_n_i_t' matrix with the initial state of the cellular grid
          (default: random).  


_D_e_t_a_i_l_s:

     To see all details, please have a look into the implementation
     below.

_R_e_f_e_r_e_n_c_e_s:

     Gardner, Martin (1970) The Fantastic Combinations of John Conway's
     New Solitaire Game 'Life.' _Scientific American_, October 1970.

_S_e_e _A_l_s_o:

     'sim', 'parms', 'init', 'times'.

_E_x_a_m_p_l_e_s:

     ##============================================
     ## Basic Usage:
     ##   explore the example
     ##============================================
     data(conway)
     plot(sim(conway))

     ## more interesting start conditions
     m <- matrix(0, 40, 40)
     m[5:35,19:21] <-1
     init(conway) <- m
     plot(sim(conway), col=c("white", "green"), axes=FALSE)

     ## change survival rules
     parms(conway) <- list(srv=c(3,4), gen=c(3,4))
     plot(sim(conway), col=c("white", "green"), axes=FALSE)
     ## Not run: 
     init(conway) <- matrix(0, 10, 10)
     fixInit(conway) # enter some "1"
     sim(conway, animate=TRUE, delay=100)

     ##============================================
     ## Implementation:
     ##   The code of Conways Game of Life
     ##============================================
     conway <- new("gridModel",
       main = function(time, init, parms) {
         x      <- init
         nb     <- eightneighbours(x)
         surviv <- (x >  0 & (nb 
         gener  <- (x == 0 & (nb 
         x      <- as.numeric((surviv + gener) > 0)
         dim(x) <- dim(init)
         return(x)
       },
       parms  = list(srv = c(2, 3), gen = 3),
       times  = 1:17,
       init   = matrix(round(runif(1000)), ncol=40),
       solver = "iteration"
     )
     ## End(Not run)

