Skip to content

Instantly share code, notes, and snippets.

@gumdropsteve
Last active December 9, 2020 07:29
Show Gist options
  • Save gumdropsteve/97825e63d9b14b3bb719475a12df19f9 to your computer and use it in GitHub Desktop.
Save gumdropsteve/97825e63d9b14b3bb719475a12df19f9 to your computer and use it in GitHub Desktop.
deck <- read.csv('https://github.com/gumdropsteve/datasets/raw/master/deck.csv', header=TRUE)
deck1 <- deck[deck$value >=7, ]
shuffler <- function(curr_deck){
mixer <- sample(1:13, size=13)
curr_deck <- curr_deck[mixer, ]
}
dealer <- function(){
# shuffle cards
play <- shuffler(deck1)
# iterate through the list 5 times, one time for each player and one time for the middle card
for (x in 1:5) {
# find end (last) & start (first) indexes for player x's cards
last = x * 3
first = last - 2
# player 1 hand
if (x == 1) {
print("----Hearts player1----")
print(play[first:last, ])
}
# player 2 hand
else if (x == 2){
print("----Hearts player2----")
print(play[first:last, ])
}
# player 3 hand
else if (x == 3) {
print("----Hearts player3----")
print(play[first:last, ])
}
# player 4 hand
else if (x == 4) {
print("----Hearts player4----")
print(play[first:last, ])
}
# middle card
else {
print("----Middle Card----")
print(play[first, ])
}
}
}
dealer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment