R/exists_three_kind.R

Defines functions exists_three_kind

Documented in exists_three_kind

#' Detects and return the existence of 3 Kind
#'
#' @param cards A list of objects from the S4 class 'card'.
#'
#' @return list containing a logical representing if there is a 3-kind,
#' and the 3-kind itself if there is one.
#' @importFrom magrittr %>%
#' @export
exists_three_kind <- function(cards){
  three <- exists_n_kind(cards,3)
  if(three$logical){
    three <- three$cards
    cards <- remove_cards(cards,three)
  } 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_cards <- names(values)[1:2] %>% as.numeric() %>% cards[.]
  cards <- c(three,top_cards)
  return(list("logical" = TRUE,"cards" = cards))
}
dfcorbin/pokersim2 documentation built on Jan. 15, 2020, 12:20 a.m.