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.
#' @export
#'
#' @examples
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))
}

set.seed(1234)
cards <- new_cards(30,new_deck())[-31]
cards <- exists_three_kind(cards)
dfcorbin/pokersim documentation built on Nov. 13, 2019, 4:21 p.m.