Update – extract.cards

The extract.cards() function we made a while back has been updated to include layout information about each card in anticipation of a major update to mtgjson that will bring in tokens from all of the game’s history.

For now let us the updated function to refine our estimate of how many cards exist.

First let’s summarize the information that is in layout. We will get rid of the joke sets early on since they needlessly confuse many things.

## Read the data into R.
AllSets <- fromJSON(file="AllSets.json")
source("CardExtract.R")

## Filter all of it through the extraction function bind it together and fix the row names.
l <- lapply(AllSets,extract.cards)
AllCards <- AllCards[AllCards$exp.type != "un",]
AllCards <- do.call(rbind.data.frame,l)
rownames(AllCards) <- 1:length(AllCards$cmc)

## Layout information
summary(AllCards$layout)
      normal     vanguard        token        split         flip        plane 
       24333          116           13          100           42           74 
     leveler       scheme double-faced   phenomenon 
          30           45           66            8 

Robert currently defines 10 distinct card layouts, each of which represent some trait of the card. Normal cards are laid out like we’ve seen before and levelers are pretty much the same, just modified to allow a unique ability.

Some of these are not “true” cards. The vanguards, planes, schemes, and phenomenon come from rare variants. Tokens are just representations of things that cards make. We will simply exclude these from our count.

The tricky part is the split cards, flip cards, and double-faced cards. Notice that there are even numbers of all of them, that’s not coincidental. Each card has two parts that are recorded independently. So there are really 50 split cards 21 flip cards and 33 double-faced cards.

Now we can make a more accurate determination of how many unique cards there are.

s <- length(AllCards$layout[AllCards$layout == 'split'])/2
f <- length(AllCards$layout[AllCards$layout == 'flip'])/2
d <- length(AllCards$layout[AllCards$layout == 'double-faced'])/2

simple <- with(AllCards,AllCards[layout == "normal"| layout == "leveler",])
name <- simple$name
length(unique(simple$name)) + s + f + d
13983

Leave a comment