R/exists_four_kind.R

Defines functions exists_four_kind

Documented in exists_four_kind

#' Detects and return the existence of 4 Kind
#'
#' @param cards A list of objects from the S4 class 'card'.
#'
#' @return A logical representing if a 4-of-a-kind exists.
#' @export
#' @importFrom magrittr %>%
#'
exists_four_kind <- function(cards){
  four <- exists_n_kind(cards,4)
  if(four$logical){
    four <- four$cards
    cards <- remove_cards(cards,four)
  } else return(list("logical" = FALSE))
  values <- c()
  for ( i in 1:length(cards)){
    values <- c(values,cards[[i]]@value)
  }
  names(values) <- paste(1:length(cards))
  values <- sort(values,decreasing=TRUE)
  top_card <- names(values)[1] %>% as.numeric() %>% cards[.]
  cards <- c(four,top_card)
  return(list("logical" = TRUE,"cards" = cards))
}
dfcorbin/pokersim2 documentation built on Jan. 15, 2020, 12:20 a.m.