conway: The Classical Coway's Game of Life

Description Usage Format Details References See Also Examples

Description

simecol example: This model simulates a deterministic cellular automaton.

Usage

1

Format

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

main

functions with the state transition rules.

parms

A list with two vector elements:

srv

number of neighbours, necessary to survive,

gen

number of neighbours, necessary to generate a new cell.

times

number of time steps to be simulated,

init

matrix with the initial state of the cellular grid (default: random).

Details

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

References

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

See Also

sim, parms, init, times.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##============================================
## 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: 
require("tcltk")
init(conway) <- matrix(0, 10, 10)
conway <- editInit(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 %in% parms$srv))
    gener  <- (x == 0 & (nb %in% parms$gen))
    x      <- (surviv + gener) > 0
    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)

simecol documentation built on Oct. 7, 2021, 9:20 a.m.