Learn R Programming

holdem (version 1.2)

switch2: Finds the cards corresponding to numbers between 1 and 52.

Description

Takes each integer between 1 and 52 and turns it into a card. Used in deal1() and tourn1().

Usage

switch2(x)

Arguments

x

a vector of integers between 1 and 52.

Value

num

numbers (2-14) of the cards

st

suits (1-4) of the cards

%% ...

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){
    ## takes a number 1-52, and turns it into a card: 
    ## returns a list, where the 1st is the number (2-14), and 2nd is suit (1-4).
    n = length(x)
    y = list(num=x, st=rep(1,n))
    for(i in c(1:n)){
	a = 1
	while(a>0){
	    if(y$num[i]<14) a = -1 else{y$st[i] = y$st[i]+1
		y$num[i] = y$num[i]-13
	    }
	}
    }
    y$num = y$num+1
    y
  } ## end of switch2
# }

Run the code above in your browser using DataLab