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

cards <- new_cards(7,new_deck())[-8]
check <- exists_pair(cards)
dfcorbin/pokersim documentation built on Nov. 13, 2019, 4:21 p.m.