The package can be used to encode/decode Legends of Runeterra decks to/from simple strings. Such codes are e.g. generated by the game for imports and exports and also how decks are specified in the game API. Any analysis of matchdata therefore requires the ability to parse deck codes into actual deck lists.
This is an R implementation following https://github.com/RiotGames/LoRDeckCodes .
You can install lordecks from github via:
remotes::install_github("https://github.com/pholzmgit/lordecks")
The library provides a function that parses deck codes into interpretable deck lists. For the output format, 2 options are available
- minimalist character vector (“{count}:{cardcode}”, representing the testdata format of the original C# library)
- dataframe with some additional columns, ready for further analysis in R (default)
library(lordecks)
deck_code <- "CEDACAIFDUAQEBAIAECAIBICAECDGNACAMCQIBQDAMCAKDISAIAQCBBWAIAQKEZPAIAQGBIMAMAQKAIZEE"
simple_decklist <- get_decklist_from_code(deck_code, format = "simple")
simple_decklist
#> [1] "3:01SI029" "3:02PZ008" "3:04PZ005" "3:01PZ051" "3:01PZ052" "3:03SI004"
#> [7] "3:03SI006" "3:03PZ005" "3:03PZ013" "3:03PZ018" "2:01PZ054" "2:01SI019"
#> [13] "2:01SI047" "1:03SI012" "1:01SI001" "1:01SI025" "1:01SI033"
df_decklist <- get_decklist_from_code(deck_code)
df_decklist
#> cardcode count faction set card_number
#> 1 01SI029 3 SI 1 029
#> 2 02PZ008 3 PZ 2 008
#> 3 04PZ005 3 PZ 4 005
#> 4 01PZ051 3 PZ 1 051
#> 5 01PZ052 3 PZ 1 052
#> 6 03SI004 3 SI 3 004
#> 7 03SI006 3 SI 3 006
#> 8 03PZ005 3 PZ 3 005
#> 9 03PZ013 3 PZ 3 013
#> 10 03PZ018 3 PZ 3 018
#> 11 01PZ054 2 PZ 1 054
#> 12 01SI019 2 SI 1 019
#> 13 01SI047 2 SI 1 047
#> 14 03SI012 1 SI 3 012
#> 15 01SI001 1 SI 1 001
#> 16 01SI025 1 SI 1 025
#> 17 01SI033 1 SI 1 033
For both deck formats, functions for the reverse action are provided
get_code_from_decklist(simple_decklist)
#> [1] "CEDACAIFDUAQEBAIAECAIBICAECDGNACAMCQIBQDAMCAKDISAIAQCBBWAIAQKEZPAIAQGBIMAMAQKAIZEE"
# a dataframe with only 'cardcode' and 'count' columns is sufficient, all other columns are ignored
get_code_from_decklist_df(df_decklist)
#> [1] "CEDACAIFDUAQEBAIAECAIBICAECDGNACAMCQIBQDAMCAKDISAIAQCBBWAIAQKEZPAIAQGBIMAMAQKAIZEE"
The deck codes start with 4 bit for format and 4 bit for version. So far this only indicates which regions are available - too old versions of the decoder have no information on factions released more recently. Like the game client, this library encodes the minimal supported version based on the factions in the deck.
The C# library previously always generated codes with the latest version, but the most recent version (4+) behaves the same way. While older versions produced slightly different deck codes, the resulting decklists were identical.
#example code list provided from the test data set
code <- "CMAQSAIFBMHREHRAFEVCWMABAYAQKAIUDURSYLIBAEAQKGQ"
#manually import and re-export in the game (Patch 2.10)
code_game <- "CEAQSAIFBMHREHRAFEVCWMABAYAQKAIUDURSYLIBAEAQKGQ"
code_lordecks <- get_code_from_decklist_df(get_decklist_from_code(code))
code_lordecks
#> [1] "CEAQSAIFBMHREHRAFEVCWMABAYAQKAIUDURSYLIBAEAQKGQ"
identical(code, code_lordecks)
#> [1] FALSE
identical(code_game, code_lordecks)
#> [1] TRUE
identical(
get_decklist_from_code(code),
get_decklist_from_code(code_lordecks)
)
#> [1] TRUE