Learn R Programming

holdem (version 1.2)

straight1: See if you have a straight.

Description

Sees if you have a straight, and if so, finds the strength of your hand. Used by handeval().

Usage

straight1(x)

Arguments

x

Value

returns the highest card of your straight, or 0 if you don't have one.

Examples

Run this code
# NOT RUN {
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(x){
a1 = sort(unique(x))
if (length(a1)<4.5) return(0)
a3 = 0
n = length(a1)
if(a1[n] == 14) a1 = c(1,a1) ## count ace as both 1 and 14
a2 = length(a1)
for(j in c(5:a2)){ ## j will be the potential highest card of straight
    if( sum(15^c(1:5) * a1[(j-4):j]) == sum(15^c(1:5) * ((a1[j]-4):a1[j]))) a3 = a1[j]
  }
a3
  }	## end of straight1
# }

Run the code above in your browser using DataLab