Learn R Programming

holdem (version 1.2)

flush1: See if you have a flush

Description

Sees if you have a flush, and if so, how high it is.

Usage

flush1(x, y)

Arguments

x

vector of numbers of your cards and the board cards, together.

y

corresponding suits of your cards and the board cards.

Value

returns 0 if you don't have a flush, or 15^4 times top number + 15^3 times 2nd-highest + ... if you do.

Details

Can break down if dealing with 10 cards or more, i.e. if 2 flushes are possible

Examples

Run this code
# NOT RUN {
x = c(2,14,8,8,5,3,4)
y = c(1,2,4,1,1,1,1)
flush1(x,y)
x = c(2,14,8,8,5,3,4)
y = c(1,2,4,1,3,1,1)
flush1(x,y)
##---- 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,y){
    ## Can break down if dealing with 10 cards or more, i.e. if 2 flushes are possible
    ## returns 15^4 times top number + 15^3 times 2nd-highest + ...
a1 = mycount1(y)
if(max(a1$ct)<4.5) return(0)
a2 = c(1:length(a1$ct))[a1$ct > 4.5]
a3 = a1$v[a2] ## this is the suit
a4 = sort(x[y == a3],decreasing=T)
sum(15^c(4:0) * a4[1:5])
  } ## end of flush1
# }

Run the code above in your browser using DataLab