#' Test Whether Action Is Valid
#'
#' @param player An object of the S4 class player.
#' @param action A string that represents the players action when it is their turn.
#' It is usually generated using the input_action() funciton.
#' @param turn An integer representing the index of the player who's go it is.
#' @param bets A vector containing the current value of each player's
#' contribution to the pot.
#' @param raise A numeric value representing the most recent raise made
#' by any of the players.
#' @return A list containing a logical value representing the validity of the action.
#' The list will have a second element when the logical value is FALSE, which
#' contains a string detailing the nature of the problem.
#' @importFrom testit has_warning
#' @export
#'
validate_bet <- function(player,action,turn,bets,raise){
if(action == ""){
return(list("logical" = FALSE,"Empty action."))
} else if(action != "fold" && has_warning(as.numeric(action))){
return(list("logical" = FALSE,"Action must be numeric or `fold`"))
} else if(action == "fold"){
return(list("logical" = TRUE))
} else if (player@chips - as.numeric(action) < 0){
return(list("logical" = FALSE,"You don't have enough chips"))
} else if (as.numeric(action) + bets[turn] == max(bets)){
return(list("logical" = TRUE))
} else if ((as.numeric(action)+bets[turn])%%2 != 0){
return(list("logical" = FALSE,"You must bet/raise to a value that is an even integer"))
} else if (as.numeric(action) < 0){
return(list("logical" = FALSE,"You can only bet/raise a non-negative amount"))
} else if (as.numeric(action) + bets[turn] - max(bets) < raise){
return(list("logical" = FALSE,"You must make a raise that is at least as large as the previous raise."))
} else return(list("logical" = TRUE))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.