#' A Reference Class to represent a rule to be applied to a board
#'
#' @field survive vector of integers that determines which count of neighbors of a livin cell leads to survival
#' @field revive vector of integers that determines which count of neighbors of a dead cell leads to revival
#' @exportClass rule
#' @export Rule
Rule = setRefClass("rule", fields = list(survive = "numeric", revive = "numeric"),
methods = list(apply = function(sums, living) {
"Takes neighborhood sums and indication of living or dead and returns new states"
states <- vector(mode = "numeric", length = length(sums))
states[living] <- ifelse(sums[living] %in% .self$survive, TRUE, FALSE)
states[!living] <- ifelse(sums[!living] %in% .self$revive, TRUE, FALSE)
states
}))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.