Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Packages needed:
library("qgraph")
library("dplyr")
# Create a deck:
createDeck <- function(){
data.frame(
card = 1:60,
type = rep(c("land","spell","spell"), length = 60)
)
}
# Overhand shuffle:
overhand <- function(deck, nPack = sample(3:5,1)){
# Number of cards:
nCard <- nrow(deck)
# Make roughly equal packs:
# pack <- sort(rep(1:nPack,length = nCard))
pack <- sort(sample(1:nPack,nCard,TRUE))
# Stack in reverse order:
deck[order(pack,decreasing = TRUE),]
}
# full randomization:
properShuffle <- function(deck){
deck[sample(1:nrow(deck)),]
}
# Plot function:
plotDeck <- function(deck,
height = 8, width = 5,
mar = c(6,2),
...){
library("qgraph")
highlight <- deck$type == "land"
layout <- matrix(1:60,nrow=3,byrow=TRUE)
adj <- matrix(0,60,60)
col <- rainbow(60)[deck$card]
col <- ifelse(!highlight,qgraph:::Fade(col,0.2),col)
qgraph(adj, layout = layout, shape = "rectangle",
labels = deck$card,
vsize2 = height, vsize = width,
color = col,
mar = c(mar[1],mar[2],mar[1],mar[2]),
..., label.cex = 1.8, font = 2,
font=ifelse(highlight,2,1),
border.width = ifelse(highlight,3,1)
# border.color = c(rep("darkred",7),rep("black",60-7))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment