read_rcg.R 843 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
#' Read RCG file
#' 
#' @param path RCG file path
#' @return Parsed tibble of RCG file in \code{path}
#' @examples 
#' read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg")
read_rcg <- function(path) {
  rcg <- path |>
    readr::read_file() |>
    jsonlite::parse_json(simplifyVector = TRUE, flatten = TRUE) |>
11
    tibble::as_tibble() |>
12
    dplyr::filter(type == "show") |>
13
    dplyr::select(time,stime,players, ball.x, ball.y, ball.vx, ball.vy) |>
14
    tidyr::unnest(players) |>
15
16
17
18
19
    dplyr::select(time:capacity, ball.x:ball.vy) |>
    dplyr::rename(step = time) |>
    dplyr::rename_with(stringr::str_replace, pattern = "\\.", replacement = "_")
  
  return(rcg)
20
}
21
22
23
24
25
26
27
28

get_ball <- function(rcg) {
  ball <- rcg |>
    dplyr::select(step, ball_x, ball_y, ball_vx, ball_vy) |>
    dplyr::distinct(step,.keep_all = TRUE)
  
  return(ball)
}