R/helpers.R

Defines functions pr_gb1989 pr_nes1989

pr_nes1989 <- function(x, state, log = FALSE) {
  # lookup table, based on 1e7 draws from rtetris
  transition_probabilities <- matrix(
  c(0.03117, 0.15621, 0.18752, 0.15643, 0.15626, 0.15622, 0.15619,
    0.15676, 0.06248, 0.15576, 0.15654, 0.15592, 0.15658, 0.15597,
    0.15579, 0.18748, 0.03140, 0.15617, 0.15633, 0.15645, 0.15638,
    0.15621, 0.15659, 0.15638, 0.03120, 0.18726, 0.15620, 0.15616,
    0.15584, 0.15662, 0.18753, 0.15641, 0.03121, 0.15646, 0.15594,
    0.15632, 0.15575, 0.15641, 0.18753, 0.15650, 0.03119, 0.15631,
    0.15616, 0.15661, 0.15658, 0.15609, 0.15585, 0.15618, 0.06252),
    ncol = 7, byrow = TRUE)
  tetrominoes <- c("I", "J", "L", "O", "S", "T", "Z")
  state_i <- match(state, tetrominoes)
  x_i <- match(x, tetrominoes)
  out <- transition_probabilities[state_i, x_i]
  if (log == TRUE) out <- log(out)
  return(out)
}


pr_gb1989 <- function(x, state, log = FALSE) {
  # lookup table, based on 1e7 draws from rtetris
  transition_probabilities <- matrix(
    c(0.01196, 0.19500, 0.01133, 0.19639, 0.19613, 0.19321, 0.19599,
      0.14267, 0.14237, 0.14342, 0.14212, 0.14264, 0.14351, 0.14326,
      0.01228, 0.19708, 0.01203, 0.19576, 0.19391, 0.19340, 0.19554,
      0.14167, 0.14219, 0.14424, 0.14288, 0.14376, 0.14278, 0.14248,
      0.14430, 0.14220, 0.14292, 0.14333, 0.14283, 0.14242, 0.14200,
      0.14326, 0.14291, 0.14280, 0.14258, 0.14378, 0.14307, 0.14159,
      0.14291, 0.14249, 0.14348, 0.14299, 0.14212, 0.14372, 0.14229,
      0.14288, 0.14274, 0.14339, 0.14184, 0.14396, 0.14313, 0.14204,
      0.19440, 0.01178, 0.01144, 0.19682, 0.19579, 0.19431, 0.19547,
      0.19555, 0.01169, 0.01159, 0.19480, 0.19440, 0.19741, 0.19456,
      0.14404, 0.14099, 0.14278, 0.14397, 0.14344, 0.14144, 0.14334,
      0.14284, 0.14201, 0.14143, 0.14429, 0.14300, 0.14331, 0.14312,
      0.14286, 0.14195, 0.14388, 0.14309, 0.14267, 0.14298, 0.14256,
      0.14436, 0.14185, 0.14362, 0.14288, 0.14173, 0.14221, 0.14334,
      0.14505, 0.14219, 0.14188, 0.14261, 0.14295, 0.14326, 0.14206,
      0.14408, 0.14279, 0.14154, 0.14372, 0.14185, 0.14357, 0.14245,
      0.16860, 0.16552, 0.00270, 0.17000, 0.16001, 0.16698, 0.16619,
      0.14283, 0.14276, 0.14235, 0.14484, 0.14256, 0.14240, 0.14226,
      0.14419, 0.14179, 0.14247, 0.14160, 0.14335, 0.14247, 0.14412,
      0.14173, 0.14294, 0.14231, 0.14261, 0.14211, 0.14383, 0.14447,
      0.14451, 0.14243, 0.14046, 0.14346, 0.14251, 0.14294, 0.14370,
      0.04624, 0.04675, 0.04705, 0.04562, 0.27219, 0.27131, 0.27084,
      0.04647, 0.04674, 0.04664, 0.04671, 0.26990, 0.27081, 0.27273,
      0.04729, 0.04715, 0.04647, 0.04652, 0.26869, 0.27143, 0.27245,
      0.04677, 0.04585, 0.04661, 0.04656, 0.27233, 0.27165, 0.27023,
      0.14292, 0.14215, 0.14244, 0.14266, 0.14352, 0.14350, 0.14281,
      0.14332, 0.14328, 0.14425, 0.14165, 0.14284, 0.14086, 0.14381,
      0.14286, 0.14252, 0.14186, 0.14392, 0.14373, 0.14264, 0.14245,
      0.14199, 0.14233, 0.14302, 0.14276, 0.14293, 0.14367, 0.14330,
      0.27013, 0.04724, 0.04616, 0.27094, 0.04590, 0.27234, 0.04729,
      0.26975, 0.04651, 0.04707, 0.27173, 0.04699, 0.27110, 0.04686,
      0.14376, 0.14274, 0.14150, 0.14118, 0.14367, 0.14278, 0.14436,
      0.27114, 0.04681, 0.04706, 0.26947, 0.04604, 0.27256, 0.04691,
      0.14373, 0.14234, 0.14269, 0.14292, 0.14264, 0.14302, 0.14264,
      0.27005, 0.04656, 0.04650, 0.27191, 0.04680, 0.27169, 0.04650,
      0.04649, 0.27223, 0.04688, 0.27007, 0.27036, 0.04681, 0.04716,
      0.14314, 0.14211, 0.14348, 0.14297, 0.14326, 0.14254, 0.14250,
      0.04682, 0.27065, 0.04736, 0.27007, 0.27240, 0.04650, 0.04620,
      0.14429, 0.14231, 0.14426, 0.14154, 0.14295, 0.14317, 0.14149,
      0.14254, 0.14356, 0.14341, 0.14162, 0.14311, 0.14285, 0.14292,
      0.04614, 0.27280, 0.04665, 0.27171, 0.26969, 0.04736, 0.04565,
      0.04654, 0.27176, 0.04617, 0.26990, 0.27228, 0.04642, 0.04693,
      0.14383, 0.14175, 0.14244, 0.14310, 0.14377, 0.14216, 0.14295,
      0.14181, 0.14330, 0.14319, 0.14275, 0.14248, 0.14320, 0.14326,
      0.19629, 0.19430, 0.01166, 0.19511, 0.19416, 0.19711, 0.01137,
      0.14245, 0.14327, 0.14341, 0.14197, 0.14358, 0.14410, 0.14123,
      0.14304, 0.14454, 0.14214, 0.14224, 0.14256, 0.14190, 0.14357,
      0.14319, 0.14266, 0.14245, 0.14341, 0.14320, 0.14281, 0.14228,
      0.19457, 0.19458, 0.01217, 0.19424, 0.19717, 0.19536, 0.01192),
    ncol = 7, byrow = TRUE)
  states <- c(
    "II", "IJ", "IL", "IO", "IS", "IT", "IZ",
    "JI", "JJ", "JL", "JO", "JS", "JT", "JZ",
    "LI", "LJ", "LL", "LO", "LS", "LT", "LZ",
    "OI", "OJ", "OL", "OO", "OS", "OT", "OZ",
    "SI", "SJ", "SL", "SO", "SS", "ST", "SZ",
    "TI", "TJ", "TL", "TO", "TS", "TT", "TZ",
    "ZI", "ZJ", "ZL", "ZO", "ZS", "ZT", "ZZ")
  state_i <- match(state, states)
  tetrominoes <- c("I", "J", "L", "O", "S", "T", "Z")
  x_i <- match(x, tetrominoes)
  out <- transition_probabilities[state_i, x_i]
  if (log == TRUE) out <- log(out)
  return(out)
}
babeheim/tetristools documentation built on Jan. 6, 2021, 8:17 a.m.