R/rank_hand.R

Defines functions rank_hand

Documented in rank_hand

#' Retrieve the value of a poker hand (incl community cards)
#'
#' @param player An object of S4 class `player`.
#'
#' @return A list containing the name of the hand, the cards and its numeric ranking.
#' @export
#'
rank_hand <- function(player){
  player <- player[[1]]
  cards <- c(player@hand,player@community)
  if (exists_s_flush(cards)$logical){
    hand_check <- exists_s_flush(cards)
    return(list("class" = "Straight Flush","cards" = hand_check$cards,"rank" = 1))
  } else if (exists_four_kind(cards)$logical){
    hand_check <- exists_four_kind(cards)
    return(list("class" = "Four of a kind","cards" = hand_check$cards,"rank" = 2))
  } else if (exists_full(cards)$logical){
    hand_check <- exists_full(cards)
    return(list("class" = "Full House","cards" = hand_check$cards,"rank" = 3))
  } else if (exists_flush(cards)$logical){
    hand_check <- exists_flush(cards)
    return(list("class" = "Flush","cards" = hand_check$cards,"rank" = 4))
  } else if (exists_straight(cards)$logical){
    hand_check <- exists_straight(cards)
    return(list("class" = "Straight","cards" = hand_check$cards,"rank" = 5))
  } else if (exists_three_kind(cards)$logical){
    hand_check <- exists_three_kind(cards)
    return(list("class" = "Three of a kind","cards" = hand_check$cards,"rank" = 6))
  } else if (exists_two_pair(cards)$logical){
    hand_check <- exists_two_pair(cards)
    return(list("class" = "Two pair","cards" = hand_check$cards,"rank" = 7))
  } else if (exists_pair(cards)$logical){
    hand_check <- exists_pair(cards)
    return(list("class" = "Pair","cards" = hand_check$cards,"rank" = 8))
  } else
    hand_check <- high_cards(cards)
    return(list("class" = "High card","cards" = hand_check$cards,"rank" = 9))
}
dfcorbin/pokersim2 documentation built on Jan. 15, 2020, 12:20 a.m.