game-class: A Reference Class to represent a Game of Life

Description Fields Methods Examples

Description

A Reference Class to represent a Game of Life

Fields

board

Board-object to manage states and state-transistion

rule

Rule-object to control state-changes of the board

verbose

decide if basic information should be printed in each iteration

plot

decide if board should be plotted in each iteration

max_iterations

numeric to set the maximum number of iterations

endless

decide if game is endless

sleep_duration

set time to sleep for plotting

Methods

nextState()

Takes the game to it's next state

run()

Iterate game constantly until maximum number of iterations is reached or endlessly

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(gameOfLife)

rule = Rule(survive = c(2, 3), revive = c(3))

gol = Game(
  board = Board(
    matrix = gliders,
    shrink_counter = 0),
  rule = rule,
  iteration = 0,
  endless = FALSE,
  max_iterations = 100,
  sleep_duration = 0.05,
  plot = TRUE,
  verbose = TRUE
)

gol$run()

chrlen/gameOfLifeAgain documentation built on July 9, 2019, 11:42 a.m.