R/exists_pair.R

Defines functions exists_pair

Documented in exists_pair

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